forked from webmin/authentic-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.cgi
executable file
·69 lines (56 loc) · 2.37 KB
/
stats.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl
#
# Authentic Theme (https://github.com/qooob/authentic-theme)
# Copyright Ilia Rostovtsev <[email protected]>
# Licensed under MIT (https://github.com/qooob/authentic-theme/blob/master/LICENSE)
#
BEGIN {push(@INC, "..");}
use WebminCore;
use File::Basename;
use lib (dirname(__FILE__) . '/lib');
use JSON qw( );
init_config();
ReadParse();
our %text = load_language($current_theme);
my %data;
if ($in{'xhr-stats'} =~ /[[:alpha:]]/) {
my $target = $in{'xhr-stats'};
if ($target eq 'general') {
if (foreign_check("proc")) {
foreign_require("proc");
my @cpuusage = proc::get_cpu_io_usage();
my @cpuinfo = proc::get_cpu_info();
my @memory = proc::get_memory_info();
my @processes = proc::list_processes();
# CPU stats and load average
$data{'cpu'} =
[int($cpuusage[0] + $cpuusage[1] + $cpuusage[3]), text('body_load', ($cpuinfo[0], $cpuinfo[1], $cpuinfo[2]))];
# IO blocks
$data{'io'} = [$cpuusage[5], $cpuusage[6]];
# Memory stats
$data{'mem'} = (
@memory && $memory[0] ?
[(100 - int(($memory[1] / $memory[0]) * 100)),
text('body_used', nice_size(($memory[0]) * 1000), nice_size(($memory[0] - $memory[1]) * 1000))
] :
[]);
$data{'virt'} = (
@memory && $memory[2] ?
[(100 - int(($memory[3] / $memory[2]) * 100)),
text('body_used', nice_size(($memory[2]) * 1000), nice_size(($memory[2] - $memory[3]) * 1000))
] :
[]);
$data{'proc'} = scalar(@processes);
}
if (foreign_check("mount")) {
foreign_require("mount");
my @disk_space = mount::local_disk_space();
$data{'disk'} = [int(($disk_space[0] - $disk_space[1]) / $disk_space[0] * 100),
text('body_used_and_free', nice_size($disk_space[0]),
nice_size($disk_space[1]), nice_size($disk_space[0] - $disk_space[1])
)];
}
}
}
print "Content-type: application/json\n\n";
print JSON->new->latin1->encode(\%data);