本文整理汇总了PHP中NetDevice::setTxBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP NetDevice::setTxBytes方法的具体用法?PHP NetDevice::setTxBytes怎么用?PHP NetDevice::setTxBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetDevice
的用法示例。
在下文中一共展示了NetDevice::setTxBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _network
/**
* get network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-nibd | grep Link', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
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);
}
}
}
}
示例2: _network
/**
* get network information
*
* @return void
*/
private function _network()
{
$dev = null;
if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\\s+/", $line);
if (!empty($ar_buf[0])) {
if (preg_match('/^<Link/i', $ar_buf[2])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
if (strlen($ar_buf[3]) < 17) {
/* no Address */
if (isset($ar_buf[11]) && trim($ar_buf[11]) != '') {
/* Idrop column exist*/
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[4] + $ar_buf[8]);
$dev->setDrops($ar_buf[11] + $ar_buf[5]);
} else {
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
$dev->setDrops($ar_buf[10]);
}
} else {
if (isset($ar_buf[12]) && trim($ar_buf[12]) != '') {
/* Idrop column exist*/
$dev->setTxBytes($ar_buf[10]);
$dev->setRxBytes($ar_buf[7]);
$dev->setErrors($ar_buf[5] + $ar_buf[9]);
$dev->setDrops($ar_buf[12] + $ar_buf[6]);
} else {
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[8]);
$dev->setDrops($ar_buf[11]);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && CommonFunctions::executeProgram('ifconfig', $ar_buf[0] . ' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\\s+ether\\s+(\\S+)/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', $ar_buf2[1]));
} elseif (preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
} elseif ((preg_match('/^\\s+inet6\\s+([^\\s%]+)\\s+prefixlen/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\s+([^\\s%]+)%\\S+\\s+prefixlen/i', $buf2, $ar_buf2)) && $ar_buf2[1] != "::" && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
}
示例3: _network
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_b, PSI_DEBUG);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_n, PSI_DEBUG);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
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]) || $ar_buf_n[3] === "0")) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0] . ' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$speedinfo = "";
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\\s+lladdr\\s+(\\S+)/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
} elseif ((preg_match('/^\\s+inet6\\s+([^\\s%]+)\\s+prefixlen/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\s+([^\\s%]+)%\\S+\\s+prefixlen/i', $buf2, $ar_buf2)) && $ar_buf2[1] != "::" && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . strtolower($ar_buf2[1]));
} elseif (preg_match('/^\\s+media:\\s+/i', $buf2) && preg_match('/[\\(\\s](\\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2]) == "G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/\\s(\\S+)-duplex/i', $buf2, $ar_buf3)) {
$speedinfo = $ar_buf2[1] . $unit . 'b/s ' . strtolower($ar_buf3[1]);
} else {
$speedinfo = $ar_buf2[1] . $unit . 'b/s';
}
}
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speedinfo);
}
}
$this->sys->setNetDevices($dev);
}
}
}
示例4: _network
/**
* get network information
*
* @return void
*/
private function _network()
{
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 = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
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])) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setDrops($ar_buf_n[8]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$this->sys->setNetDevices($dev);
}
}
}
示例5: _network
/**
* Network devices
*
* @return void
*/
private function _network()
{
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface');
//, array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded'));
$allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration');
//, array('Description', 'MACAddress', 'IPAddress', 'SettingID'));
foreach ($allDevices as $device) {
$dev = new NetDevice();
$name = $device['Name'];
if (preg_match('/^isatap\\.({[A-Fa-f0-9\\-]*})/', $name, $ar_name)) {
//isatap device
foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if ($ar_name[1] == $NetworkAdapterConfiguration['SettingID']) {
$dev->setName($NetworkAdapterConfiguration['Description']);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
$dev->setInfo(preg_replace('/:/', '-', $NetworkAdapterConfiguration['MACAddress']));
if (isset($NetworkAdapterConfiguration['IPAddress'])) {
foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres) {
if ($ipaddres != "0.0.0.0" && !preg_match('/^fe80::/i', $ipaddres)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ipaddres);
}
}
}
}
break;
}
}
} else {
$cname = preg_replace('/[^A-Za-z0-9]/', '_', $name);
//convert to canonical
if (preg_match('/\\s-\\s([^-]*)$/', $name, $ar_name)) {
$name = substr($name, 0, strlen($name) - strlen($ar_name[0]));
}
$dev->setName($name);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if (preg_replace('/[^A-Za-z0-9]/', '_', $NetworkAdapterConfiguration['Description']) == $cname) {
if (!is_null($dev->getInfo())) {
$dev->setInfo('');
//multiple with the same name
} else {
$dev->setInfo(preg_replace('/:/', '-', $NetworkAdapterConfiguration['MACAddress']));
if (isset($NetworkAdapterConfiguration['IPAddress'])) {
foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres) {
if ($ipaddres != "0.0.0.0" && !preg_match('/^fe80::/i', $ipaddres)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ipaddres);
}
}
}
}
}
}
}
}
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
$txbytes = $device['BytesSentPersec'];
$rxbytes = $device['BytesReceivedPersec'];
if ($txbytes < 0 && $rxbytes < 0) {
$txbytes += 4294967296;
$rxbytes += 4294967296;
} elseif ($txbytes < 0) {
if ($device['BytesTotalPersec'] > $rxbytes) {
$txbytes = $device['BytesTotalPersec'] - $rxbytes;
} else {
$txbytes += 4294967296;
}
} elseif ($rxbytes < 0) {
if ($device['BytesTotalPersec'] > $txbytes) {
$rxbytes = $device['BytesTotalPersec'] - $txbytes;
} else {
$rxbytes += 4294967296;
}
}
$dev->setTxBytes($txbytes);
$dev->setRxBytes($rxbytes);
$dev->setErrors($device['PacketsReceivedErrors']);
$dev->setDrops($device['PacketsReceivedDiscarded']);
$this->sys->setNetDevices($dev);
}
}
示例6: _network
/**
* Network devices
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\\s+/", $line);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
preg_match('/^(\\D+)(\\d+)$/', $ar_buf[0], $intf);
$prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
$cnt = $this->_kstat($prefix . 'drop');
if ($cnt > 0) {
$dev->setDrops($cnt);
}
$cnt = $this->_kstat($prefix . 'obytes64');
if ($cnt > 0) {
$dev->setTxBytes($cnt);
}
$cnt = $this->_kstat($prefix . 'rbytes64');
if ($cnt > 0) {
$dev->setRxBytes($cnt);
}
$this->sys->setNetDevices($dev);
}
}
}
}
示例7: _network
/**
* get network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\\s+/", $line, 10);
if (!empty($ar_buf[0])) {
$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]);
}
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && CommonFunctions::executeProgram('ifconfig', $ar_buf[0] . ' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\\s+ether\\s+(\\S+)/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', $ar_buf2[1]));
} elseif (preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
} elseif ((preg_match('/^\\s+inet6\\s+([^\\s%]+)\\s+prefixlen/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\s+([^\\s%]+)%\\S+\\s+prefixlen/i', $buf2, $ar_buf2)) && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
示例8: _network
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
private function _network()
{
if (CommonFunctions::rfts('/proc/net/dev', $bufr)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\\s+/', trim($stats_list));
$dev = new NetDevice();
$dev->setName(trim($dev_name));
$dev->setRxBytes($stats[0]);
$dev->setTxBytes($stats[8]);
$dev->setErrors($stats[2] + $stats[10]);
$dev->setDrops($stats[3] + $stats[11]);
$this->sys->setNetDevices($dev);
}
}
}
}
示例9: _network
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network()
{
if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\\s+/', trim($stats_list));
$dev = new NetDevice();
$dev->setName(trim($dev_name));
$dev->setRxBytes($stats[0]);
$dev->setTxBytes($stats[8]);
$dev->setErrors($stats[2] + $stats[10]);
$dev->setDrops($stats[3] + $stats[11]);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && CommonFunctions::executeProgram('ifconfig', trim($dev_name) . ' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
// if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
if (preg_match('/\\s+encap:Ethernet\\s+HWaddr\\s(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+ether\\s+(\\S+)\\s+txqueuelen/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', $ar_buf2[1]));
} elseif (preg_match('/^\\s+inet\\saddr:(\\S+)\\s+P-t-P:(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask.+destination\\s+(\\S+)/i', $buf2, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1] . ";:" . $ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
} elseif (preg_match('/^\\s+inet\\saddr:(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2) || preg_match('/^' . trim($dev_name) . ':\\s+ip\\s+(\\S+)\\s+mask/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\saddr:\\s([^\\/]+)(.+)\\s+Scope:[GH]/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\s+(\\S+)\\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
$this->sys->setNetDevices($dev);
}
}
} elseif (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$notwas = true;
foreach ($lines as $line) {
if (preg_match("/^([^\\s:]+)/", $line, $ar_buf)) {
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (preg_match('/^' . $ar_buf[1] . '\\s+Link\\sencap:Ethernet\\s+HWaddr\\s(\\S+)/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', $ar_buf2[1]));
} elseif (preg_match('/^' . $ar_buf[1] . ':\\s+ip\\s+(\\S+)\\s+mask/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
} else {
if (!$notwas) {
if (preg_match('/\\sRX bytes:(\\d+)\\s/i', $line, $ar_buf2)) {
$dev->setRxBytes($ar_buf2[1]);
}
if (preg_match('/\\sTX bytes:(\\d+)\\s/i', $line, $ar_buf2)) {
$dev->setTxBytes($ar_buf2[1]);
}
if (preg_match('/\\sRX packets:\\d+\\serrors:(\\d+)\\sdropped:(\\d+)/i', $line, $ar_buf2)) {
$errors += $ar_buf2[1];
$drops += $ar_buf2[2];
} elseif (preg_match('/\\sTX packets:\\d+\\serrors:(\\d+)\\sdropped:(\\d+)/i', $line, $ar_buf2)) {
$errors += $ar_buf2[1];
$drops += $ar_buf2[2];
}
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (preg_match('/\\s+encap:Ethernet\\s+HWaddr\\s(\\S+)/i', $line, $ar_buf2) || preg_match('/^\\s+ether\\s+(\\S+)\\s+txqueuelen/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', $ar_buf2[1]));
} elseif (preg_match('/^\\s+inet\\saddr:(\\S+)\\s+P-t-P:(\\S+)/i', $line, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask.+destination\\s+(\\S+)/i', $line, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1] . ";:" . $ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
} elseif (preg_match('/^\\s+inet\\saddr:(\\S+)/i', $line, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $line, $ar_buf2) || preg_match('/^\\s+inet6\\saddr:\\s([^\\/]+)(.+)\\s+Scope:[GH]/i', $line, $ar_buf2) || preg_match('/^\\s+inet6\\s+(\\S+)\\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
}
}
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
}
}
示例10: _network
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\\s+/", $line);
if (!empty($ar_buf[0]) && !empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
示例11: _network
/**
* get network information
*
* @return void
*/
private function _network()
{
$dev = NULL;
if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\\s+/", $line);
if (!empty($ar_buf[0])) {
if (preg_match('/^<Link/i', $ar_buf[2])) {
if (!is_null($dev)) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
if (strlen($ar_buf[3]) < 17) {
/* no Address */
if (isset($ar_buf[11])) {
/* Idrop column exist*/
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[4] + $ar_buf[8]);
$dev->setDrops($ar_buf[11] + $ar_buf[5]);
} else {
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
$dev->setDrops($ar_buf[10]);
}
} else {
if (isset($ar_buf[12])) {
/* Idrop column exist*/
$dev->setTxBytes($ar_buf[10]);
$dev->setRxBytes($ar_buf[7]);
$dev->setErrors($ar_buf[5] + $ar_buf[9]);
$dev->setDrops($ar_buf[12] + $ar_buf[6]);
} else {
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[8]);
$dev->setDrops($ar_buf[11]);
}
$dev->setInfo(preg_replace('/:/', '-', $ar_buf[3]));
}
} else {
if (!is_null($dev)) {
if ($dev->getName() == $ar_buf[0]) {
/* other infos */
if (!preg_match('/^fe80::/i', $ar_buf[3])) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf[3]);
}
} else {
/* something wrong */
$this->sys->setNetDevices($dev);
$dev = NULL;
}
}
}
}
}
if (!is_null($dev)) {
$this->sys->setNetDevices($dev);
}
}
}
示例12: _network
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network()
{
if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\\s+/', trim($stats_list));
$dev = new NetDevice();
$dev->setName(trim($dev_name));
$dev->setRxBytes($stats[0]);
$dev->setTxBytes($stats[8]);
$dev->setErrors($stats[2] + $stats[10]);
$dev->setDrops($stats[3] + $stats[11]);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (CommonFunctions::executeProgram('ip', 'addr show ' . trim($dev_name), $bufr2, PSI_DEBUG) && trim($bufr2) != "" || CommonFunctions::executeProgram('ifconfig', trim($dev_name) . ' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
$macaddr = "";
foreach ($bufe2 as $buf2) {
// if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
if (preg_match('/\\s+encap:Ethernet\\s+HWaddr\\s(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+ether\\s+(\\S+)\\s+txqueuelen/i', $buf2, $ar_buf2) || preg_match('/^\\s+link\\/ether\\s+(\\S+)\\s+brd/i', $buf2, $ar_buf2)) {
//ip
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
} elseif (preg_match('/^\\s+inet\\saddr:(\\S+)\\s+P-t-P:(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask.+destination\\s+(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+([^\\/\\s]+).*peer\\s+([^\\/\\s]+).*\\s+scope\\s((global)|(host))/i', $buf2, $ar_buf2)) {
//ip
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1] . ";:" . $ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
} elseif (preg_match('/^\\s+inet\\saddr:(\\S+)/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2) || preg_match('/^' . trim($dev_name) . ':\\s+ip\\s+(\\S+)\\s+mask/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\saddr:\\s([^\\/\\s]+)(.+)\\s+Scope:[GH]/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6\\s+(\\S+)\\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2) || preg_match('/^\\s+inet6?\\s+([^\\/\\s]+).*\\s+scope\\s((global)|(host))/i', $buf2, $ar_buf2)) {
//ip
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . strtolower($ar_buf2[1]));
}
}
}
if ($macaddr != "") {
$dev->setInfo($macaddr . ($dev->getInfo() ? ';' . $dev->getInfo() : ''));
}
if (CommonFunctions::rfts('/sys/class/net/' . trim($dev_name) . '/speed', $buf, 1, 4096, false) && trim($buf) != "" && $buf > 0 && $buf < 65535) {
$speed = trim($buf);
if ($speed > 1000) {
$speed = $speed / 1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/' . trim($dev_name) . '/duplex', $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speed . $unit . 'b/s ' . strtolower(trim($buf)));
} else {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speed . $unit . 'b/s');
}
}
}
$this->sys->setNetDevices($dev);
}
}
} elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && trim($bufr) != "") {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
foreach ($lines as $line) {
if (preg_match("/^\\d+:\\s+([^\\s:]+)/", $line, $ar_buf)) {
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr . ($dev->getInfo() ? ';' . $dev->getInfo() : ''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $speedinfo);
}
$this->sys->setNetDevices($dev);
}
$speedinfo = "";
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
if (CommonFunctions::executeProgram('ip', '-s link show ' . $ar_buf[1], $bufr2, PSI_DEBUG) && trim($bufr2) != "" && preg_match("/\n\\s+RX:\\s[^\n]+\n\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+(\\d+)[^\n]+\n\\s+TX:\\s[^\n]+\n\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+(\\d+)/m", $bufr2, $ar_buf2)) {
$dev->setRxBytes($ar_buf2[1]);
$dev->setTxBytes($ar_buf2[4]);
$dev->setErrors($ar_buf2[2] + $ar_buf2[5]);
$dev->setDrops($ar_buf2[3] + $ar_buf2[6]);
}
$was = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (CommonFunctions::rfts('/sys/class/net/' . $ar_buf[1] . '/speed', $buf, 1, 4096, false) && trim($buf) != "") {
$speed = trim($buf);
if ($speed > 1000) {
$speed = $speed / 1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/' . $ar_buf[1] . '/duplex', $buf, 1, 4096, false) && trim($buf) != "") {
$speedinfo = $speed . $unit . 'b/s ' . strtolower(trim($buf));
} else {
//.........这里部分代码省略.........
示例13: _network
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$notwas = true;
foreach ($lines as $line) {
if (preg_match("/^(\\S+)/", $line, $ar_buf)) {
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
} else {
if (!$notwas) {
if (preg_match('/\\sReceive:\\s\\d+\\spackets,\\s(\\d+)\\serrors,\\s(\\d+)\\sbytes,\\s\\d+\\smcasts,\\s(\\d+)\\sdropped/i', $line, $ar_buf2)) {
$errors += $ar_buf2[1];
$drops += $ar_buf2[3];
$dev->setRxBytes($ar_buf2[2]);
} else {
if (preg_match('/\\sTransmit:\\s\\d+\\spackets,\\s(\\d+)\\serrors,\\s(\\d+)\\sbytes,\\s\\d+\\smcasts,\\s(\\d+)\\sdropped/i', $line, $ar_buf2)) {
$errors += $ar_buf2[1];
$drops += $ar_buf2[3];
$dev->setTxBytes($ar_buf2[2]);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (preg_match('/\\sEthernet,\\s+Address:\\s(\\S*)/i', $line, $ar_buf2)) {
$dev->setInfo(preg_replace('/:/', '-', $ar_buf2[1]));
} else {
if (preg_match('/^\\s+inet\\saddr:\\s(\\S*),/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
} else {
if (preg_match('/^\\s+inet6\\saddr:\\s(\\S*),/i', $line, $ar_buf2)) {
if (!preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
}
}
}
}
}
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
}
}
示例14: _network
/**
* Network devices
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\\s+/", $line);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
if (preg_match('/^(\\D+)(\\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
} elseif (preg_match('/^(\\D.*)(\\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1] . ':' . $intf[2] . ':mac:';
} else {
$prefix = "";
}
if ($prefix !== "") {
$cnt = $this->_kstat($prefix . 'drop');
if ($cnt > 0) {
$dev->setDrops($cnt);
}
$cnt = $this->_kstat($prefix . 'obytes64');
if ($cnt > 0) {
$dev->setTxBytes($cnt);
}
$cnt = $this->_kstat($prefix . 'rbytes64');
if ($cnt > 0) {
$dev->setRxBytes($cnt);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0], $bufr2, PSI_DEBUG) && !is_null($bufr2) && trim($bufr2) !== "") {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\\s+ether\\s+(\\S+)/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . preg_replace('/:/', '-', $ar_buf2[1]));
} elseif (preg_match('/^\\s+inet\\s+(\\S+)\\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0] . ' inet6', $bufr2, PSI_DEBUG) && !is_null($bufr2) && trim($bufr2) !== "") {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\\s+inet6\\s+([^\\s\\/]+)/i', $buf2, $ar_buf2) && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo() ? $dev->getInfo() . ';' : '') . $ar_buf2[1]);
}
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
示例15: _network
/**
* Network devices
*
* @return void
*/
private function _network()
{
foreach ($this->_getWMI('Win32_PerfRawData_Tcpip_NetworkInterface') as $device) {
$dev = new NetDevice();
$dev->setName($device['Name']);
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
$txbytes = $device['BytesSentPersec'];
if ($txbytes < 0) {
$txbytes = $device['BytesTotalPersec'] - $device['BytesReceivedPersec'];
}
$dev->setTxBytes($txbytes);
$rxbytes = $device['BytesReceivedPersec'];
if ($rxbytes < 0) {
$rxbytes = $device['BytesTotalPersec'] - $device['BytesSentPersec'];
}
$dev->setRxBytes($rxbytes);
$dev->setErrors($device['PacketsReceivedErrors']);
$dev->setDrops($device['PacketsReceivedDiscarded']);
$this->sys->setNetDevices($dev);
}
}