調査のついでに作ってみた。cのgearmandで動いてます。PP版は確認してない
gearmandのステータスは、telnetでアクセスして、statusコマンドを発行するととれる
$ telnet localhost 4730
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
status
resize 3 3 78
.
数値は、キュー数、実行中のキュー、Workerの数となってる。キュー数には実行中のキューも含むらしい。
package CloudForecast::Data::Gearmand; | |
use CloudForecast::Data -base; | |
use IO::Socket::INET; | |
=head1 NAME | |
CloudForecast::Data::Gearmand | |
=head1 SYNOPSIS | |
host_config) | |
resources: | |
- gearmand[[:port]:job]] | |
eg) | |
- gearmand # default 7003 port, 全てのjob | |
- gearmand:4730 # ほかのportで起動 | |
- gearmand:4730:resize # resize jobだけの統計 | |
=cut | |
rrds map { [$_,'GAUGE'] } qw/queue proc/; | |
graphs 'queue' => 'Queue'; | |
title { | |
my $c = shift; | |
my $title = "Gearmand"; | |
if ( my $port = $c->args->[0] ) { | |
$title .= " ($port)"; | |
} | |
if ( my $job = $c->args->[1] ) { | |
$title .= " $job"; | |
} | |
return $title; | |
}; | |
sysinfo { | |
my $c = shift; | |
$c->ledge_get('sysinfo') || []; | |
}; | |
fetcher { | |
my $c = shift; | |
my $host = $c->address; | |
my $port = $c->args->[0] || 7003; | |
my $sock = IO::Socket::INET->new( | |
PeerAddr => $host, | |
PeerPort => $port, | |
Proto => 'tcp', | |
); | |
my ($raw_status); | |
$sock->syswrite("status\r\n"); | |
$sock->sysread( $raw_status, 8192 ); | |
my %status; | |
foreach my $line ( split /\r?\n/, $raw_status ) { | |
my @st = split /\s+/, $line; | |
next unless @st == 4; | |
$status{$st[0]} = \@st; | |
} | |
if ( my $job = $c->args->[1] ) { | |
my $status = $status{$job}; | |
return [undef,undef] unless $status; | |
$c->ledge_set( 'sysinfo', [ $job, $status->[3] ] ); | |
return [ $status->[1], $status->[2] ]; | |
} | |
my ($queue, $proc) = ( 0, 0 ); | |
my @sysinfo = qw/job worker/; | |
for my $job ( values %status ) { | |
$queue += $job->[1]; | |
$proc += $job->[2]; | |
push @sysinfo, $job->[0], $job->[3]; | |
} | |
$c->ledge_set( 'sysinfo', \@sysinfo ); | |
return [ $queue, $proc ]; | |
}; | |
__DATA__ | |
@@ queue | |
DEF:my1a=<%RRD%>:queue:AVERAGE | |
DEF:my2=<%RRD%>:proc:AVERAGE | |
CDEF:my1=my1a,my2,- | |
AREA:my2#0000C0:Running | |
GPRINT:my2:LAST:Cur\: %6.1lf | |
GPRINT:my2:AVERAGE:Ave\: %6.1lf | |
GPRINT:my2:MAX:Max\: %6.1lf | |
GPRINT:my2:MIN:Min\: %6.1lf\c | |
STACK:my1#00C000:Queue | |
GPRINT:my1:LAST:Cur\: %6.1lf | |
GPRINT:my1:AVERAGE:Ave\: %6.1lf | |
GPRINT:my1:MAX:Max\: %6.1lf | |
GPRINT:my1:MIN:Min\: %6.1lf\c | |
ソースはgist。