Skip to content

Instantly share code, notes, and snippets.

@bayashi
Created February 12, 2011 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayashi/823476 to your computer and use it in GitHub Desktop.
Save bayashi/823476 to your computer and use it in GitHub Desktop.
check_starman_cow
#!/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