make 5G test user quota
[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 $t = time();
17 my $max;
18 my $erase_screen = 1;
19 my $last_names = '?';
20
21 while(1) {
22         my $uptime = time() - $t;
23         print "\e[2J" if $erase_screen || $uptime % 5 == 0;
24         print "\e[0;0H"; # Cursor Home
25         print "Gearman " . localtime(time()) . "\t\e[34mmax update: $uptime\e[0m\n"; 
26         printf "\e[4mqueued  running  wrk function\e[0m\n";
27
28         print $sock "STATUS\n";
29
30         my $names;
31
32         while ( my $line = <$sock> ) {
33                 chomp $line;
34 #               warn "# [$line]\n";
35                 last if $line eq '.';
36                 next if $line =~ m/\t0$/; # ignore functions which don't have active workers
37                 my ( $name, $queued, $running, $workers ) = split(/\t/,$line,4);
38                 $max->{$name}->{$_} ||= 0 foreach qw(queued running);
39                 $max->{$name}->{queued}  = $queued  if $queued > $max->{$name}->{queued};
40                 $max->{$name}->{running} = $running if $running > $max->{$name}->{running};
41                 printf "%3d \e[34m%-3d\e[0m %3d \e[34m%-3d\e[0m %3d  %s\n"
42                         , $queued,  $max->{$name}->{queued}
43                         , $running, $max->{$name}->{running}
44                         , $workers
45                         , $name
46                 ;
47                 $names .= $name;
48         }
49
50 =for workers
51         print $sock "WORKERS\n";
52
53         while ( my $line = <$sock> ) {
54                 chomp $line;
55                 warn "# [$line]\n";
56                 last if $line eq '.';
57         }
58 =cut
59
60         if ( $names ne $last_names ) {
61                 $erase_screen = 1;
62                 $last_names = $names;
63         }
64
65         sleep 1;
66 }