]>
Commit | Line | Data |
---|---|---|
72fe12a9 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
0d08de33 | 5 | # Copyright (C) 2005-2010 IPFire Team # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
72fe12a9 MT |
21 | |
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
cb5e9c6c CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
72fe12a9 MT |
27 | |
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
350b52c5 | 31 | require "${General::swroot}/graphs.pl"; |
72fe12a9 | 32 | |
4e481c3a CS |
33 | my %color = (); |
34 | my %mainsettings = (); | |
35 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 36 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
72fe12a9 | 37 | |
4190b2a6 LAH |
38 | &Header::showhttpheaders(); |
39 | &Header::openpage($Lang::tr{'memory information'}, 1, ''); | |
40 | &Header::openbigbox('100%', 'left'); | |
72fe12a9 | 41 | |
4190b2a6 LAH |
42 | &Header::openbox('100%', 'center', "Memory $Lang::tr{'graph'}"); |
43 | &Graphs::makegraphbox("memory.cgi","memory","day"); | |
44 | &Header::closebox(); | |
45 | ||
46 | if (-f "$mainsettings{'RRDLOG'}/collectd/localhost/swap") { | |
47 | &Header::openbox('100%', 'center', "Swap $Lang::tr{'graph'}"); | |
48 | &Graphs::makegraphbox("memory.cgi","swap","day"); | |
4e481c3a | 49 | &Header::closebox(); |
4190b2a6 | 50 | } |
72fe12a9 | 51 | |
4190b2a6 LAH |
52 | &Header::openbox('100%', 'center', $Lang::tr{'memory'}); |
53 | print "<table width='95%' cellspacing='5'>"; | |
54 | my $size=0; | |
55 | my $used=0; | |
56 | my $free=0; | |
57 | my $percent=0; | |
58 | my $shared=0; | |
59 | my $buffers=0; | |
60 | my $cached=0; | |
61 | my $available=0; | |
72fe12a9 | 62 | |
4190b2a6 LAH |
63 | # output format: kibibytes, wide mode (buffers and cache in two columns) |
64 | open(my $cmd_fh, "-|", '/usr/bin/free -k -w') or die $!; | |
65 | while(<$cmd_fh>){ | |
66 | if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cache\s+available$/ ){ | |
67 | print <<END | |
72fe12a9 | 68 | <tr> |
4190b2a6 LAH |
69 | <td align='center'> </td> |
70 | <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td> | |
71 | <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td> | |
72 | <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td> | |
73 | <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td> | |
72fe12a9 MT |
74 | </tr> |
75 | END | |
76 | ; | |
4190b2a6 LAH |
77 | }else{ |
78 | if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/){ | |
79 | ($size,$used,$free,$shared,$buffers,$cached,$available) = ($1,$2,$3,$4,$5,$6,$7); | |
80 | ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; | |
81 | print <<END | |
72fe12a9 | 82 | <tr> |
4190b2a6 | 83 | <td class='boldbase'><b>$Lang::tr{'ram'}</b></td> |
72fe12a9 MT |
84 | END |
85 | ; | |
4190b2a6 LAH |
86 | }elsif($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/){ |
87 | ($size,$used,$free) = ($1,$2,$3); | |
88 | if ($size != 0){ | |
89 | ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; | |
90 | }else{ | |
91 | ($percent = ''); | |
92 | } | |
93 | print <<END | |
72fe12a9 | 94 | <tr> |
4190b2a6 | 95 | <td class='boldbase'><b>$Lang::tr{'swap'}</b></td> |
72fe12a9 MT |
96 | END |
97 | ; | |
4190b2a6 LAH |
98 | } |
99 | print <<END | |
100 | <td align='center'>$size KiB</td> | |
101 | <td align='center'>$used KiB</td> | |
102 | <td align='center'>$free KiB</td> | |
103 | <td> | |
72fe12a9 MT |
104 | END |
105 | ; | |
4190b2a6 LAH |
106 | &percentbar($percent); |
107 | print <<END | |
72fe12a9 | 108 | </td> |
4190b2a6 | 109 | <td align='left'>$percent</td> |
72fe12a9 MT |
110 | </tr> |
111 | END | |
112 | ; | |
4e481c3a | 113 | } |
4190b2a6 LAH |
114 | } |
115 | close($cmd_fh); | |
116 | print <<END | |
43f20d6e LAH |
117 | <tr><td colspan='6'><br /></td></tr> |
118 | <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='center'>$shared KiB</td></tr> | |
119 | <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='center'>$buffers KiB</td></tr> | |
120 | <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='center'>$cached KiB</td></tr> | |
121 | <tr><td class='boldbase'><b>$Lang::tr{'available'}</b></td><td align='center'>$available KiB</td></tr> | |
72fe12a9 MT |
122 | </table> |
123 | END | |
124 | ; | |
4190b2a6 | 125 | &Header::closebox(); |
72fe12a9 | 126 | |
4190b2a6 LAH |
127 | &Header::closebigbox(); |
128 | &Header::closepage(); | |
72fe12a9 | 129 | |
4e481c3a CS |
130 | sub percentbar{ |
131 | my $percent = $_[0]; | |
132 | my $fg = '#a0a0a0'; | |
133 | my $bg = '#e2e2e2'; | |
72fe12a9 | 134 | |
4e481c3a CS |
135 | if ($percent =~ m/^(\d+)%$/ ){ |
136 | print <<END | |
72fe12a9 MT |
137 | <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'> |
138 | <tr> | |
139 | END | |
140 | ; | |
4e481c3a CS |
141 | if ($percent eq "100%"){ |
142 | print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"; | |
143 | }elsif($percent eq "0%"){ | |
144 | print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"; | |
145 | }else{ | |
146 | print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"; | |
147 | } | |
148 | print <<END | |
72fe12a9 MT |
149 | <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table> |
150 | END | |
151 | ; | |
4e481c3a | 152 | } |
72fe12a9 | 153 | } |