added maximum number of queued and running jobs in blue
[cloudstore.git] / gearman-top.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use IO::Socket::INET;
6 use Data::Dump qw(dump);
7
8 my $sock = IO::Socket::INET->new(
9         PeerAddr => '127.0.0.1',
10         PeerPort => 4730,
11         Proto    => 'tcp'
12 ) || die $1;
13
14 print "\e[2J"; # Erase Screen
15
16 my $max;
17
18 while(1) {
19         print "\e[0;0H"; # Cursor Home
20         print "Gearman " . localtime(time()) . "\n";
21         printf "\e[4mqueued  running  wrk function \e[34mmax\e[0m\n";
22
23         print $sock "STATUS\n";
24
25         while ( my $line = <$sock> ) {
26                 chomp $line;
27 #               warn "# [$line]\n";
28                 last if $line eq '.';
29                 next if $line =~ m/\t0$/; # ignore functions which don't have active workers
30                 my ( $name, $queued, $running, $workers ) = split(/\t/,$line,4);
31                 $max->{$name}->{$_} ||= 0 foreach qw(queued running);
32                 $max->{$name}->{queued}  = $queued  if $queued > $max->{$name}->{queued};
33                 $max->{$name}->{running} = $running if $running > $max->{$name}->{running};
34                 printf "%3d \e[34m%-3d\e[0m %3d \e[34m%-3d\e[0m %3d  %s\n"
35                         , $queued,  $max->{$name}->{queued}
36                         , $running, $max->{$name}->{running}
37                         , $workers
38                         , $name
39                 ;
40         }
41
42 =for workers
43         print $sock "WORKERS\n";
44
45         while ( my $line = <$sock> ) {
46                 chomp $line;
47                 warn "# [$line]\n";
48                 last if $line eq '.';
49         }
50 =cut
51
52         sleep 1;
53 }