611e9765593aa6061c7a135a84805e7bd8fcd3fd
[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 while(1) {
17         print "\e[0;0H"; # Cursor Home
18         print "Gearman " . localtime(time()) . "\n";
19         printf "   q   r   w  function\n";
20
21         print $sock "STATUS\n";
22
23         while ( my $line = <$sock> ) {
24                 chomp $line;
25 #               warn "# [$line]\n";
26                 last if $line eq '.';
27                 next if $line =~ m/\t0$/; # ignore functions which don't have active workers
28                 my ( $name, $queued, $running, $workers ) = split(/\t/,$line,4);
29                 printf "%4d%4d%4d  %s\n", $queued, $running, $workers, $name;
30         }
31
32 =for workers
33         print $sock "WORKERS\n";
34
35         while ( my $line = <$sock> ) {
36                 chomp $line;
37                 warn "# [$line]\n";
38                 last if $line eq '.';
39         }
40 =cut
41
42         sleep 1;
43 }