From eeb53eac48404fa83e199014593b86d8f70c02a9 Mon Sep 17 00:00:00 2001 From: Dmitry Nechai Date: Thu, 27 Jun 2013 13:56:04 +0300 Subject: [PATCH] Module for extracting and transmitting data to client JSON RPC(mod_perl) --- .../perlmods/lib/OpenILS/Dashboard/ReqHandler.pm | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/Dashboard/ReqHandler.pm diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Dashboard/ReqHandler.pm b/Open-ILS/src/perlmods/lib/OpenILS/Dashboard/ReqHandler.pm new file mode 100644 index 0000000000..7e07edbfd6 --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/Dashboard/ReqHandler.pm @@ -0,0 +1,50 @@ +package OpenILS::Dashboard::ReqHandler; + + use 5.006; + use strict; + use base qw(JSON::RPC::Legacy::Procedure); # Perl 5.6 or more than + use Storable qw(retrieve); + + my %result; + my $saved_data = '/tmp/janus_data'; + + sub getCPU : Public { + getData('cpu'); + return \%result; + } + + sub getMemoryUsage : Public { + getData('mem'); + return \%result; + } + + sub getCurrenLoad : Public { + getData('load'); + return \%result; + } + + sub getDiskSpace : Public { + getData('disk'); + return \%result; + } + + sub getTotalProcesses : Public { + getData('proc'); + return \%result; + } + + sub getData : Private { + my $perf_data_ref; + if (-e $saved_data){ #if exists file with data + $perf_data_ref = retrieve($saved_data); #retrieve data + } else { + die "File with data does not exist!"; + } + my $type = shift; #get type of requested value + %result = (); #clear result hash + foreach my $host (keys $perf_data_ref){ + $result{$host} = $perf_data_ref->{$host}{$type}; #add value to result hash + } + } + +1; \ No newline at end of file -- 2.11.0