#!/usr/bin/env perl $indexport = shift; die "usage: flare_status.pl [indexport]" unless ($indexport); print <<"EOM"; server:port role state balance partition items -------------------------------------------------------------------- EOM open(NC, "echo 'stats nodes' | nc localhost $indexport |") or die; while() { chomp; if (/^STAT (\d+\.\d+\.\d+\.\d+):(\d+):([^\s]+)\s+([^\s]+)/) { $stat{"$1:$2"}{$3} = $4; } } close(NC); $items_sum = 0; foreach $s (sort sort_sv_port (keys(%stat))) { $items = 0; if ($stat{$s}{'state'} eq 'active') { $items = &get_items(split(/:/, $s)); } $items_sum += $items; printf(" %-22s %-8s %-8s %3s %9s %10d\n", $s, $stat{$s}{'role'}, $stat{$s}{'state'}, $stat{$s}{'balance'}, $stat{$s}{'partition'}, $items); } print <<"EOM"; -------------------------------------------------------------------- EOM printf(" sum %10d\n", $items_sum); sub get_items { my ($sv, $port) = @_; chomp($items = `echo 'stats' | nc $sv $port | grep curr_items | awk '{print \$3}'`); return $items; } sub sort_sv_port { my ($sv, $port) = split(/:/, $a); my @ip = split(/\./, $sv); my $numa = $ip[0]*(2**24) + $ip[1]*(2**16) + $ip[2]*(2**8) + $ip[3]; my ($sv, $port) = split(/:/, $b); my @ip = split(/\./, $sv); my $numb = $ip[0]*(2**24) + $ip[1]*(2**16) + $ip[2]*(2**8) + $ip[3]; return $numa<=>$numb; }