Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created August 30, 2010 06:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kazeburo/557080 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment