Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created July 9, 2010 07:49
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 kazeburo/469203 to your computer and use it in GitHub Desktop.
Save kazeburo/469203 to your computer and use it in GitHub Desktop.
package CloudForecast::Data::Gearmanstarter;
use CloudForecast::Data -base;
use IO::Socket::INET;
=head1 NAME
CloudForecast::Data::Gearmanstarter
=head1 SYNOPSIS
host_config)
resources:
- gearmanstarter[:port]
eg)
- gearmanstarter # 監視ポート9000
- gearmanstarter:9005 # ほかのportで起動
=cut
rrds map { [$_,'GAUGE'] } qw/busy idle/;
graphs 'status' => 'worker status';
fetcher {
my $c = shift;
my $host = $c->address;
my $port = $c->args->[0] || 9000;
my $sock = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => 5,
);
die "could not connecet to $host:$port" unless $sock;
my $raw_stats;
$sock->sysread( $raw_stats, 8192 );
my $busy = -1;
my $idle = -1;
foreach my $line ( split /[\r\n]+/, $raw_stats ) {
if ( $line =~ /^Busy.+: (\d+)/ ) {
$busy = $1;
}
if ( $line =~ /^Idle.+: (\d+)/ ) {
$idle = $1;
}
}
return [$busy,$idle];
};
__DATA__
@@ status
DEF:my1=<%RRD%>:busy:AVERAGE
DEF:my2=<%RRD%>:idle:AVERAGE
AREA:my1#00C000:Busy
GPRINT:my1:LAST:Cur\: %4.1lf
GPRINT:my1:AVERAGE:Ave\: %4.1lf
GPRINT:my1:MAX:Max\: %4.1lf
GPRINT:my1:MIN:Min\: %4.1lf\c
STACK:my2#0000C0:Idle
GPRINT:my2:LAST:Cur\: %4.1lf
GPRINT:my2:AVERAGE:Ave\: %4.1lf
GPRINT:my2:MAX:Max\: %4.1lf
GPRINT:my2:MIN:Min\: %4.1lf\c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment