Handle hostnames with upper-case letters
[webmin.git] / status / memory-monitor.pl
1 # memory-monitor.pl
2 # Check the free memory
3
4 sub get_memory_status
5 {
6 return { 'up' => -1 } if (!&foreign_check("proc"));
7 &foreign_require("proc", "proc-lib.pl");
8 local @mem;
9 eval "\@mem = &proc::get_memory_info()";
10 if ($@) {
11         return { 'up' => -1 };
12         }
13 elsif ($mem[1] < $_[0]->{'min'}) {
14         return { 'up' => 0,
15                  'desc' => &text('memory_freelow', &nice_size($mem[1]*1024)) };
16         }
17 elsif ($mem[2] && $mem[3] < $_[0]->{'minswap'}) {
18         return { 'up' => 0,
19                  'desc' => &text('memory_freelowswap',
20                                  &nice_size($mem[3]*1024)) };
21         }
22 else {
23         my @desc = ( &text('memory_free2', &nice_size($mem[1]*1024)) );
24         if ($mem[2]) {
25                 push(@desc, &text('memory_freeswap', &nice_size($mem[2]*1024)));
26                 }
27         return { 'up' => 1,
28                  'desc' => join(", ", @desc) };
29         }
30 }
31
32 sub show_memory_dialog
33 {
34 print &ui_table_row($text{'memory_min2'},
35         &ui_bytesbox("min", $_[0]->{'min'}*1024));
36
37 print &ui_table_row($text{'memory_minswap'},
38         &ui_bytesbox("minswap", $_[0]->{'minswap'}*1024));
39 }
40
41 sub parse_memory_dialog
42 {
43 &depends_check($_[0], "proc");
44 &foreign_require("proc", "proc-lib.pl");
45 defined(&proc::get_memory_info) || &error($text{'memory_eproc'});
46 $in{'min'} =~ /^[0-9\.]+$/ || &error($text{'memory_emin'});
47 $_[0]->{'min'} = $in{'min'}*$in{'min_units'}/1024;
48 $in{'minswap'} =~ /^[0-9\.]+$/ || &error($text{'memory_eminswap'});
49 $_[0]->{'minswap'} = $in{'minswap'}*$in{'minswap_units'}/1024;
50 }
51