Handle hostnames with upper-case letters
[webmin.git] / status / load-monitor.pl
1 # load-monitor.pl
2 # Check if the system load exceeds some level
3
4 sub get_load_status
5 {
6 local @u = &uptime_output();
7 if (!@u) {
8         return { 'up' => -1 }
9         }
10 elsif ($u[$_[0]->{'time'}] >= $_[0]->{'max'}) {
11         return { 'up' => 0 }
12         }
13 else {
14         return { 'up' => 1,
15                  'desc' => "Load is $u[$_[0]->{'time'}]" };
16         }
17 }
18
19 sub show_load_dialog
20 {
21 print &ui_table_row($text{'load_time'},
22         &ui_radio("time", int($_[0]->{'time'}),
23                   [ [ 0, $text{'load_1'} ],
24                     [ 1, $text{'load_5'} ],
25                     [ 2, $text{'load_15'} ] ]));
26
27 print &ui_table_row($text{'load_max'},
28         &ui_textbox("max", $_[0]->{'max'}, 6));
29 }
30
31 sub parse_load_dialog
32 {
33 &has_command("uptime") || &error($text{'load_ecmd'});
34 scalar(&uptime_output()) || &error($text{'load_efmt'});
35 $in{'max'} =~ /^[0-9\.]+$/ || &error($text{'load_emax'});
36 $_[0]->{'time'} = $in{'time'};
37 $_[0]->{'max'} = $in{'max'};
38 }
39
40 sub uptime_output
41 {
42 local $out = `uptime 2>&1`;
43 return $out =~ /average(s)?:\s+([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)/i ?
44                 ( $2, $3, $4 ) : ( );
45 }
46