@ 2014-07-03T22:28:20Z #!/usr/bin/env php
<?php
$ts = date_timestamp_get(date_create());
$pdu6 = new PduStats(6, $ts);
//$pdu6->toArray();
//$pdu6->putval();
$pdu7 = new PduStats(7, $ts);
//$pdu7->toArray();
//$pdu7->putval();
class PduStats
{
/**
* Statistics
* @var array
*/
private $stats = array();
private $host;
private $cookie;
private $baseurl;
private static $st;
/**
* Constructor.
*
* @param integer $id PDU identifier
*/
public function __construct($id, $TS, $user = 'apc', $pass = 'apc')
{
$this->ts = $TS;
$this->cookie = tempnam(sys_get_temp_dir(), 'ucspdu-');
$this->host = "10.10.254.${id}";
$loginUrl = "http://".$this->host."/Forms/login1";
$datosLogin = 'login_username='.$user.'&login_password='.$pass;
// Hacemos logging para obtener la cookie
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1); // a 0
curl_setopt($ch, CURLOPT_POSTFIELDS, $datosLogin);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
if (!preg_match('@(http://[^/]+/[^/]+/[^/]+/)@Ui', $url, $match)) {
throw new RuntimeException('No redirection');
}
$this->baseurl=$match[0];
curl_close($ch);
$this->toArray();
$this->putval();
$this->close();
}
public function close()
{
// Logout
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseurl . 'logout.htm');
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
// Delete cookie
unlink($this->cookie);
}
public function toArray()
{
$this->getDeviceInfo();
$this->getPhaseInfo();
$this->getBankInfo();
}
protected function getDeviceInfo()
{
// Parse info
preg_match_all(
'@<span name="Value_with_Units\?\d+,\d">([0-9.]+) \w+<@Ui',
$this->getUrl('loadman.htm'),
$matches,
PREG_SET_ORDER
);
// Store clean stats
$this->stats['device']['load'] = 0 + $matches[0][1];
$this->stats['device']['peak'] = 0 + $matches[1][1];
$this->stats['device']['total'] = 0 + $matches[2][1];
}
protected function getPhaseInfo()
{
// Parse info
preg_match_all(
'@<tr>\s*<td noWrap> ([^<]+)</td>\s*<td noWrap>(\d+\.?\d*)\D*</td>\s*<td noWrap>(\d+\.?\d*)\D*</td>\s*<td noWr
$this->getUrl('phload.htm'),
$matches,
PREG_SET_ORDER
);
// Store clean stats
foreach ($matches as $match) {
$this->stats['phases'][substr($match[1],1,1)]['V'] = 0 + $match[2];
$this->stats['phases'][substr($match[1],1,1)]['kW'] = 0 + $match[3];
$this->stats['phases'][substr($match[1],1,1)]['A'] = 0 + $match[4];
}
}
protected function getBankInfo()
{
//Parse info
preg_match_all(
'@<tr>\s*<td noWrap> ([^<]+)</td>\s*<td noWrap>(\d+\.?\d*)\D*</td>@Uis',
$this->getUrl('bankload.htm'),
$matches,
PREG_SET_ORDER
);
// list($dummy, $bankid, $amp) = $match;
// Store clean stats
foreach ($matches as $match) {
$this->stats['banks'][$match[1]]['A'] = 0 + $match[2];
$phase = floor(($match[1] - 1) / 2) + 1;
$this->stats['banks'][$match[1]]['V'] = $this->stats['phases'][$phase]['V'];
$this->stats['banks'][$match[1]]['kW'] = $this->stats['banks'][$match[1]]['A'] *
$this->stats['banks'][$match[1]]['V'] / 1000;
}
}
private function getUrl($uri)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseurl . $uri);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
public function putval()
{
var_dump(this->host);
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$file = "/var/lib/rrdcached/db/UcsToCsv.csv";
$fp = fopen($file , "r+");
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
/*
public function putval()
{
foreach ($this->stats as $key1 => $pdu){
switch ($key1){
case "device":
echo "PUTVAL \"".$this->host."/DEVICE/pdu_global\" ".$this->ts.":${pdu['total']}:${pdu['load']}\n";
break;
case "phases":
foreach ($pdu as $key2 => $type){
echo "PUTVAL \"".$this->host."/PHASE-$key2/pdu_phase\" ".$this->ts.":${type['V']}:${type['kW']}
}
break;
case "banks":
foreach ($pdu as $key2 => $type){
$idPhase = floor(($key2+1)/2);
$idBank = ($key2+1)%2+1;
echo "PUTVAL \"".$this->host."/PHASE-${idPhase}/pdu_bank-${idBank}\" ".$this->ts.":${type['V']}:${type[
}
break;
}
}
}*/
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.30 0.027 0.063 19.31 5.4.29 0.053 0.050 18.85 5.4.28 0.037 0.040 19.00 5.4.27 0.040 0.053 19.02 5.4.26 0.033 0.040 19.21 5.4.25 0.040 0.060 19.11 5.4.24 0.040 0.060 19.05 5.4.23 0.027 0.040 19.21 5.4.22 0.033 0.070 19.05 5.4.21 0.020 0.043 19.21 5.4.20 0.043 0.063 18.88 5.4.19 0.027 0.043 19.01 5.4.18 0.037 0.057 18.88 5.4.17 0.023 0.040 18.90 5.4.16 0.023 0.037 19.04 5.4.15 0.023 0.080 19.06 5.4.14 0.033 0.063 16.37 5.4.13 0.027 0.037 16.38 5.4.12 0.027 0.070 16.32 5.4.11 0.020 0.040 16.36 5.4.10 0.030 0.057 16.57 5.4.9 0.030 0.070 16.47 5.4.8 0.027 0.070 16.55 5.4.7 0.027 0.047 16.59 5.4.6 0.023 0.073 16.19 5.4.5 0.027 0.050 16.18 5.4.4 0.033 0.030 16.34 5.4.3 0.030 0.050 16.55 5.4.2 0.027 0.040 16.34 5.4.1 0.023 0.050 16.56 5.4.0 0.027 0.040 15.96 5.3.28 0.033 0.070 14.55 5.3.27 0.033 0.037 14.63 5.3.26 0.030 0.063 14.72 5.3.25 0.037 0.067 14.55 5.3.24 0.030 0.067 14.80 5.3.23 0.040 0.063 14.54 5.3.22 0.040 0.033 14.58 5.3.21 0.023 0.047 14.61 5.3.20 0.033 0.057 14.83 5.3.19 0.037 0.033 14.72 5.3.18 0.037 0.060 14.65 5.3.17 0.037 0.067 14.57 5.3.16 0.037 0.037 14.68 5.3.15 0.033 0.033 14.60 5.3.14 0.033 0.033 14.56 5.3.13 0.033 0.063 14.66 5.3.12 0.027 0.047 14.59 5.3.11 0.040 0.060 14.59 5.3.10 0.037 0.037 14.10 5.3.9 0.030 0.030 14.03 5.3.8 0.023 0.037 14.17 5.3.7 0.030 0.037 13.98 5.3.6 0.037 0.057 13.99 5.3.5 0.033 0.027 14.04 5.3.4 0.027 0.070 13.89 5.3.3 0.027 0.043 14.02 5.3.2 0.020 0.053 13.66 5.3.1 0.037 0.050 13.60 5.3.0 0.023 0.037 13.90
preferences:dark mode live preview
140.68 ms | 1394 KiB | 7 Q