Created
February 12, 2011 03:39
-
-
Save bayashi/823476 to your computer and use it in GitHub Desktop.
check_starman_cow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Linux::Smaps; | |
my $proc_name = 'starman';#shift or die "usage: $0 PROC_NAME"; | |
my $proc_list = `ps a|grep $proc_name` || ''; | |
my @pid_list; | |
for my $proc (split /\n/, $proc_list) { | |
if ($proc =~ m!$proc_name.*[^\-](master|worker)!) { | |
my $type = $1; | |
my ($pid) = ($proc =~ m!^[^\d]*(\d+)[^\d]!); | |
push @pid_list, +{ type => $type, pid => $pid }; | |
} | |
} | |
die "not exists $proc_name" unless @pid_list; | |
printf "PID\tTYPE\tRSS\tSHARED\n"; | |
for my $p (@pid_list) { | |
my $map = Linux::Smaps->new($p->{pid}); | |
unless ($map) { | |
warn $!; | |
next; | |
} | |
printf | |
"%d\t%s\t%d\t%d (%d%%)\n", | |
$p->{pid}, | |
$p->{type}, | |
$map->rss, | |
$map->shared_dirty + $map->shared_clean, | |
int((($map->shared_dirty + $map->shared_clean) / $map->rss) * 100) | |
} | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment