Created
July 13, 2012 09:59
-
-
Save berekuk/3104011 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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