Revision: 263
http://phpsysinfo.svn.sourceforge.net/phpsysinfo/?rev=263&view=rev
Author: bigmichi1
Date: 2009-06-22 13:01:52 +0000 (Mon, 22 Jun 2009)
Log Message:
-----------
restructure xml; include trees for memory, hardware and ups; using to between classes and xml parser
Modified Paths:
--------------
ChangeLog
includes/class.CommonFunctions.inc.php
includes/class.Parser.inc.php
includes/interface/class.PSI_Interface_OS.inc.php
includes/interface/class.PSI_Interface_Sensor.inc.php
includes/interface/class.PSI_Interface_UPS.inc.php
includes/mb/class.Coretemp.inc.php
includes/mb/class.HDDTemp.inc.php
includes/mb/class.HWSensors.inc.php
includes/mb/class.Healthd.inc.php
includes/mb/class.IPMI.inc.php
includes/mb/class.K8Temp.inc.php
includes/mb/class.LMSensors.inc.php
includes/mb/class.MBM5.inc.php
includes/mb/class.MBMon.inc.php
includes/os/class.BSDCommon.inc.php
includes/os/class.Darwin.inc.php
includes/os/class.DragonFly.inc.php
includes/os/class.FreeBSD.inc.php
includes/os/class.HPUX.inc.php
includes/os/class.Linux.inc.php
includes/os/class.NetBSD.inc.php
includes/os/class.OS.inc.php
includes/os/class.OpenBSD.inc.php
includes/os/class.SunOS.inc.php
includes/os/class.WINNT.inc.php
includes/output/class.Webpage.inc.php
includes/ups/class.Apcupsd.inc.php
includes/ups/class.Nut.inc.php
includes/xml/class.XML.inc.php
js/phpSysInfo/phpsysinfo.js
Added Paths:
-----------
includes/mb/class.Sensors.inc.php
includes/ups/class.UPS.inc.php
phpsysinfo3.xsd
Removed Paths:
-------------
phpsysinfo.xsd
Modified: ChangeLog
===================================================================
--- ChangeLog 2009-06-22 10:48:33 UTC (rev 262)
+++ ChangeLog 2009-06-22 13:01:52 UTC (rev 263)
@@ -5,6 +5,12 @@
- [FIX] Fixed Bug [ 2803964 ] Disabling language or template picklist fails
- [FIX] Fixed Bug [ 2803480 ] Empty page when hddtemp enabled
- [FIX] Fixed Bug [ 2804624 ] typos in config.php.new
+
+ - [ADD] Added FR [ 2804580 ] Memory Usage Display
+
+ - [UPD] refactoring of the xml structure
+ - [UPD] avoid using arrays, instead using transport objects with default values for essential properties
+ - [UPD] using treeTable plugin for Hardware, Memory and Ups block
phpSysInfo 3.0 RC-8, 2009-06-09
- [FIX] Fixed Notice Array to String conversion for scsi and ide
Modified: includes/class.CommonFunctions.inc.php
===================================================================
--- includes/class.CommonFunctions.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/class.CommonFunctions.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -130,29 +130,6 @@
}
/**
- * find duplicate entrys and count them, show this value befor the duplicated name
- *
- * @param array $arrInput source array that should be checked for duplicated names
- *
- * @return array array with duplicate entries removed and a appended value, how many times the entry has appeared
- */
- public static function finddups($arrInput)
- {
- $arrResult = array();
- if (is_array($arrInput)) {
- $arrBuffer = array_count_values($arrInput);
- foreach ($arrBuffer as $strKey=>$intValue) {
- if ($intValue > 1) {
- $arrResult[] = "(".$intValue."x) ".$strKey;
- } else {
- $arrResult[] = $strKey;
- }
- }
- }
- return $arrResult;
- }
-
- /**
* read a file and return the content as a string
*
* @param string $strFileName name of the file which should be read
Modified: includes/class.Parser.inc.php
===================================================================
--- includes/class.Parser.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/class.Parser.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -28,57 +28,53 @@
/**
* parsing the output of lspci command
*
- * @return mixed
+ * @return Array
*/
public static function lspci()
{
$arrResults = array();
- $strBuf = "";
if (CommonFunctions::executeProgram("lspci", "", $strBuf, PSI_DEBUG)) {
$arrLines = split("\n", $strBuf);
foreach ($arrLines as $strLine) {
list($strAddr, $strName) = explode(' ', trim($strLine), 2);
$strName = preg_replace('/\(.*\)/', '', $strName);
- $arrResults[] = $strName;
+ $dev = new HWDevice();
+ $dev->setName($strName);
+ $arrResults[] = $dev;
}
}
- if ( empty($arrResults)) {
- return false;
- } else {
- asort($arrResults);
- return $arrResults;
- }
+ return $arrResults;
}
/**
* parsing the output of pciconf command
*
- * @return mixed
+ * @return Array
*/
public static function pciconf()
{
$arrResults = array();
$intS = 0;
- $strBuf = "";
if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
+ $arrTemp = array();
$arrLines = explode("\n", $strBuf);
foreach ($arrLines as $strLine) {
if (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
if (trim($arrParts[1]) == "vendor") {
- $arrResults[$intS] = trim($arrParts[2]);
+ $arrTemp[$intS] = trim($arrParts[2]);
} elseif (trim($arrParts[1]) == "device") {
- $arrResults[$intS] .= " - ".trim($arrParts[2]);
+ $arrTemp[$intS] .= " - ".trim($arrParts[2]);
$intS++;
}
}
}
+ foreach ($arrTemp as $name) {
+ $dev = new HWDevice();
+ $dev->setName($name);
+ $arrResults[] = $dev;
+ }
}
- if ( empty($arrResults)) {
- return false;
- } else {
- asort($arrResults);
- return $arrResults;
- }
+ return $arrResults;
}
/**
@@ -90,16 +86,11 @@
*/
public static function df($df_param = "")
{
- $results = array();
- $j = 0;
- $df = "";
- $df2 = "";
- $mount = "";
- if (CommonFunctions::executeProgram('df', '-k '.$df_param, $df, PSI_DEBUG) || ! empty($df)) {
+ $arrResult = array();
+ if (CommonFunctions::executeProgram('df', '-k '.$df_param, $df, PSI_DEBUG)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
- natsort($df);
if (PSI_SHOW_INODES) {
- if (CommonFunctions::executeProgram('df', '-i '.$df_param, $df2, PSI_DEBUG) || ! empty($df)) {
+ if (CommonFunctions::executeProgram('df', '-i '.$df_param, $df2, PSI_DEBUG)) {
$df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY);
// Store inode use% in an associative array (df_inodes) for later use
foreach ($df2 as $df2_line) {
@@ -107,7 +98,6 @@
$df_inodes[$inode_buf[1]] = $inode_buf[2];
}
}
- unset($df2, $df2_line, $inode_buf);
}
}
if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
@@ -124,7 +114,6 @@
$mount_parm[$mount_buf[1]]['options'] = isset($mount_buf[4]) ? $mount_buf[4] : '';
}
}
- unset($mount, $mount_line, $mount_buf);
foreach ($df as $df_line) {
$df_buf1 = preg_split("/(\%\s)/", $df_line, 2);
if (count($df_buf1) != 2) {
@@ -134,36 +123,28 @@
$df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]);
if (count($df_buf) == 6) {
$df_buf[5] = trim($df_buf[5]);
- $results[$j] = array();
- $results[$j]['disk'] = trim($df_buf[0]);
- $results[$j]['size'] = $df_buf[1] * 1024;
- $results[$j]['used'] = $df_buf[2] * 1024;
- $results[$j]['free'] = $df_buf[3] * 1024;
- if ($results[$j]['used'] < 0) {
- $results[$j]['size'] = $results[$j]['free'] * 1024;
- $results[$j]['free'] = 0;
- $results[$j]['used'] = $results[$j]['size'] * 1024;
+ $dev = new DiskDevice();
+ $dev->setName(trim($df_buf[0]));
+ if ($df_buf[2] < 0) {
+ $dev->setTotal($df_buf[3] * 1024);
+ $dev->setUsed($df_buf[3] * 1024);
+ } else {
+ $dev->setTotal($df_buf[1] * 1024);
+ $dev->setUsed($df_buf[2] * 1024);
+ $dev->setFree($df_buf[3] * 1024);
}
- if ($results[$j]['size'] == 0) {
- continue;
+ $dev->setMountPoint($df_buf[5]);
+ $dev->setFsType($mount_parm[$df_buf[5]]['fstype']);
+ $dev->setOptions($mount_parm[$df_buf[5]]['options']);
+ if (PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) {
+ $dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]);
}
- $results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
- $results[$j]['mount'] = $df_buf[5];
- $results[$j]['fstype'] = $mount_parm[$df_buf[5]]['fstype'];
- $results[$j]['options'] = $mount_parm[$df_buf[5]]['options'];
- if (PSI_SHOW_INODES && isset($df_inodes[$results[$j]['disk']])) {
- $results[$j]['inodes'] = $df_inodes[$results[$j]['disk']];
- }
- $j++;
+ $arrResult[] = $dev;
}
}
- return $results;
- } else {
- return array();
}
- } else {
- return array();
}
+ return $arrResult;
}
}
?>
Modified: includes/interface/class.PSI_Interface_OS.inc.php
===================================================================
--- includes/interface/class.PSI_Interface_OS.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/interface/class.PSI_Interface_OS.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -28,140 +28,24 @@
interface PSI_Interface_OS
{
/**
- * Virtual Host Name
+ * get a special encoding from os where phpsysinfo is running
*
* @return string
*/
- function vhostname();
+ function getEncoding();
/**
- * IP of the Virtual Host Name
+ * build the os information
*
- * @return string
+ * @return void
*/
- function vipaddr();
+ function build();
/**
- * Canonical Host Name
+ * get the filled or unfilled (with default values) system object
*
- * @return string
+ * @return System
*/
- function chostname();
-
- /**
- * IP of the Canonical Host Name
- *
- * @return string
- */
- function ipaddr();
-
- /**
- * Kernel Version
- *
- * @return string
- */
- function kernel();
-
- /**
- * UpTime
- * time the system is running
- *
- * @return integer
- */
- function uptime();
-
- /**
- * Number of Users
- *
- * @return integer
- */
- function users();
-
- /**
- * Processor Load
- * optionally create a loadbar
- *
- * @param boolean $bar include a bar
- *
- * @return array
- */
- function loadavg($bar = false);
-
- /**
- * CPU information
- *
- * @return array
- */
- function cpuinfo();
-
- /**
- * PCI devices
- *
- * @return array
- */
- function pci();
-
- /**
- * IDE devices
- *
- * @return array
- */
- function ide();
-
- /**
- * SCSI devices
- *
- * @return array
- */
- function scsi();
-
- /**
- * USB devices
- *
- * @return array
- */
- function usb();
-
- /**
- * Network devices
- *
- * @return array
- */
- function network();
-
- /**
- * Physical memory information and Swap Space information
- *
- * @return array
- */
- function memory();
-
- /**
- * filesystem information
- *
- * @return array
- */
- function filesystems();
-
- /**
- * Distribution
- *
- * @return string
- */
- function distro();
-
- /**
- * Distribution Icon
- *
- * @return string
- */
- function distroicon();
-
- /**
- * get a special encoding from os where phpsysinfo is running
- *
- * @return string
- */
- function getEncoding();
+ function getSys();
}
?>
Modified: includes/interface/class.PSI_Interface_Sensor.inc.php
===================================================================
--- includes/interface/class.PSI_Interface_Sensor.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/interface/class.PSI_Interface_Sensor.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -28,24 +28,17 @@
interface PSI_Interface_Sensor
{
/**
- * get temperature information
+ * build the mbinfo information
*
- * @return array
+ * @return void
*/
- function temperature();
+ function build();
/**
- * get voltage information
+ * get the filled or unfilled (with default values) MBInfo object
*
- * @return array
+ * @return MBInfo
*/
- function voltage();
-
- /**
- * get fan information
- *
- * @return array
- */
- function fans();
+ function getMBInfo();
}
?>
Modified: includes/interface/class.PSI_Interface_UPS.inc.php
===================================================================
--- includes/interface/class.PSI_Interface_UPS.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/interface/class.PSI_Interface_UPS.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -27,10 +27,17 @@
interface PSI_Interface_UPS
{
/**
- * generate the output
+ * build the ups information
*
* @return void
*/
- function info();
+ function build();
+
+ /**
+ * get the filled or unfilled (with default values) UPSInfo object
+ *
+ * @return UPSInfo
+ */
+ function getUPSInfo();
}
?>
Modified: includes/mb/class.Coretemp.inc.php
===================================================================
--- includes/mb/class.Coretemp.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.Coretemp.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* coretemp sensor class
*
@@ -24,49 +24,39 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class Coretemp implements PSI_Interface_Sensor
+class Coretemp extends Sensors
{
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- function temperature()
+ private function _temperature()
{
- $results = array ();
$smp = 1;
CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
for ($i = 0; $i < $smp; $i++) {
$temp = 0;
if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
- $results[$i]['label'] = "CPU ".($i+1);
- $results[$i]['value'] = $temp;
- $results[$i]['limit'] = '70.0';
- $results[$i]['percent'] = $results[$i]['value']*100/
- $results[$i]['limit'];
+ $dev = new SensorDevice();
+ $dev->setName("CPU ".($i + 1));
+ $dev->setValue($temp);
+ $dev->setMax(70);
+ $this->mbinfo->setMbTemp($dev);
}
}
- return $results;
}
-
+
/**
- * get fan information
+ * get the information
*
- * @return array fans in array with lable
- */
- function fans()
- {
- return null;
- }
-
- /**
- * get voltage information
+ * @see PSI_Interface_Sensor::build()
*
- * @return array voltage in array with lable
+ * @return Void
*/
- function voltage()
+ public function build()
{
- return null;
+ $this->_temperature();
}
}
?>
Modified: includes/mb/class.HDDTemp.inc.php
===================================================================
--- includes/mb/class.HDDTemp.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.HDDTemp.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* hddtemp sensor class
*
@@ -24,35 +24,18 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class HDDTemp
+class HDDTemp extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
- * create the error object
- */
- public function __construct()
- {
- $this->_error = Error::Singleton();
- }
-
-
- /**
* get the temperature information from hddtemp
* access is available through tcp or command
*
* @return array temperatures in array
*/
- public function temperature()
+ private function _temperature()
{
- $ar_buf = array ();
- $results = array ();
- switch(PSI_HDD_TEMP) {
+ $ar_buf = array();
+ switch (PSI_HDD_TEMP) {
case "tcp":
$lines = '';
// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
@@ -64,7 +47,7 @@
}
fclose($fp);
} else {
- $this->_error->addError("HDDTemp error", $errno.", ".$errstr);
+ $this->error->addError("HDDTemp error", $errno.", ".$errstr);
}
$lines = str_replace("||", "|\n|", $lines);
$ar_buf = explode("\n", $lines);
@@ -101,7 +84,7 @@
}
}
if (trim($strDrives) == "") {
- return array ();
+ break;
}
if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value)) {
$hddtemp_value = explode("\n", $hddtemp_value);
@@ -114,34 +97,40 @@
array_push($ar_buf, "|".implode("|", $temp)."|");
}
}
- } else {
- return array ();
}
break;
default:
- $this->_error->addConfigError("temperature()", "PSI_HDD_TEMP");
+ $this->error->addConfigError("temperature()", "PSI_HDD_TEMP");
break;
}
// Timo van Roermund: parse the info from the hddtemp daemon.
- $i = 0;
foreach ($ar_buf as $line) {
- $data = array ();
+ $data = array();
if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data)) {
if (trim($data[3]) != "ERR") {
// get the info we need
- $results[$i]['label'] = $data[1];
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
if (is_numeric($data[3])) {
- $results[$i]['value'] = $data[3];
- } else {
- $results[$i]['value'] = 0;
+ $dev->setValue($data[3]);
}
- //extra processing because of a bug in some versions of hddtemp
- $results[$i]['model'] = trim(str_replace("\x10\x80", "", $data[2]));
- $i++;
+ $dev->setMax(60);
+ $this->mbinfo->setMbTemp($dev);
}
}
}
- return $results;
}
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return Void
+ */
+ public function build()
+ {
+ $this->_temperature();
+ }
}
?>
Modified: includes/mb/class.HWSensors.inc.php
===================================================================
--- includes/mb/class.HWSensors.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.HWSensors.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* hwsensors sensor class
*
@@ -23,107 +23,101 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class HWSensors implements PSI_Interface_Sensor
+class HWSensors extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* content to parse
*
* @var array
*/
- private $_lines = array ();
-
+ private $_lines = array();
+
/**
* fill the private content var through tcp or file access
*/
function __construct()
{
- $this->_error = Error::Singleton();
- switch(strtolower(PSI_SENSOR_ACCESS))
- {
+ parent::__construct();
+ switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'tcp':
$lines = "";
CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
$this->_lines = explode("\n", $lines);
break;
default:
- $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
-
+
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temperature()
{
- $ar_buf = array ();
- $results = array ();
- $j = 0;
foreach ($this->_lines as $line) {
$ar_buf = preg_split("/[\s,]+/", $line);
- if ( isset ($ar_buf[3]) && $ar_buf[2] == 'temp') {
- $results[$j]['label'] = $ar_buf[1];
- $results[$j]['value'] = $ar_buf[3];
- $results[$j]['limit'] = '70.0';
- $results[$j]['percent'] = $results[$j]['value']*100/
- $results[$j]['limit'];
- $j++;
+ if (isset($ar_buf[3]) && $ar_buf[2] == 'temp') {
+ $dev = new SensorDevice();
+ $dev->setName($ar_buf[1]);
+ $dev->setValue($ar_buf[3]);
+ $dev->setMax(70);
+ $this->mbinfo->setMbTemp($dev);
}
}
- return $results;
}
-
+
/**
* get fan information
*
- * @return array fans in array with lable
+ * @return void
*/
- public function fans()
+ private function _fans()
{
- $ar_buf = array ();
- $results = array ();
- $j = 0;
foreach ($this->_lines as $line) {
$ar_buf = preg_split("/[\s,]+/", $line);
- if ( isset ($ar_buf[3]) && $ar_buf[2] == 'fanrpm') {
- $results[$j]['label'] = $ar_buf[1];
- $results[$j]['value'] = $ar_buf[3];
- $j++;
+ if (isset($ar_buf[3]) && $ar_buf[2] == 'fanrpm') {
+ $dev = new SensorDevice();
+ $dev->setName($ar_buf[1]);
+ $dev->setValue($ar_buf[3]);
+ $this->mbinfo->setMbFan($dev);
}
}
- return $results;
}
-
+
/**
* get voltage information
*
- * @return array voltage in array with lable
+ * @return void
*/
- public function voltage()
+ private function _voltage()
{
- $ar_buf = array ();
- $results = array ();
- $j = 0;
foreach ($this->_lines as $line) {
$ar_buf = preg_split("/[\s,]+/", $line);
- if ( isset ($ar_buf[3]) && $ar_buf[2] == 'volts_dc') {
- $results[$j]['label'] = $ar_buf[1];
- $results[$j]['value'] = $ar_buf[3];
- $results[$j]['min'] = '0.00';
- $results[$j]['max'] = '0.00';
- $j++;
+ if (isset($ar_buf[3]) && $ar_buf[2] == 'volts_dc') {
+ $dev = new SensorDevice();
+ $dev->setName($ar_buf[1]);
+ $dev->setValue($ar_buf[3]);
+ $this->mbinfo->setMbVolt($dev);
}
}
- return $results;
}
+
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return Void
+ */
+ public function build()
+ {
+ $this->_temperature();
+ $this->_voltage();
+ $this->_fans();
+ }
}
?>
Modified: includes/mb/class.Healthd.inc.php
===================================================================
--- includes/mb/class.Healthd.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.Healthd.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* healthd sensor class
*
@@ -23,126 +23,133 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class Healthd implements PSI_Interface_Sensor
+class Healthd extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* content to parse
*
* @var array
*/
- private $_lines = array ();
-
+ private $_lines = array();
+
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
- $this->_error = Error::Singleton();
- switch(strtolower(PSI_SENSOR_ACCESS)) {
+ parent::__construct();
+ switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('healthdc', '-t', $lines);
$this->_lines = explode("\n", $lines);
break;
default:
- $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
-
+
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temperature()
{
- $ar_buf = array ();
- $results = array ();
$ar_buf = preg_split("/\t+/", $this->_lines);
- $results[0]['label'] = 'temp1';
- $results[0]['value'] = $ar_buf[1];
- $results[0]['limit'] = '70.0';
- $results[0]['percent'] = $results[0]['value']*100/$results[0]['limit'];
- $results[1]['label'] = 'temp2';
- $results[1]['value'] = $ar_buf[2];
- $results[1]['limit'] = '70.0';
- $results[1]['percent'] = $results[1]['value']*100/$results[1]['limit'];
- $results[2]['label'] = 'temp3';
- $results[2]['value'] = $ar_buf[3];
- $results[2]['limit'] = '70.0';
- $results[2]['percent'] = $results[2]['value']*100/$results[2]['limit'];
- return $results;
+ $dev1 = new SensorDevice();
+ $dev1->setName('temp1');
+ $dev1->setValue($ar_buf[1]);
+ $dev1->setMax(70);
+ $this->mbinfo->setMbTemp($dev1);
+ $dev2 = new SensorDevice();
+ $dev2->setName('temp1');
+ $dev2->setValue($ar_buf[2]);
+ $dev2->setMax(70);
+ $this->mbinfo->setMbTemp($dev2);
+ $dev3 = new SensorDevice();
+ $dev3->setName('temp1');
+ $dev3->setValue($ar_buf[3]);
+ $dev3->setMax(70);
+ $this->mbinfo->setMbTemp($dev3);
}
-
+
/**
* get fan information
*
- * @return array fans in array with lable
+ * @return void
*/
- public function fans()
+ private function _fans()
{
- $ar_buf = array ();
- $results = array ();
$ar_buf = preg_split("/\t+/", $this->_lines);
- $results[0]['label'] = 'fan1';
- $results[0]['value'] = $ar_buf[4];
- $results[0]['min'] = '3000';
- $results[1]['label'] = 'fan2';
- $results[1]['value'] = $ar_buf[5];
- $results[1]['min'] = '3000';
- $results[2]['label'] = 'fan3';
- $results[2]['value'] = $ar_buf[6];
- $results[2]['min'] = '3000';
- return $results;
+ $dev1 = new SensorDevice();
+ $dev1->setName('fan1');
+ $dev1->setValue($ar_buf[4]);
+ $dev1->setMin(3000);
+ $this->mbinfo->setMbFan($dev1);
+ $dev2 = new SensorDevice();
+ $dev2->setName('fan2');
+ $dev2->setValue($ar_buf[5]);
+ $dev2->setMin(3000);
+ $this->mbinfo->setMbFan($dev2);
+ $dev3 = new SensorDevice();
+ $dev3->setName('fan3');
+ $dev3->setValue($ar_buf[6]);
+ $dev3->setMin(3000);
+ $this->mbinfo->setMbFan($dev3);
}
-
+
/**
* get voltage information
*
* @return array voltage in array with lable
*/
- public function voltage()
+ private function _voltage()
{
- $ar_buf = array ();
- $results = array ();
$ar_buf = preg_split("/\t+/", $this->_lines);
- $results[0]['label'] = 'Vcore1';
- $results[0]['value'] = $ar_buf[7];
- $results[0]['min'] = '0.00';
- $results[0]['max'] = '0.00';
- $results[1]['label'] = 'Vcore2';
- $results[1]['value'] = $ar_buf[8];
- $results[1]['min'] = '0.00';
- $results[1]['max'] = '0.00';
- $results[2]['label'] = '3volt';
- $results[2]['value'] = $ar_buf[9];
- $results[2]['min'] = '0.00';
- $results[2]['max'] = '0.00';
- $results[3]['label'] = '+5Volt';
- $results[3]['value'] = $ar_buf[10];
- $results[3]['min'] = '0.00';
- $results[3]['max'] = '0.00';
- $results[4]['label'] = '+12Volt';
- $results[4]['value'] = $ar_buf[11];
- $results[4]['min'] = '0.00';
- $results[4]['max'] = '0.00';
- $results[5]['label'] = '-12Volt';
- $results[5]['value'] = $ar_buf[12];
- $results[5]['min'] = '0.00';
- $results[5]['max'] = '0.00';
- $results[6]['label'] = '-5Volt';
- $results[6]['value'] = $ar_buf[13];
- $results[6]['min'] = '0.00';
- $results[6]['max'] = '0.00';
- return $results;
+ $dev1 = new SensorDevice();
+ $dev1->setName('Vcore1');
+ $dev1->setValue($ar_buf[7]);
+ $this->mbinfo->setMbVolt($dev1);
+ $dev2 = new SensorDevice();
+ $dev2->setName('Vcore2');
+ $dev2->setValue($ar_buf[8]);
+ $this->mbinfo->setMbVolt($dev2);
+ $dev3 = new SensorDevice();
+ $dev3->setName('3volt');
+ $dev3->setValue($ar_buf[9]);
+ $this->mbinfo->setMbVolt($dev3);
+ $dev4 = new SensorDevice();
+ $dev4->setName('+5Volt');
+ $dev4->setValue($ar_buf[10]);
+ $this->mbinfo->setMbVolt($dev4);
+ $dev5 = new SensorDevice();
+ $dev5->setName('+12Volt');
+ $dev5->setValue($ar_buf[11]);
+ $this->mbinfo->setMbVolt($dev5);
+ $dev6 = new SensorDevice();
+ $dev6->setName('-12Volt');
+ $dev6->setValue($ar_buf[12]);
+ $this->mbinfo->setMbVolt($dev6);
+ $dev7 = new SensorDevice();
+ $dev7->setName('-5Volt');
+ $dev7->setValue($ar_buf[13]);
+ $this->mbinfo->setMbVolt($dev7);
}
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return Void
+ */
+ public function build()
+ {
+ $this->_temperature();
+ $this->_fans();
+ $this->_voltage();
+ }
}
?>
Modified: includes/mb/class.IPMI.inc.php
===================================================================
--- includes/mb/class.IPMI.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.IPMI.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* ipmi sensor class
*
@@ -23,92 +23,83 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class IPMI implements PSI_Interface_Sensor
+class IPMI extends Sensors
{
/**
* content to parse
*
* @var array
*/
- private $_lines = array ();
-
+ private $_lines = array();
+
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* fill the private content var through tcp or file access
*/
public function __construct()
{
- $this->_error = Error::Singleton();
- switch(strtolower(PSI_SENSOR_ACCESS)) {
+ parent::__construct();
+ switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('ipmitool', 'sensor', $lines);
$this->_lines = explode("\n", $lines);
break;
default:
- $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
-
+
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temp()
{
- $result = array ();
- $i = 0;
foreach ($this->_lines as $line) {
$buffer = preg_split("/[ ]+\|[ ]+/", $line);
if ($buffer[2] == "degrees C" && $buffer[5] != "na") {
- $result[$i]['label'] = $buffer[0];
- $result[$i]['value'] = $buffer[1];
- $result[$i]['limit'] = $buffer[8];
- $i++;
+ $dev = new SensorDevice();
+ $dev->setName($buffer[0]);
+ $dev->setValue($buffer[1]);
+ $dev->setMax($buffer[8]);
+ $this->mbinfo->setMbTemp($dev);
}
}
- return $result;
}
-
+
/**
- * get fan information
- *
- * @return array fans in array with lable
- */
- public function fans()
- {
- $result = array ();
- return $result;
- }
-
- /**
* get voltage information
*
- * @return array voltage in array with lable
+ * @return void
*/
- public function voltage()
+ private function _voltage()
{
- $result = array ();
- $i = 0;
foreach ($this->_lines as $line) {
$buffer = preg_split("/[ ]+\|[ ]+/", $line);
if ($buffer[2] == "Volts" && $buffer[5] != "na") {
- $result[$i]['label'] = $buffer[0];
- $result[$i]['value'] = $buffer[1];
- $result[$i]['min'] = $buffer[5];
- $result[$i]['max'] = $buffer[8];
- $i++;
+ $dev = new SensorDevice();
+ $dev->setName($buffer[0]);
+ $dev->setValue($buffer[1]);
+ $dev->setMin($buffer[5]);
+ $dev->setMax($buffer[8]);
+ $this->mbinfo->setMbVolt($dev);
}
}
- return $result;
}
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return Void
+ */
+ public function build()
+ {
+ $this->_temp();
+ $this->_voltage();
+ }
}
?>
Modified: includes/mb/class.K8Temp.inc.php
===================================================================
--- includes/mb/class.K8Temp.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.K8Temp.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -23,85 +23,65 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class K8Temp implements PSI_Interface_Sensor
+class K8Temp extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* content to parse
*
* @var array
*/
- private $_lines = array ();
-
+ private $_lines = array();
+
/**
* fill the private array
*/
function __construct()
{
- $this->_error = Error::Singleton();
+ parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
- case 'command': $lines = "";
+ case 'command':
+ $lines = "";
CommonFunctions::executeProgram('k8temp', '', $lines);
$this->_lines = explode("\n", $lines);
break;
- default: $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ default:
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
-
+
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temperature()
{
- $results = array ();
foreach ($this->_lines as $line) {
if (preg_match('/(.*):\s*(\d*)/', $line, $data)) {
- if ($data[2] <> '0') {
- $results[$i]['label'] = $data[1];
- $results[$i]['limit'] = '70.0';
- if ($data[2] > 250) {
- $results[$i]['value'] = 0;
- $results[$i]['percent'] = 0;
- } else {
- $results[$i]['value'] = $data[2];
- $results[$i]['percent'] = $results[$i]['value'] * 100 / $results[$i]['limit'];
+ if ($data[2] > 0) {
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
+ $dev->setMax('70.0');
+ if ($data[2] < 250) {
+ $dev->setValue($data[2]);
}
- $i++;
+ $this->mbinfo->setMbTemp($dev);
}
}
}
- return $results;
}
-
+
/**
- * get fan information
+ * get the information
*
- * @return array fans in array with lable
- */
- public function fans()
- {
- $results = array ();
- return $results;
- }
-
- /**
- * get voltage information
+ * @see PSI_Interface_Sensor::build()
*
- * @return array voltage in array with lable
+ * @return Void
*/
- public function voltage()
+ public function build()
{
- $results = array ();
- return $results;
+ $this->_temperature();
}
}
?>
Modified: includes/mb/class.LMSensors.inc.php
===================================================================
--- includes/mb/class.LMSensors.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.LMSensors.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -23,16 +23,9 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class LMSensors implements PSI_Interface_Sensor
+class LMSensors extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* content to parse
*
* @var array
@@ -44,7 +37,7 @@
*/
function __construct()
{
- $this->_error = Error::Singleton();
+ parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
@@ -57,7 +50,7 @@
}
break;
default:
- $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
@@ -65,14 +58,14 @@
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temperature()
{
$ar_buf = array();
- $results = array();
+ $data = array();
foreach ($this->_lines as $line) {
- $data = array();
+ unset($data);
if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data)) {
;
} elseif (ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data)) {
@@ -89,7 +82,6 @@
}
}
}
- $i = 0;
foreach ($ar_buf as $line) {
unset($data);
if (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)", $line, $data)) {
@@ -108,35 +100,38 @@
$data[$key] = trim($value);
}
}
- $results[$i]['label'] = $data[1];
- $results[$i]['value'] = $data[2];
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
+ $dev->setValue($data[2]);
+ $limit = 0;
+ $perce = 0;
if (isset($data[6]) && $data[2] > $data[6]) {
- $results[$i]['limit'] = "75";
- $results[$i]['perce'] = "75";
+ $limit = 75;
+ $perce = 75;
} else {
- $results[$i]['limit'] = isset($data[4]) ? $data[4] : "75";
- $results[$i]['perce'] = isset($data[6]) ? $data[6] : "75";
+ $limit = isset($data[4]) ? $data[4] : 75;
+ $perce = isset($data[6]) ? $data[6] : 75;
}
- if ($results[$i]['limit'] < $results[$i]['perce']) {
- $results[$i]['limit'] = $results[$i]['perce'];
+ if ($limit < $perce) {
+ $dev->setMax($perce);
+ } else {
+ $dev->setMax($limit);
}
- $i++;
+ $this->mbinfo->setMbTemp($dev);
}
- asort($results);
- return array_values($results);
}
/**
* get fan information
*
- * @return array fans in array with lable
+ * @return void
*/
- public function fans()
+ private function _fans()
{
$ar_buf = array();
- $results = array();
+ $data = array();
foreach ($this->_lines as $line) {
- $data = array();
+ unset($data);
if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data)) {
;
} elseif (ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data)) {
@@ -157,7 +152,6 @@
}
}
}
- $i = 0;
foreach ($ar_buf as $line) {
unset($data);
if (ereg("(.*):(.*) RPM \((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)", $line, $data)) {
@@ -169,26 +163,27 @@
} else {
ereg("(.*):(.*) RPM", $line, $data);
}
- $results[$i]['label'] = trim($data[1]);
- $results[$i]['value'] = trim($data[2]);
- $results[$i]['min'] = isset($data[4]) ? trim($data[4]) : 0;
- $i++;
+ $dev = new SensorDevice();
+ $dev->setName(trim($data[1]));
+ $dev->setValue(trim($data[2]));
+ if (isset($data[4])) {
+ $dev->setMin(trim($data[4]));
+ }
+ $this->mbinfo->setMbFan($dev);
}
- asort($results);
- return array_values($results);
}
/**
* get voltage information
*
- * @return array voltage in array with lable
+ * @return void
*/
- public function voltage()
+ private function _voltage()
{
$ar_buf = array();
- $results = array();
+ $data = array();
foreach ($this->_lines as $line) {
- $data = array();
+ unset($data);
if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data)) {
;
} else {
@@ -207,7 +202,6 @@
}
}
}
- $i = 0;
foreach ($ar_buf as $line) {
unset($data);
if (ereg("(.*):(.*) V \((.*)=(.*) V,(.*)=(.*) V\)(.*)\)", $line, $data)) {
@@ -225,14 +219,32 @@
}
}
if (isset($data[1])) {
- $results[$i]['label'] = $data[1];
- $results[$i]['value'] = $data[2];
- $results[$i]['min'] = isset($data[4]) ? $data[4] : 0;
- $results[$i]['max'] = isset($data[6]) ? $data[6] : 0;
- $i++;
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
+ $dev->setValue($data[2]);
+ if (isset($data[4])) {
+ $dev->setMin($data[4]);
+ }
+ if (isset($data[6])) {
+ $dev->setMax($data[6]);
+ }
+ $this->mbinfo->setMbVolt($dev);
}
}
- return $results;
}
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return Void
+ */
+ function build()
+ {
+ $this->_temperature();
+ $this->_voltage();
+ $this->_fans();
+ }
}
?>
Modified: includes/mb/class.MBM5.inc.php
===================================================================
--- includes/mb/class.MBM5.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.MBM5.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* MBM5 sensor class
*
@@ -24,37 +24,30 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class MBM5 implements PSI_Interface_Sensor
+class MBM5 extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* array with the names of the labels
*
* @var array
*/
- private $_buf_label = array ();
+ private $_buf_label = array();
-
+
/**
* array withe the values
*
* @var array
*/
- private $_buf_value = array ();
-
+ private $_buf_value = array();
+
/**
* read the MBM5.csv file and fill the private arrays
*/
function __construct()
{
- $this->_error = Error::Singleton();
- switch(strtolower(PSI_SENSOR_ACCESS)) {
+ parent::__construct();
+ switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'file':
$buffer = "";
CommonFunctions::rfts(APP_ROOT."/data/MBM5.csv", $buffer);
@@ -68,76 +61,82 @@
$this->_buf_value = split($delim, substr($buffer[1], 0, -2));
break;
default:
- $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
-
+
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temperature()
{
- $results = array ();
- $intCount = 0;
for ($intPosi = 3; $intPosi < 6; $intPosi++) {
if ($this->_buf_value[$intPosi] == 0) {
- continue ;
+ continue;
}
- $results[$intCount]['label'] = $this->_buf_label[$intPosi];
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
- $results[$intCount]['value'] = $hits[0];
- $results[$intCount]['limit'] = '70.0';
- $intCount++;
+ $dev = new SensorDevice();
+ $dev->setName($this->_buf_label[$intPosi]);
+ $dev->setValue($hits[0]);
+ $dev->setMax(70);
+ $this->mbinfo->setMbTemp($dev);
}
- return $results;
}
-
+
/**
* get fan information
*
- * @return array fans in array with lable
+ * @return void
*/
- public function fans()
+ private function _fans()
{
- $results = array ();
- $intCount = 0;
for ($intPosi = 13; $intPosi < 16; $intPosi++) {
- if (! isset ($this->_buf_value[$intPosi])) {
- continue ;
+ if (!isset($this->_buf_value[$intPosi])) {
+ continue;
}
- $results[$intCount]['label'] = $this->_buf_label[$intPosi];
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
- $results[$intCount]['value'] = $hits[0];
- $results[$intCount]['min'] = '3000';
- $intCount++;
+ $dev = new SensorDevice();
+ $dev->setName($this->_buf_label[$intPosi]);
+ $dev->setValue($hits[0]);
+ $dev->setMin(3000);
+ $this->mbinfo->setMbFan($dev);
}
- return $results;
}
-
+
/**
* get voltage information
*
- * @return array voltage in array with lable
+ * @return void
*/
- public function voltage()
+ private function _voltage()
{
- $results = array ();
- $intCount = 0;
for ($intPosi = 6; $intPosi < 13; $intPosi++) {
if ($this->_buf_value[$intPosi] == 0) {
- continue ;
+ continue;
}
- $results[$intCount]['label'] = $this->_buf_label[$intPosi];
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
- $results[$intCount]['value'] = $hits[0];
- $results[$intCount]['min'] = '0.00';
- $results[$intCount]['max'] = '0.00';
- $intCount++;
+ $dev = new SensorDevice();
+ $dev->setName($this->_buf_label[$intPosi]);
+ $dev->setValue($hits[0]);
+ $this->mbinfo->setMbVolt($dev);
}
- return $results;
}
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return Void
+ */
+ public function build()
+ {
+ $this->_fans();
+ $this->_temperature();
+ $this->_voltage();
+ }
}
?>
Modified: includes/mb/class.MBMon.inc.php
===================================================================
--- includes/mb/class.MBMon.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/mb/class.MBMon.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* mbmon sensor class
*
@@ -23,29 +23,22 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class MBMon implements PSI_Interface_Sensor
+class MBMon extends Sensors
{
/**
- * object for error handling
- *
- * @var Error
- */
- private $_error;
-
- /**
* content to parse
*
* @var array
*/
- private $_lines = array ();
-
+ private $_lines = array();
+
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
- $this->_error = Error::Singleton();
- switch(strtolower(PSI_SENSOR_ACCESS)) {
+ parent::__construct();
+ switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'tcp':
$fp = fsockopen("localhost", 411, $errno, $errstr, 5);
if ($fp) {
@@ -55,7 +48,7 @@
}
$this->_lines = explode("\n", $lines);
} else {
- $this->_error->addError("fsockopen()", $errno." ".$errstr);
+ $this->error->addError("fsockopen()", $errno." ".$errstr);
}
break;
case 'command':
@@ -63,82 +56,84 @@
$this->_lines = explode("\n", $lines);
break;
default:
- $this->_error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
+ $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
-
+
/**
* get temperature information
*
- * @return array temperatures in array with lable
+ * @return void
*/
- public function temperature()
+ private function _temperature()
{
- $results = array ();
- $i = 0;
foreach ($this->_lines as $line) {
if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '0') {
- $results[$i]['label'] = $data[1];
- $results[$i]['limit'] = '70.0';
- if ($data[2] > 250) {
- $results[$i]['value'] = 0;
- $results[$i]['percent'] = 0;
- } else {
- $results[$i]['value'] = $data[2];
- $results[$i]['percent'] = $results[$i]['value']*100/$results[$i]['limit'];
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
+ $dev->setMax(70);
+ if ($data[2] < 250) {
+ $dev->setValue($data[2]);
}
- $i++;
+ $this->mbinfo->setMbTemp($dev);
}
}
}
- return $results;
}
-
+
/**
* get fan information
*
- * @return array fans in array with lable
+ * @return void
*/
- public function fans()
+ private function _fans()
{
- $results = array ();
- $i = 0;
foreach ($this->_lines as $line) {
if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '0') {
- $results[$i]['label'] = $data[1];
- $results[$i]['value'] = $data[2];
- $results[$i]['min'] = '3000';
- $i++;
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
+ $dev->setValue($data[2]);
+ $dev->setMax(3000);
+ $this->mbinfo->setMbFan($dev);
}
}
}
- return $results;
}
-
+
/**
* get voltage information
*
- * @return array voltage in array with lable
+ * @return void
*/
- public function voltage()
+ private function _voltage()
{
- $results = array ();
- $i = 0;
foreach ($this->_lines as $line) {
if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '+0.00') {
- $results[$i]['label'] = $data[1];
- $results[$i]['value'] = $data[2];
- $results[$i]['min'] = '0.00';
- $results[$i]['max'] = '0.00';
- $i++;
+ $dev = new SensorDevice();
+ $dev->setName($data[1]);
+ $dev->setValue($data[2]);
+ $this->mbinfo->setMbVolt($dev);
}
}
}
- return $results;
}
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_Sensor::build()
+ *
+ * @return void
+ */
+ public function build()
+ {
+ $this->_temperature();
+ $this->_voltage();
+ $this->_fans();
+ }
}
?>
Added: includes/mb/class.Sensors.inc.php
===================================================================
--- includes/mb/class.Sensors.inc.php (rev 0)
+++ includes/mb/class.Sensors.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Basic OS Class
+ *
+ * PHP version 5
+ *
+ * @category PHP
+ * @package PSI_OS
+ * @author Michael Cramer <BigMichi1@...>
+ * @copyright 2009 phpSysInfo
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @version SVN: $Id$
+ * @link http://phpsysinfo.sourceforge.net
+ */
+ /**
+ * Basic OS functions for all OS classes
+ *
+ * @category PHP
+ * @package PSI_OS
+ * @author Michael Cramer <BigMichi1@...>
+ * @copyright 2009 phpSysInfo
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @version Release: 3.0
+ * @link http://phpsysinfo.sourceforge.net
+ */
+abstract class Sensors implements PSI_Interface_Sensor
+{
+ /**
+ * object for error handling
+ *
+ * @var Error
+ */
+ protected $error;
+
+ /**
+ * object for the information
+ *
+ * @var MBInfo
+ */
+ protected $mbinfo;
+
+ /**
+ * build the global Error object
+ */
+ public function __construct()
+ {
+ $this->error = Error::singleton();
+ $this->mbinfo = new MBInfo();
+ }
+
+ /**
+ * get the filled or unfilled (with default values) MBInfo object
+ *
+ * @see PSI_Interface_Sensor::getMBInfo()
+ *
+ * @return MBInfo
+ */
+ public final function getMBInfo()
+ {
+ $this->build();
+ return $this->mbinfo;
+ }
+}
+?>
Property changes on: includes/mb/class.Sensors.inc.php
___________________________________________________________________
Added: svn:mime-type
+ text/x-php
Added: svn:keywords
+ Id
Added: svn:eol-style
+ LF
Modified: includes/os/class.BSDCommon.inc.php
===================================================================
--- includes/os/class.BSDCommon.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/os/class.BSDCommon.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -25,13 +25,14 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-abstract class BSDCommon extends OS {
+abstract class BSDCommon extends OS
+{
/**
* content of the syslog
*
* @var array
*/
- private $_dmesg;
+ private $_dmesg = array();
/**
* regexp1 for cpu information out of the syslog
@@ -162,19 +163,14 @@
*/
protected function readdmesg()
{
- $buf = "";
- if (!$this->_dmesg) {
- if (PHP_OS == "Darwin") {
- $this->_dmesg = array();
- } else {
+ if (count($this->_dmesg) === 0) {
+ if (!PHP_OS == "Darwin") {
if (CommonFunctions::rfts('/var/run/dmesg.boot', $buf)) {
$parts = explode("rebooting", $buf);
$this->_dmesg = explode("\n", $parts[count($parts) - 1]);
- } else {
- $this->_dmesg = array();
- }
- }
- }
+ }
+ }
+ }
return $this->_dmesg;
}
@@ -192,105 +188,80 @@
return $buf;
} else {
return '';
- }
+ }
}
/**
* Virtual Host Name
*
- * @return string
+ * @return void
*/
- public function vhostname()
+ protected function hostname()
{
- if (!($result = getenv('SERVER_NAME'))) {
- $result = "N.A.";
- }
- return $result;
- }
-
- /**
- * Canonical Host Name
- *
- @return string
- */
- public function chostname()
- {
- $buf = "";
- if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
- return $buf;
+ if (PSI_USE_VHOST === true) {
+ $this->sys->setHostname(getenv('SERVER_NAME'));
} else {
- return 'N.A.';
- }
+ if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
+ $this->sys->setHostname($buf);
+ }
+ }
}
/**
* IP of the Canonical Host Name
*
- * @return string
+ * @return void
*/
- public function ipaddr()
+ protected function ip()
{
- if (!($result = getenv('SERVER_ADDR'))) {
- $result = gethostbyname($this->chostname());
- }
- return $result;
+ if (PSI_USE_VHOST === true) {
+ $this->sys->setIp(gethostbyname($this->_hostname()));
+ } else {
+ if (!($result = getenv('SERVER_ADDR'))) {
+ $this->sys->setIp(gethostbyname($this->_hostname()));
+ } else {
+ $this->sys->setIp($result);
+ }
+ }
}
/**
- * IP of the Virtual Host Name
- *
- * @return string
- */
- public function vipaddr()
- {
- if (!($result = getenv('SERVER_ADDR'))) {
- $result = gethostbyname($this->chostname());
- }
- return $result;
- }
-
- /**
* Kernel Version
*
- * @return string
+ * @return void
*/
- public function kernel()
+ protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = explode(':', $s);
- return $a[0].$a[1].':'.$a[2];
+ $this->sys->setKernel($a[0].$a[1].':'.$a[2]);
}
/**
* Number of Users
*
- * @return integer
+ * @return void
*/
- public function users()
+ protected function users()
{
- $buf = "";
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
- return $buf;
- } else {
- return - 1;
- }
+ $this->sys->setUsers($buf);
+ }
}
/**
* Processor Load
* optionally create a loadbar
*
- * @param boolean $bar include a bar
- *
- * @return array
+ * @return void
*/
- public function loadavg($bar = false)
+ protected function loadavg()
{
$s = $this->grabkey('vm.loadavg');
$s = ereg_replace('{ ', '', $s);
$s = ereg_replace(' }', '', $s);
- $results['avg'] = explode(' ', $s);
- if ($bar) {
+ $this->sys->setLoad($s);
+ if (PSI_LOAD_BAR) {
if ($fd = $this->grabkey('kern.cp_time')) {
// Find out the CPU load
// user + sys = load
@@ -304,130 +275,106 @@
preg_match($this->_CPURegExp2, $fd, $res);
$load2 = $res[2] + $res[3] + $res[4];
$total2 = $res[2] + $res[3] + $res[4] + $res[5];
- $results['cpupercent'] = (100 * ($load2 - $load)) / ($total2 - $total);
- }
- }
- return $results;
+ $this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
+ }
+ }
}
/**
* CPU information
*
- * @return array
+ * @return void
*/
- public function cpuinfo()
+ protected function cpuinfo()
{
- $results = array();
- $ar_buf = array();
- $results['model'] = $this->grabkey('hw.model');
- $results['cpus'] = $this->grabkey('hw.ncpu');
- for ($i = 0, $max = count($this->readdmesg()); $i < $max; $i++) {
- $buf = $this->_dmesg[$i];
- if (preg_match("/".$this->_CPURegExp1."/", $buf, $ar_buf)) {
- $results['cpuspeed'] = round($ar_buf[2]);
+ $dev = new CpuDevice();
+ $dev->setModel($this->grabkey('hw.model'));
+ foreach ($this->readdmesg() as $line) {
+ if (preg_match("/".$this->_CPURegExp1."/", $line, $ar_buf)) {
+ $dev->setCpuSpeed(round($ar_buf[2]));
break;
- }
- }
- return $results;
+ }
+ }
+ $this->sys->setCpus($dev);
}
/**
* SCSI devices
* get the scsi device information out of dmesg
*
- * @return array
+ * @return void
*/
- public function scsi()
+ protected function scsi()
{
- $results = array();
- $ar_buf = array();
- for ($i = 0, $max = count($this->readdmesg()); $i < $max; $i++) {
- $buf = $this->_dmesg[$i];
- if (preg_match("/".$this->_SCSIRegExp1."/", $buf, $ar_buf)) {
- $s = $ar_buf[1];
- $results[$s]['model'] = $ar_buf[2];
- $results[$s]['media'] = 'Hard Disk';
- } elseif (preg_match("/".$this->_SCSIRegExp2."/", $buf, $ar_buf)) {
- $s = $ar_buf[1];
- $results[$s]['capacity'] = $ar_buf[2] * 2048 * 1.049;
- }
- }
- asort($results);
- return $results;
+ foreach ($this->readdmesg() as $line) {
+ if (preg_match("/".$this->_SCSIRegExp1."/", $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1]);
+ $this->sys->setScsiDevices($dev);
+ } elseif (preg_match("/".$this->_SCSIRegExp2."/", $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1]);
+ $dev->setCapacity($ar_buf[2] * 2048 * 1.049);
+ $this->sys->setScsiDevices($dev);
+ }
+ }
}
/**
* PCI devices
* get the pci device information out of dmesg
*
- * @return array
+ * @return void
*/
- public function pci()
+ protected function pci()
{
- $results = array();
if (!(is_array($results = Parser::lspci()) || is_array($results = Parser::pciconf()))) {
- for ($i = 0, $s = 0; $i < count($this->readdmesg()); $i++) {
- $buf = $this->_dmesg[$i];
- if (preg_match("/".$this->_PCIRegExp1."/", $buf, $ar_buf)) {
- $results[$s++] = $ar_buf[1].": ".$ar_buf[2];
- } elseif (preg_match("/".$this->_PCIRegExp2."/", $buf, $ar_buf)) {
- $results[$s++] = $ar_buf[1].": ".$ar_buf[2];
- }
- }
- asort($results);
- }
- return $results;
+ foreach ($this->readdmesg() as $line) {
+ if (preg_match("/".$this->_PCIRegExp1."/", $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1].": ".$ar_buf[2]);
+ $results[] = $dev;
+ } elseif (preg_match("/".$this->_PCIRegExp2."/", $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1].": ".$ar_buf[2]);
+ $results[] = $dev;
+ }
+ }
+ }
+ foreach ($results as $device) {
+ $this->sys->setPciDevices($dev);
+ }
}
/**
* IDE devices
* get the ide device information out of dmesg
*
- * @return array
+ * @return void
*/
- public function ide()
+ protected function ide()
{
- $results = array();
- $s = 0;
- for ($i = 0, $max = count($this->readdmesg()); $i < $max; $i++) {
- $buf = $this->_dmesg[$i];
- if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $buf, $ar_buf)) {
- $s = $ar_buf[1];
- $results[$s]['model'] = $ar_buf[3];
- $results[$s]['media'] = 'Hard Disk';
- $results[$s]['capacity'] = $ar_buf[2] * 1024;
- } elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $buf, $ar_buf)) {
- $s = $ar_buf[1];
- $results[$s]['model'] = $ar_buf[3];
- $results[$s]['media'] = 'CD-ROM';
- }
- }
- asort($results);
- return $results;
+ foreach ($this->readdmesg() as $line) {
+ if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1]);
+ $dev->setCapacity($ar_buf[2] * 1024);
+ $this->sys->setIdeDevices($dev);
+ } elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1]);
+ $this->sys->setIdeDevices($dev);
+ }
+ }
}
/**
- * USB devices
- * place holder function until we add acual usb detection
- *
- * @return array
- */
- public function usb()
- {
- // FIXME
- $results = array();
- return $results;
- }
-
- /**
* Physical memory information and Swap Space information
*
- * @return array
+ * @return void
*/
- public function memory()
+ protected function memory()
{
- $pstat = "";
- $s = $this->grabkey('hw.physmem');
if (PHP_OS == 'FreeBSD' || PHP_OS == 'OpenBSD') {
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
// I should probably add some version checking here, but for now
@@ -435,97 +382,84 @@
$pagesize = 1024;
} else {
$pagesize = $this->grabkey('hw.pagesize');
- }
- $results['ram'] = array();
- if (!CommonFunctions::executeProgram('vmstat', '', $pstat, PSI_DEBUG)) {
- $pstat = '';
- }
- $lines = split("\n", $pstat);
- for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\s+/", trim($lines[$i]), 19);
- if ($i == 2) {
- if (PHP_OS == 'NetBSD' || PHP_OS == 'DragonFly') {
- $results['ram']['free'] = $ar_buf[4] * 1024;
- } else {
- $results['ram']['free'] = $ar_buf[4] * $pagesize;
- }
- }
- }
- $results['ram']['total'] = $s;
- $results['ram']['shared'] = 0;
- $results['ram']['buffers'] = 0;
- $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
- $results['ram']['cached'] = 0;
- $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
- if (PHP_OS == 'OpenBSD' || PHP_OS == 'NetBSD') {
- if (!CommonFunctions::executeProgram('swapctl', '-l -k', $pstat, PSI_DEBUG)) {
- $pstat = '';
- }
- } else {
- if (!CommonFunctions::executeProgram('swapinfo', '-k', $pstat, PSI_DEBUG)) {
- $pstat = '';
- }
- }
- $lines = split("\n", $pstat);
- $results['swap']['total'] = 0;
- $results['swap']['used'] = 0;
- $results['swap']['free'] = 0;
- $results['swap']['percent'] = 0;
- for ($i = 1, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\s+/", $lines[$i], 6);
- if ($ar_buf[0] != 'Total') {
- $results['swap']['total'] = $results['swap']['total'] + $ar_buf[1] * 1024;
- $results['swap']['used'] = $results['swap']['used'] + $ar_buf[2] * 1024;
- $results['swap']['free'] = $results['swap']['free'] + $ar_buf[3] * 1024;
- $results['devswap'][$i - 1] = array();
- $results['devswap'][$i - 1]['dev'] = $ar_buf[0];
- $results['devswap'][$i - 1]['total'] = $ar_buf[1] * 1024;
- $results['devswap'][$i - 1]['used'] = $ar_buf[2] * 1024;
- $results['devswap'][$i - 1]['free'] = ($results['devswap'][$i - 1]['total'] - $results['devswap'][$i - 1]['used']);
- if ($ar_buf[2] > 0) {
- $results['devswap'][$i - 1]['percent'] = round(($ar_buf[2] * 100) / $ar_buf[1]);
- } else {
- $results['devswap'][$i - 1]['percent'] = 0;
- }
- }
- }
- if (($i - 1) > 0) {
- if (($results['swap']['total'] > 0)) {
- $results['swap']['percent'] = ceil(($results['swap']['used'] * 100) / $results['swap']['total']);
-
+ }
+ if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
+ $lines = split("\n", $vmstat);
+ $ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
+ if (PHP_OS == 'NetBSD' || PHP_OS == 'DragonFly') {
+ $this->sys->setMemFree($ar_buf[4] * 1024);
} else {
- $results['swap']['percent'] = 0;
- }
- }
- if (is_callable(array($this, 'memoryadditional'))) {
- $this->memoryadditional($results);
- }
- return $results;
+ $this->sys->setMemFree($ar_buf[4] * $pagesize);
+ }
+ $this->sys->setMemTotal($this->grabkey('hw.physmem'));
+ $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
+
+ if (((PHP_OS == 'OpenBSD' || PHP_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
+ $lines = split("\n", $swapstat);
+ foreach ($lines as $line) {
+ $ar_buf = preg_split("/\s+/", $line, 6);
+ if ($ar_buf[0] != 'Total') {
+ $dev = new DiskDevice();
+ $dev->setMountPoint($ar_buf[0]);
+ $dev->setName("SWAP");
+ $dev->setFsType('swap');
+ $dev->setTotal($ar_buf[1] * 1024);
+ $dev->setUsed($ar_buf[2] * 1024);
+ $dev->setFree($dev->getTotal() - $dev->getUsed());
+ $this->sys->setSwapDevices($dev);
+ }
+ }
+ }
+ }
}
/**
* filesystem information
*
- * @return array
+ * @return void
*/
- public function filesystems()
+ protected function filesystems()
{
- return Parser::df();
+ $arrResult = Parser::df();
+ foreach ($arrResult as $dev) {
+ $this->sys->setDiskDevices($dev);
+ }
}
/**
* Distribution
*
- * @return string
+ * @return void
*/
- public function distro()
+ protected function distro()
{
- $result = "";
if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
- return $result;
- } else {
- return 'N.A.';
- }
- }
+ $this->sys->setDistribution($result);
+ }
+ }
+
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_OS::build()
+ *
+ * @return Void
+ */
+ function build()
+ {
+ $this->distro();
+ $this->memory();
+ $this->ide();
+ $this->pci();
+ $this->cpuinfo();
+ $this->filesystems();
+ $this->kernel();
+ $this->users();
+ $this->loadavg();
+ $this->hostname();
+ $this->ip();
+ $this->scsi();
+ }
}
?>
Modified: includes/os/class.Darwin.inc.php
===================================================================
--- includes/os/class.Darwin.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/os/class.Darwin.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -25,7 +25,8 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class Darwin extends BSDCommon {
+class Darwin extends BSDCommon
+{
/**
* define the regexp for log parser
*/
@@ -47,14 +48,13 @@
*/
protected function grabkey($key)
{
- $s = "";
if (CommonFunctions::executeProgram('sysctl', $key, $s, PSI_DEBUG)) {
$s = ereg_replace($key.': ', '', $s);
$s = ereg_replace($key.' = ', '', $s);
return $s;
} else {
return '';
- }
+ }
}
/**
@@ -66,7 +66,6 @@
*/
private function _grabioreg($key)
{
- $s = "";
if (CommonFunctions::executeProgram('ioreg', '-cls "'.$key.'" | grep "'.$key.'"', $s, PSI_DEBUG)) {
$s = ereg_replace('\|', '', $s);
$s = ereg_replace('\+\-\o', '', $s);
@@ -75,190 +74,148 @@
return $s;
} else {
return '';
- }
+ }
}
/**
* UpTime
* time the system is running
*
- * @return integer
+ * @return void
*/
- public function uptime()
+ private function _uptime()
{
- $a = "";
if (CommonFunctions::executeProgram('sysctl', '-n kern.boottime', $a, PSI_DEBUG)) {
- $sys_ticks = time() - $a;
- return $sys_ticks;
- } else {
- return 0;
- }
+ $this->sys->setUptime(time() - $a);
+ }
}
/**
* get CPU information
*
- * @return array
+ * @return void
*/
- public function cpuinfo()
+ protected function cpuinfo()
{
- $results = array();
- $buf = "";
- $buffer = array();
- if (!CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
- $buf = 'N.A.';
- }
- $results['model'] = ereg_replace('Processor type: ', '', $buf);
- $results['cpus'] = $this->grabkey('hw.ncpu');
- $results['cpuspeed'] = round($this->grabkey('hw.cpufrequency') / 1000000);
- $results['busspeed'] = round($this->grabkey('hw.busfrequency') / 1000000);
- $results['cache'] = round($this->grabkey('hw.l2cachesize'));
-
- if (CommonFunctions::rfts(APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
- $buffer = split("\n", $buffer);
- foreach ($buffer as $line) {
- $ar_buf = split(":", $line, 2);
- if ($modelRAW === trim($ar_buf[0])) {
- $results['model'] = trim($ar_buf[1]);
- }
- }
- }
- return $results;
+ $dev = new CpuDevice();
+ if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
+ if (CommonFunctions::rfts(APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
+ $buffer = split("\n", $buffer);
+ foreach ($buffer as $line) {
+ $ar_buf = split(":", $line, 2);
+ if (trim($buf) === trim($ar_buf[0])) {
+ $dev->setModel(trim($ar_buf[1]));
+ }
+ }
+ }
+ $dev->setModel(ereg_replace('Processor type: ', '', $buf));
+ }
+ $dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
+ $dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
+ $dev->setCache(round($this->grabkey('hw.l2cachesize')));
}
/**
* get the pci device information out of ioreg
*
- * @return array
+ * @return void
*/
- public function pci()
+ protected function pci()
{
- $results = array();
$s = $this->_grabioreg('IOPCIDevice');
$lines = split("\n", $s);
- for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\s+/", $lines[$i], 19);
- $results[$i] = $ar_buf[0];
- }
- asort($results);
- return array_values(array_unique($results));
+ foreach ($lines as $line) {
+ $ar_buf = preg_split("/\s+/", $line, 19);
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[0]);
+ $this->sys->setIdeDevices($dev);
+ }
}
/**
* get the ide device information out of ioreg
*
- * @return array
+ * @return void
*/
- public function ide()
+ protected function ide()
{
- $results = array();
$s = $this->_grabioreg('IOATABlockStorageDevice');
$lines = split("\n", $s);
- $j = 0;
- for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\/\//", $lines[$i], 19);
+ foreach ($lines as $line) {
+ $ar_buf = preg_split("/\/\//", $line, 19);
if (isset($ar_buf[1]) && $ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
- $results[$j++]['model'] = $ar_buf[0];
- }
- }
- asort($results);
- return array_values(array_unique($results));
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[0]);
+ $this->sys->setIdeDevices($dev);
+ }
+ }
}
/**
* get memory and swap information
*
- * @return array
+ * @return void
*/
- public function memory()
+ protected function memory()
{
- $pstat = "";
$s = $this->grabkey('hw.memsize');
- $results['ram'] = array();
- $results['swap'] = array();
- $results['devswap'] = array();
- if (!CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
- $pstat = '';
- }
- $lines = split("\n", $pstat);
- for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\s+/", $lines[$i], 19);
- if ($i == 1) {
- // calculate free memory from page sizes (each page = 4MB)
- $results['ram']['free'] = $ar_buf[2] * 4 * 1024;
- }
- }
- $results['ram']['total'] = $s;
- $results['ram']['shared'] = 0;
- $results['ram']['buffers'] = 0;
- $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
- $results['ram']['cached'] = 0;
- $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
-
-
- $swapBuff = "";
- if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
- $swap1 = split('M', $swapBuff);
- $swap2 = split('=', $swap1[1]);
- $swap3 = split('=', $swap1[2]);
+ if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
+ $lines = split("\n", $pstat);
+ $ar_buf = preg_split("/\s+/", $lines[1], 19);
+ // calculate free memory from page sizes (each page = 4MB)
+ $this->sys->setMemTotal($s);
+ $this->sys->setMemFree($ar_buf[2] * 4 * 1024);
+ $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
- $results['swap']['total'] = $swap1[0] * 1024 * 1024;
- $results['swap']['used'] = $swap2[1] * 1024 * 1024;
- $results['swap']['free'] = $swap3[1] * 1024 * 1024;
- if ($results['swap']['total'] <= 0) {
- $results['swap']['percent'] = 0;
- } else {
- $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
- }
- }
- return $results;
+ if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
+ $swap1 = split('M', $swapBuff);
+ $swap2 = split('=', $swap1[1]);
+ $swap3 = split('=', $swap1[2]);
+ $dev = new DiskDevice();
+ $dev->setName('SWAP');
+ $dev->setFsType('swap');
+ $dev->setTotal($swap1[0] * 1024 * 1024);
+ $dev->setUsed($swap2[1] * 1024 * 1024);
+ $dev->setFree($swap3[1] * 1024 * 1024);
+ $this->sys->setSwapDevices($dev);
+ }
+ }
}
/**
* get network information
*
- * @return array
+ * @return void
*/
- public function network()
+ private function _network()
{
- $netstat = "";
if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
$lines = split("\n", $netstat);
- $results = array();
- for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\s+/", $lines[$i], 10);
+ foreach ($lines as $line) {
+ $ar_buf = preg_split("/\s+/", $line, 10);
if (! empty($ar_buf[0])) {
- $results[$ar_buf[0]] = array();
- $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
- $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
- $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
- $results[$ar_buf[0]]['drop'] = isset($ar_buf[10]) ? $ar_buf[10] : 0;
- }
- }
- return $results;
- } else {
- return array();
- }
+ $dev = new NetDevice();
+ $dev->setName($ar_buf[0]);
+ $dev->setTxBytes($ar_buf[8]);
+ $dev->setRxBytes($ar_buf[5]);
+ $dev->setErrors($ar_buf[4] + $ar_buf[7]);
+ if (isset($ar_buf[10])) {
+ $dev->setDrops($ar_buf[10]);
+ }
+ $this->sys->setNetDevices($dev);
+ }
+ }
+ }
}
/**
* get icon name
*
- * @return string
+ * @return void
*/
- public function distroicon()
+ protected function distro()
{
- $result = 'Darwin.png';
- return $result;
- }
-
- /**
- * get distribution name
- *
- * @return string
- */
- public function distro()
- {
+ $this->sys->setDistributionIcon('Darwin.png');
if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) {
parent::distro();
} else {
@@ -266,12 +223,25 @@
foreach ($arrBuff as $line) {
$arrLine = split(':', $line);
if (trim($arrLine[0]) === "System Version") {
- $result = trim($arrLine[1]);
- break;
- }
- }
- return $result;
- }
- }
+ $this->sys->setDistribution(trim($arrLine[1]));
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * get the information
+ *
+ * @see PSI_Interface_OS::build()
+ *
+ * @return Void
+ */
+ function build()
+ {
+ parent::build();
+ $this->_uptime();
+ $this->_network();
+ }
}
?>
Modified: includes/os/class.DragonFly.inc.php
===================================================================
--- includes/os/class.DragonFly.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/os/class.DragonFly.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -24,7 +24,8 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class DragonFly extends BSDCommon {
+class DragonFly extends BSDCommon
+{
/**
* define the regexp for log parser
*/
@@ -42,54 +43,39 @@
* UpTime
* time the system is running
*
- * @return integer
+ * @return void
*/
- public function uptime()
+ private function _uptime()
{
$a = $this->grab_key('kern.boottime');
preg_match("/sec = ([0-9]+)/", $a, $buf);
- $sys_ticks = time() - $buf[1];
- return $sys_ticks;
+ $this->sys->setUptime(time() - $buf[1]);
}
/**
- * load bar not implemented yet, so call everytime with false
- *
- * @param boolean $bar control if a bar is displayed
- *
- * @return array
- */
- public function loadavg($bar = false)
- {
- return parent::loadavg(false);
- }
-
- /**
* get network information
*
* @return array
*/
- public function network()
+ private function _network()
{
- $netstat_b = "";
- $netstat_n = "";
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = split("\n", $netstat_b);
$lines_n = split("\n", $netstat_n);
- $results = array();
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
- $results[$ar_buf_b[0]] = array();
- $results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[5];
- $results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[8];
- $results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
- $results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
- }
- }
- return $results;
+ $dev = new NetDevice();
+ $dev->setName($ar_buf_b[0]);
+ $dev->setTxBytes($ar_buf_b[8]);
+ $dev->setRxBytes($ar_buf_b[5]);
+ $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
+ $dev->setDrops($ar_buf_n[8]);
+ $this->sys->setNetDevices($dev);
+ }
+ }
}
/**
@@ -97,36 +83,43 @@
*
* @return array
*/
- public function ide()
+ protected function ide()
{
- $results = array();
- $s = 0;
- $dmesg = $this->readdmesg();
- for ($i = 0, $max = count($dmesg); $i < $max; $i++) {
- $buf = $dmesg[$i];
- if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]\-(.*)) (.*)/', $buf, $ar_buf)) {
- $results[$ar_buf[1]]['model'] = $ar_buf[3];
- if (preg_match("/^acd[0-9](.*)/", $ar_buf[1])) {
- $results[$ar_buf[1]]['media'] = $ar_buf[2];
- } else {
- $results[$ar_buf[1]]['media'] = 'Hard Disk';
- $results[$ar_buf[1]]['capacity'] = $ar_buf[2] * 1024;
- }
- }
- }
- asort($results);
- return $results;
+ foreach ($this->readdmesg() as $line) {
+ if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]\-(.*)) (.*)/', $line, $ar_buf)) {
+ $dev = new HWDevice();
+ $dev->setName($ar_buf[1]);
+ if (!preg_match("/^acd[0-9](.*)/", $ar_buf[1])) {
+ $dev->setCapacity($ar_buf[2] * 1024);
+ }
+ $this->sys->setIdeDevices($dev);
+ }
+ }
}
/**
* get icon name
*
- * @return string
+ * @return void
*/
- public function distroicon()
+ private function _distroicon()
{
- $result = 'DragonFly.png';
- return ($result);
- }
+ $this->sys->setDistributionIcon('DragonFly.png');
+ }
+
+ /**
+ * get the information
+ *
+ * @see BSDCommon::build()
+ *
+ * @return Void
+ */
+ function build()
+ {
+ parent::build();
+ $this->_distroicon();
+ $this->_network();
+ $this->_uptime();
+ }
}
?>
Modified: includes/os/class.FreeBSD.inc.php
===================================================================
--- includes/os/class.FreeBSD.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/os/class.FreeBSD.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -24,11 +24,10 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class FreeBSD extends BSDCommon {
+class FreeBSD extends BSDCommon
+{
/**
* define the regexp for log parser
- *
- * @access public
*/
public function __construct()
{
@@ -45,76 +44,84 @@
* UpTime
* time the system is running
*
- * @return integer
+ * @return void
*/
- public function uptime()
+ private function _uptime()
{
$s = explode(' ', $this->grabkey('kern.boottime'));
$a = ereg_replace('{ ', '', $s[3]);
- $sys_ticks = time() - $a;
- return $sys_ticks;
+ $this->sys->setUptime(time() - $a);
}
/**
* get network information
*
- * @return array
+ * @return void
*/
- public function network()
+ private function _network()
{
- $netstat = "";
- if (!CommonFunctions::executeProgram('netstat', '-nibd | grep Link', $netstat, PSI_DEBUG)) {
- $netstat = '';
- }
- $lines = split("\n", $netstat);
- $results = array();
- for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
- $ar_buf = preg_split("/\s+/", $lines[$i]);
- if (! empty($ar_buf[0])) {
- $results[$ar_buf[0]] = array();
- if (strlen($ar_buf[3]) < 15) {
- $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
- $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
- $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
- $results[$ar_buf[0]]['drop'] = $ar_buf[10];
- } else {
- $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[6];
- $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[9];
- $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[8];
- $results[$ar_buf[0]]['drop'] = $ar_buf[11];
- }
- }
- }
- return $results;
+ if (CommonFunctions::executeProgram('netstat', '-nibd | grep Link', $netstat, PSI_DEBUG)) {
+ $lines = split("\n", $netstat);
+ foreach ($lines as $line) {
+ $ar_buf = preg_split("/\s+/", $line);
+ if (! empty($ar_buf[0])) {
+ $dev = new NetDevice();
+ $dev->setName($ar_buf[0]);
+ if (strlen($ar_buf[3]) < 15) {
+ $dev->setTxBytes($ar_buf[8]);
+ $dev->setRxBytes($ar_buf[5]);
+ $dev->setDrops($ar_buf[10]);
+ $dev->setErrors($ar_buf[4] + $ar_buf[7]);
+ } else {
+ $dev->setTxBytes($ar_buf[9]);
+ $dev->setRxBytes($ar_buf[6]);
+ $dev->setErrors($ar_buf[5] + $ar_buf[8]);
+ $dev->setDrops($ar_buf[11]);
+ }
+ $this->sys->setNetDevices($dev);
+ }
+ }
+ }
}
/**
* get icon name
*
- * @return string
+ * @return void
*/
- public function distroicon()
+ private function _distroicon()
{
- $result = 'FreeBSD.png';
- return $result;
+ $this->sys->setDistributionIcon('FreeBSD.png');
}
/**
* extend the memory information with additional values
*
- * @param array &$results memory array to which the additional information are added
+ * @return void
+ */
+ private function _memoryadditional()
+ {
+ $pagesize = $this->grabkey("hw.pagesize");
+ $this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
+ $this->sys->setMemApplication($this->grabkey("vm.stats.vm.v_active_count") * $pagesize);
+ $this->sys->setMemBuffer($this->sys->getMemTotal() - $this->sys->getMemApplication() - $this->sys->getMemCache());
+ }
+
+
+ /**
+ * get the information
*
- * @return array memory array with the additional information
+ * @see BSDCommon::build()
+ *
+ * @return Void
*/
- protected function memoryadditional(&$results)
+ function build()
{
- $pagesize = $this->grabkey("hw.pagesize");
- $results['ram']['cached'] = $this->grabkey("vm.stats.vm.v_cache_count") * $pagesize;
- $results['ram']['cached_percent'] = round($results['ram']['cached'] * 100 / $results['ram']['total']);
- $results['ram']['app'] = $this->grabkey("vm.stats.vm.v_active_count") * $pagesize;
- $results['ram']['app_percent'] = round($results['ram']['app'] * 100 / $results['ram']['total']);
- $results['ram']['buffers'] = $results['ram']['used'] - $results['ram']['app'] - $results['ram']['cached'];
- $results['ram']['buffers_percent'] = round($results['ram']['buffers'] * 100 / $results['ram']['total']);
- }
+ parent::build();
+ $this->_memoryadditional();
+ $this->_distroicon();
+ $this->_network();
+ $this->_uptime();
+ }
}
?>
Modified: includes/os/class.HPUX.inc.php
===================================================================
--- includes/os/class.HPUX.inc.php 2009-06-22 10:48:33 UTC (rev 262)
+++ includes/os/class.HPUX.inc.php 2009-06-22 13:01:52 UTC (rev 263)
@@ -24,499 +24,382 @@
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
-class HPUX implements PSI_Interface_OS {
+class HPUX extends OS
+{
/**
* Virtual Host Name
*
- * @return string
+ * @return void
*/
- public function vhostname()
+ private function _hostname()
{
- if (!($result = getenv('SERVER_NAME'))) {
- $result = 'N.A.';
- }
- return $result;
+ if (PSI_USE_VHOST === true) {
+ $this->sys->setHostname(getenv('SERVER_NAME'));
+ } else {
+ if (CommonFunctions::executeProgram('hostname', '', $ret)) {
+ $this->sys->setHostname($ret);
+ }
+ }
}
/**
* IP of the Virtual Host Name
*
- * @return string
+ * @return void
*/
- public function vipaddr()
+ private function _ip()
{
- return gethostbyname($this->vhostname());
- }
-
- /**
- * Canonical Host Name
- *
- @return string
- */
- public function chostname()
- {
- $ret = "";
- if (CommonFunctions::executeProgram('hostname', '', $ret)) {
- return $ret;
+ if (PSI_USE_VHOST === true) {
+ $this->sys->setIp(gethostbyname($this->_hostname()));
} else {
- return 'N.A.';
- }
+ if (!($result = getenv('SERVER_ADDR'))) {
+ $this->sys->setIp(gethostbyname($this->_hostname()));
+ } else {
+ $this->sys->setIp($result);
+ }
+ }
}
/**
- * IP of the Canonical Host Name
- *
- * @return string
- */
- public function ipaddr()
- {
- if (!($result = getenv('SERVER_ADDR'))) {
- $result = gethostbyname($this->chostname());
- }
- return $result;
- }
-
- /**
* HP-UX Version
*
- * @return string
+ * @return void
*/
- public function kernel()
+ private function _kernel()
{
- $ret = "";
if (CommonFunctions::executeProgram('uname', '-srvm', $ret)) {
- return $ret;
- } else {
- return 'N.A.';
- }
+ $this->sys->setKernel($ret);
+ }
}
/**
* UpTime
* time the system is running
*
- * @return integer
+ * @return void
*/
- public function uptime()
+ private function _uptime()
{
- $buf = "";
- $result = -1;
- $ar_buf = array();
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
- $result = $days * 86400 + $hours * 3600 + $min * 60;
- }
- }
- return $result;
+ $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
+ }
+ }
}
/**
* Number of Users
*
- * @return integer
+ * @return void
*/
- public function users()
+ private function _users()
{
- $ret = "";
if (CommonFunctions::executeProgram('who', '-q', $ret)) {
$who = split('=', $ret);
- $result = $who[1];
- return $result;
- } else {
- return - 1;
- }
+ $this->sys->setUsers($who[1]);
+ }
}
/**
* Processor Load
* optionally create a loadbar
*
- * @param boolean $bar include a bar
- *
- * @return array
+ * @return void
*/
- public function loadavg($bar = false)
+ private function _loadavg()
{
- $buf = "";
- $ar_buf = array();
- $results['avg'] = array('N.A.', 'N.A.', 'N.A.');
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
- $results['avg'] = array($ar_buf[1], $ar_buf[2], $ar_buf[3]);
- }
- }
- return $results;
+ $this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
+ }
+ }
}
/**
* CPU information
* All of the tags here are highly architecture dependant
*
- * @return array
+ * @return void
*/
- public function cpuinfo()
+ private function _cpuinfo()
{
- $results = array();
- $ar_buf = array();
- $bufr = "";
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
- $bufe = explode("\n", $bufr);
- foreach ($bufe as $buf) {
- list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);
- switch ($key) {
- case 'model name':
- $results['model'] = $value;
- break;
- case 'cpu MHz':
- $results['cpuspeed'] = sprintf('%.2f', $value);
- break;
- case 'cycle frequency [Hz]':
- // For Alpha arch - 2.2.x
- $results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
- break;
- case 'clock':
- // For PPC arch (damn borked POS)
- $results['cpuspeed'] = sprintf('%.2f', $value);
- break;
- case 'cpu':
- // For PPC arch (damn borked POS)
- $results['model'] = $value;
- break;
- case 'revision':
- // For PPC arch (damn borked POS)
- $results['model'] .= ' ( rev: '.$value.')';
- break;
- case 'cpu model':
- // For Alpha arch - 2.2.x
- $results['model'] .= ' ('.$value.')';
- break;
- case 'cache size':
- $results['cache'] = $value * 1024;
- break;
- case 'bogomips':
- $results['bogomips'] += $value;
- break;
- case 'BogoMIPS':
- // For alpha arch - 2.2.x
- $results['bogomips'] += $value;
- break;
- case 'BogoMips':
- // For sparc arch
- $results['bogomips'] += $value;
- break;
- case 'cpus detected':
- // For Alpha arch - 2.2.x
- $results['cpus'] += $value;
- break;
- case 'system type':
- // Alpha arch - 2.2.x
- $results['model'] .= ', '.$value.' ';
- break;
- case 'platform string':
- // Alpha arch - 2.2.x
- $results['model'] .= ' ('.$value.')';
- break;
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|