From: Dobrica Pavlinusic Date: Sun, 20 May 2012 21:49:30 +0000 (+0200) Subject: show gearman queue from command-line X-Git-Url: http://git.rot13.org/?p=APKPM.git;a=commitdiff_plain;h=23d25119d67606011207e9b70f14691dffa7ef90;ds=sidebyside show gearman queue from command-line --- diff --git a/gearman-top.pl b/gearman-top.pl new file mode 100755 index 0000000..88108dc --- /dev/null +++ b/gearman-top.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use IO::Socket::INET; +use Data::Dump qw(dump); + +my $sock = IO::Socket::INET->new( + PeerAddr => '127.0.0.1', + PeerPort => 4730, + Proto => 'tcp' +) || die $1; + +print ""; # Erase Screen + +my $t = time(); +my $max; +my $erase_screen = 1; +my $last_names = '?'; + +while(1) { + my $uptime = time() - $t; + print "" if $erase_screen || $uptime % 5 == 0; + print ""; # Cursor Home + print "Gearman " . localtime(time()) . "\tmax update: $uptime\n"; + printf "queued running wrk function\n"; + + print $sock "STATUS\n"; + + my $names; + + while ( my $line = <$sock> ) { + chomp $line; +# warn "# [$line]\n"; + last if $line eq '.'; + next if $line =~ m/\t0$/; # ignore functions which don't have active workers + my ( $name, $queued, $running, $workers ) = split(/\t/,$line,4); + next if ! $ENV{ALL} && $queued == 0; + $max->{$name}->{$_} ||= 0 foreach qw(queued running); + $max->{$name}->{queued} = $queued if $queued > $max->{$name}->{queued}; + $max->{$name}->{running} = $running if $running > $max->{$name}->{running}; + printf "%3d %-3d %3d %-3d %3d %s\n" + , $queued, $max->{$name}->{queued} + , $running, $max->{$name}->{running} + , $workers + , $name + ; + $names .= $name; + } + +=for workers + print $sock "WORKERS\n"; + + while ( my $line = <$sock> ) { + chomp $line; + warn "# [$line]\n"; + last if $line eq '.'; + } +=cut + + if ( $names ne $last_names ) { + $erase_screen = 1; + $last_names = $names; + } + + sleep 1; +}