Skip to content

Instantly share code, notes, and snippets.

@berekuk
Created July 13, 2012 09:59
Show Gist options
  • Select an option

  • Save berekuk/3104011 to your computer and use it in GitHub Desktop.

Select an option

Save berekuk/3104011 to your computer and use it in GitHub Desktop.
package Ubic::Service::SimpleDaemon::WithMemoryUsage;
use strict;
use warnings;
use parent qw(Ubic::Service::SimpleDaemon);
use Ubic::Daemon qw(check_daemon);
use Ubic::Result qw(result);
sub custom_commands {
my $self = shift;
return ($self->SUPER::custom_commands, qw/ memory_usage /);
}
sub memory_usage {
my $self = shift;
my $pid = check_daemon($self->pidfile)->pid;
my $proc_status = qx(cat /proc/$pid/status);
die "Can't get process status for $pid" unless $proc_status;
my ($rss) = $proc_status =~ /VmRSS:\s+(.*)/;
unless ($rss) {
die "Invalid process status for $pid";
}
print "$rss\n";
return result('ok');
}
sub do_custom_command {
my $self = shift;
my ($command) = @_;
if ($command eq 'memory_usage') {
return $self->memory_usage;
}
return $self->SUPER::do_custom_command($command);
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment