Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
325 richard 1
<?php
2
/***************************************************************************
3
 *   Copyright (C) 2006 by phpSysInfo - A PHP System Information Script    *
4
 *   http://phpsysinfo.sourceforge.net/                                    *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU General Public License as published by  *
8
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 *   (at your option) any later version.                                   *
10
 *                                                                         *
11
 *   This program is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU General Public License for more details.                          *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU General Public License     *
17
 *   along with this program; if not, write to the                         *
18
 *   Free Software Foundation, Inc.,                                       *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20
 ***************************************************************************/
21
 
22
// $Id: memory.php,v 1.18 2007/02/08 20:16:25 bigmichi1 Exp $
23
 
24
//
25
// xml_memory()
26
//
27
function xml_memory () {
28
	global $sysinfo;
29
 
30
	$arrMem = $sysinfo->memory();
31
	$i = 0;
32
 
33
	$_text = "  <Memory>\n"
34
		. "    <Free>" . htmlspecialchars( $arrMem['ram']['free'], ENT_QUOTES ) . "</Free>\n"
35
		. "    <Used>" . htmlspecialchars( $arrMem['ram']['used'], ENT_QUOTES ) . "</Used>\n"
36
		. "    <Total>" . htmlspecialchars( $arrMem['ram']['total'], ENT_QUOTES ) . "</Total>\n"
37
		. "    <Percent>" . htmlspecialchars( $arrMem['ram']['percent'], ENT_QUOTES ) . "</Percent>\n";
38
 
39
	if( isset( $arrMem['ram']['app_percent'] ) ) {
40
		$_text .= "    <App>" . htmlspecialchars( $arrMem['ram']['app'], ENT_QUOTES ) . "</App>\n    <AppPercent>" . htmlspecialchars( $arrMem['ram']['app_percent'], ENT_QUOTES ) . "</AppPercent>\n";
41
	}
42
	if( isset( $arrMem['ram']['buffers_percent'] ) ) {
43
		$_text .= "    <Buffers>" . htmlspecialchars( $arrMem['ram']['buffers'], ENT_QUOTES ) . "</Buffers>\n    <BuffersPercent>" . htmlspecialchars( $arrMem['ram']['buffers_percent'], ENT_QUOTES ) . "</BuffersPercent>\n";
44
	}
45
	if( isset( $arrMem['ram']['cached_percent'] ) ) {
46
		$_text .= "    <Cached>" . htmlspecialchars( $arrMem['ram']['cached'], ENT_QUOTES ) . "</Cached>\n    <CachedPercent>" . htmlspecialchars( $arrMem['ram']['cached_percent'], ENT_QUOTES ) . "</CachedPercent>\n";
47
	}
48
 
49
	$_text .= "  </Memory>\n";
50
 
51
	$_text .= "  <Swap>\n";
52
	if( isset( $arrMem['swap']['total'] ) && $arrMem['swap']['total'] > 0 ) {
53
		$_text .= "    <Free>" . htmlspecialchars( $arrMem['swap']['free'], ENT_QUOTES ) . "</Free>\n"
54
			. "    <Used>" . htmlspecialchars( $arrMem['swap']['used'], ENT_QUOTES ) . "</Used>\n"
55
			. "    <Total>" . htmlspecialchars( $arrMem['swap']['total'], ENT_QUOTES ) . "</Total>\n"
56
			. "    <Percent>" . htmlspecialchars( $arrMem['swap']['percent'], ENT_QUOTES ) . "</Percent>\n";
57
	}
58
	$_text .= "  </Swap>\n";
59
 
60
	$_text .= "  <Swapdevices>\n";
61
	foreach( $arrMem['devswap'] as $arrDevice) {
62
		$_text .="    <Mount>\n"
63
			. "     <MountPointID>" . htmlspecialchars( $i++, ENT_QUOTES ) . "</MountPointID>\n"
64
			. "     <Type>Swap</Type>"
65
			. "     <Device><Name>" . htmlspecialchars( $arrDevice['dev'], ENT_QUOTES ) . "</Name></Device>\n"
66
			. "     <Percent>" . htmlspecialchars( $arrDevice['percent'], ENT_QUOTES ) . "</Percent>\n"
67
			. "     <Free>" . htmlspecialchars( $arrDevice['free'], ENT_QUOTES ) . "</Free>\n"
68
			. "     <Used>" . htmlspecialchars( $arrDevice['used'], ENT_QUOTES ) . "</Used>\n"
69
			. "     <Size>" . htmlspecialchars( $arrDevice['total'], ENT_QUOTES ) . "</Size>\n"
70
			. "    </Mount>\n";
71
	}
72
	$_text .= "  </Swapdevices>\n";
73
 
74
	return $_text;
75
}
76
 
77
//
78
// html_memory()
79
//
80
function html_memory () {
81
	global $XPath;
82
	global $text;
83
 
84
	$textdir = direction();
85
	$scale_factor = 2;
86
 
87
	$strRam = create_bargraph( $XPath->getData( "/phpsysinfo/Memory/Used" ), $XPath->getData( "/phpsysinfo/Memory/Total" ), $scale_factor );
88
	$strRam .= "&nbsp;&nbsp;" . $XPath->getData( "/phpsysinfo/Memory/Percent" ) . "% ";
89
 
90
	if( $XPath->match( "/phpsysinfo/Swap/Total" ) ) {
91
		$strSwap = create_bargraph( $XPath->getData( "/phpsysinfo/Swap/Used" ), $XPath->getData( "/phpsysinfo/Swap/Total" ), $scale_factor );
92
		$strSwap .= "&nbsp;&nbsp;" . $XPath->getData( "/phpsysinfo/Swap/Percent" ) . "% ";
93
	}
94
 
95
	if( $XPath->match( "/phpsysinfo/Memory/AppPercent" ) ) {
96
		$strApp = create_bargraph( $XPath->getData( "/phpsysinfo/Memory/App" ), $XPath->getData( "/phpsysinfo/Memory/Total" ), $scale_factor );
97
		$strApp .= "&nbsp;&nbsp;" . $XPath->getData( "/phpsysinfo/Memory/AppPercent" ) . "% ";
98
	}
99
	if( $XPath->match( "/phpsysinfo/Memory/BuffersPercent" ) ) {
100
		$strBuffers = create_bargraph( $XPath->getData( "/phpsysinfo/Memory/Buffers" ), $XPath->getData( "/phpsysinfo/Memory/Total" ), $scale_factor);
101
		$strBuffers .= "&nbsp;&nbsp;" . $XPath->getData( "/phpsysinfo/Memory/BuffersPercent" ) . "% ";
102
	}
103
	if( $XPath->match( "/phpsysinfo/Memory/CachedPercent" ) ) {
104
		$strCached = create_bargraph( $XPath->getData( "/phpsysinfo/Memory/Cached" ), $XPath->getData( "/phpsysinfo/Memory/Total" ), $scale_factor);
105
		$strCached .= "&nbsp;&nbsp;" . $XPath->getData( "/phpsysinfo/Memory/CachedPercent" ) . "% ";
106
	}
107
 
108
	$_text = "<table border=\"0\" width=\"100%\" align=\"center\">\n"
109
		. "  <tr>\n"
110
		. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\"><b>" . $text['type'] . "</b></font></td>\n"
111
		. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\"><b>" . $text['percent'] . "</b></font></td>\n"
112
		. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\"><b>" . $text['free'] . "</b></font></td>\n"
113
		. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\"><b>" . $text['used'] . "</b></font></td>\n"
114
		. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\"><b>" . $text['size'] . "</b></font></td>\n"
115
		. "  </tr>\n"
116
		. "  <tr>\n"
117
		. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $text['phymem'] . "</font></td>\n"
118
		. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $strRam . "</font></td>\n"
119
		. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Free" ) ) . "</font></td>\n"
120
		. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Used" ) ) . "</font></td>\n"
121
		. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Total" ) ) . "</font></td>\n"
122
		. "  </tr>\n";
123
	if( isset( $strApp ) ) {
124
		$_text .= "  <tr>\n"
125
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">- " . $text['app'] . "</font></td>\n"
126
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $strApp . "</font></td>\n"
127
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">&nbsp;</font></td>\n"
128
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/App" ) ) . "</font></td>\n"
129
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">&nbsp;</font></td>\n"
130
			. "  </tr>\n";
131
	}
132
	if( isset( $strBuffers ) ) {
133
		$_text .= "  <tr>\n"
134
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">- " . $text['buffers'] . "</font></td>\n"
135
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $strBuffers . "</font></td>\n"
136
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">&nbsp;</font></td>\n"
137
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Buffers" ) ) . "</font></td>\n"
138
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">&nbsp;</font></td>\n"
139
			. "  </tr>\n";
140
	}
141
 
142
	if( isset( $strCached ) ) {
143
		$_text .= "  <tr>\n"
144
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">- " . $text['cached'] . "</font></td>\n"
145
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $strCached . "</font></td>\n"
146
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">&nbsp;</font></td>\n"
147
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Cached" ) ) . "</font></td>\n"
148
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">&nbsp;</font></td>\n"
149
			. "  </tr>\n";
150
	}
151
 
152
	if( isset( $strSwap ) ) {
153
		$_text .= "  <tr>\n"
154
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $text['swap'] . "</font></td>\n"
155
			. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $strSwap . "</font></td>\n"
156
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Swap/Free" ) ) . "</font></td>\n"
157
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Swap/Used" ) ) . "</font></td>\n"
158
			. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData( "/phpsysinfo/Swap/Total" ) ) . "</font></td>\n"
159
			. "  </tr>\n";
160
	}
161
 
162
	if( ($max = sizeof( $XPath->getDataParts( "/phpsysinfo/Swapdevices" ) ) ) > 2 ) {
163
		for( $i = 1; $i < $max; $i++ ) {
164
			$strSwapdev = create_bargraph( $XPath->getData( "/phpsysinfo/Swapdevices/Mount[" . $i . "]/Used" ), $XPath->getData( "/phpsysinfo/Swapdevices/Mount[" . $i . "]/Size" ), $scale_factor );
165
			$strSwapdev .= "&nbsp;&nbsp;" . $XPath->getData( "/phpsysinfo/Swapdevices/Mount[" . $i . "]/Percent" ) . "% ";
166
			$_text .= "  <tr>\n"
167
				. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\"> - " . $XPath->getData( "/phpsysinfo/Swapdevices/Mount[" . $i . "]/Device/Name" ) . "</font></td>\n"
168
				. "    <td align=\"" . $textdir['left'] . "\" valign=\"top\"><font size=\"-1\">" . $strSwapdev . "</font></td>\n"
169
				. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData("/phpsysinfo/Swapdevices/Mount[" . $i . "]/Free" ) ) . "</font></td>\n"
170
				. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData("/phpsysinfo/Swapdevices/Mount[" . $i . "]/Used" ) ) . "</font></td>\n"
171
				. "    <td align=\"" . $textdir['right'] . "\" valign=\"top\"><font size=\"-1\">" . format_bytesize( $XPath->getData("/phpsysinfo/Swapdevices/Mount[" . $i . "]/Size" ) ) . "</font></td>\n"
172
				. "  </tr>\n";
173
		}
174
	}
175
	$_text .= "</table>";
176
 
177
	return $_text;
178
}
179
 
180
function wml_memory() {
181
	global $XPath;
182
	global $text;
183
 
184
	$_text = "<card id=\"memory\" title=\"" . $text['memusage'] . "\">\n"
185
		. "<p>" . $text['phymem'] . ":<br/>\n"
186
		. "- " . $text['free'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Free" ) ) . "<br/>\n"
187
		. "- " . $text['used'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Used" ) ) . "<br/>\n"
188
		. "- " . $text['size'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Total" ) ) . "</p>\n";
189
	if( $XPath->match( "/phpsysinfo/Memory/App" ) ) {
190
		$_text .= "<p>" . $text['app'] . ":<br/>\n"
191
			. "- " . $text['used'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/App" ) ) . "</p>\n";
192
	}
193
	if( $XPath->match( "/phpsysinfo/Memory/Cached" ) ) {
194
		$_text .= "<p>" . $text['cached'] . ":<br/>\n"
195
			. "- " . $text['used'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Cached" ) ) . "</p>\n";
196
	}
197
	if( $XPath->match( "/phpsysinfo/Memory/Buffers" ) ) {
198
		$_text .= "<p>" . $text['buffers'] . ":<br/>\n"
199
			. "- " . $text['used'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Memory/Buffers" ) ) . "</p>\n";
200
	}
201
	if( $XPath->match( "/phpsysinfo/Swap/Total" ) ) {
202
		$_text .= "<p>" . $text['swap'] . ":<br/>\n"
203
			. "- " . $text['free'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Swap/Free" ) ) . "<br/>\n"
204
			. "- " . $text['used'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Swap/Used" ) ) . "<br/>\n"
205
			. "- " . $text['size'] . ": " . format_bytesize( $XPath->getData( "/phpsysinfo/Swap/Total" ) ) . "</p>\n";
206
	}
207
	$_text .= "</card>\n";
208
 
209
	return $_text;
210
}
211
?>