28 |
|
|
29 |
my $data = Storable::retrieve $data_path if -e $data_path; |
my $data = Storable::retrieve $data_path if -e $data_path; |
30 |
|
|
31 |
|
sub proc { |
32 |
|
local $/ = undef; |
33 |
|
open(my $fh, '<', '/proc/' . shift); |
34 |
|
<$fh>; |
35 |
|
} |
36 |
|
|
37 |
while (1) { |
while (1) { |
38 |
for my $sock ($sel->can_read(1)) { |
for my $sock ($sel->can_read(1)) { |
39 |
my $request = eval { Storable::fd_retrieve($sock) }; |
my $request = eval { Storable::fd_retrieve($sock) }; |
45 |
my $response = { port => $port }; |
my $response = { port => $port }; |
46 |
if ( $request->{ping} ) { |
if ( $request->{ping} ) { |
47 |
$response->{ping} = 'pong'; |
$response->{ping} = 'pong'; |
48 |
|
$response->{proc}->{$_} = proc $_ foreach ( 'loadavg', 'meminfo', "$$/status" ); |
49 |
} elsif ( $request->{load} ) { |
} elsif ( $request->{load} ) { |
50 |
$response->{load} = 'shard'; |
$response->{load} = 'shard'; |
51 |
} elsif ( $request->{bulk_load} ) { |
} elsif ( $request->{bulk_load} ) { |