function updateRrds() { $timeStampNow = time(); foreach ($this->devices as $device) { switch ($device["type"]) { case "valve": $rrdPath = $this->rrdBasePath . "valves/peer_" . $device["peerId"] . ".rrd"; if (file_exists($rrdPath)) { $options = array(sprintf("%d:%d:%d:%d", $timeStampNow, $device["tempSensor"], $device["targetTemp"], $device["valveState"])); if (!rrd_update($rrdPath, $options)) { echo "RRD ERROR:" . rrd_error() . "\n"; } } break; case "envsensor": $rrdPath = $this->rrdBasePath . "sensors/peer_" . $device["peerId"] . ".rrd"; if (file_exists($rrdPath)) { $options = array(sprintf("%d:%d:%d", $timeStampNow, $device["tempSensor"], $device["humidSensor"])); if (!rrd_update($rrdPath, $options)) { echo "RRD ERROR:" . rrd_error() . "\n"; } } break; } } }
function getMNVotes($testnet = false) { if ($testnet) { $testnetval = "1"; $testnetstr = "testnet"; } else { $testnetval = "0"; $testnetstr = ""; } xecho("Retrieving masternodes votes (testnet={$testnetval}): "); $result = dmn_api_get("/masternodes/votes?testnet={$testnetval}", array(), $response); if ($response['http_code'] == 200) { echo "Fetched..."; $votes = json_decode($result, true); if ($votes === false) { echo " Failed to JSON decode!\n"; die(200); } elseif (!is_array($votes) || !array_key_exists('data', $votes) || !is_array($votes['data'])) { echo " Incorrect data!\n"; die(202); } $votes = $votes['data']; echo " OK (" . count($votes) . " entries)\n"; } else { echo "Failed [" . $response['http_code'] . "]\n"; if ($response['http_code'] != 500) { $result = json_decode($result, true); if ($result !== false) { foreach ($result['messages'] as $num => $msg) { xecho("Error #{$num}: {$msg}\n"); } } } die(201); } $votesyea = 0; $votesnay = 0; $votesabstain = 0; $votestotal = 0; foreach ($votes as $vote) { if ($vote["Vote"] == "Yea") { $votesyea += $vote["VoteCount"]; } elseif ($vote["Vote"] == "Nay") { $votesnay += $vote["VoteCount"]; } else { $votesabstain += $vote["VoteCount"]; } } $votestotal = $votesyea + $votesnay + $votesabstain; xecho("Submitting to RRDtool DB (N:{$votesyea}:{$votesnay}:{$votesabstain}:{$votestotal}): "); // rrdtool create mnvotes2.rrd --start 1431101864 DS:Yea:GAUGE:600:U:U DS:Nay:GAUGE:600:U:U DS:Abstain:GAUGE:600:U:U DS:Total:GAUGE:600:U:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 if (rrd_update("mnvotes2{$testnetstr}.rrd", ["N:{$votesyea}:{$votesnay}:{$votesabstain}:{$votestotal}"])) { echo "OK\n"; } else { echo "Failed\n"; } }
function update($location, $values) { $input_string = 'N'; foreach ($values as $value) { $input_string .= ":" . $value; } $result = rrd_update($location, $input_string); if ($result) { print rrd_error(); return false; } return true; }
public function execute() { if (!file_exists($this->db_path)) { throw new Rrdtool_Exception("Rrdtool\\Update() ERROR: rdd file '" . $this->db_path . "' not exists"); } $insert = "N"; foreach ($this->datas as $data) { $insert .= ':' . $data; } $return = rrd_update($this->db_path, $insert); if (!$return) { throw new Rrdtool_Exception("rrd_update() ERROR: " . rrd_error()); } else { return $return; } }
function rrd_xload() { $filetime = "/etc/artica-postfix/pids/rrd.load.time"; $unix = new unix(); if (!$GLOBALS["FORCE"]) { $timeN = $unix->file_time_sec($filetime); if ($timeN < 120) { if ($GLOBALS["VERBOSE"]) { echo "{$timeN}/120, abroting\n"; } return; } } @unlink($filetime); @file_put_contents($filetime, time()); if (!is_dir("/usr/share/artica-postfix/ressources/databases/rrd")) { @mkdir("/usr/share/artica-postfix/ressources/databases/rrd", 0755, true); } if (!is_file("/usr/share/artica-postfix/ressources/databases/rrd/load.rrd")) { echo "Creating load.rrd\n"; $opts = array("--step", "120", "--start", 0, "DS:load:GAUGE:120:U:U", "RRA:AVERAGE:0.5:1:1440", "RRA:AVERAGE:0.5:6:1800", "RRA:AVERAGE:0.5:24:1800", "RRA:AVERAGE:0.5:288:1800", "RRA:MIN:0.5:1:1440", "RRA:MIN:0.5:6:1800", "RRA:MIN:0.5:24:1800", "RRA:MIN:0.5:288:1800", "RRA:MAX:0.5:1:1440", "RRA:MAX:0.5:6:1800", "RRA:MAX:0.5:24:1800", "RRA:MAX:0.5:288:1800"); $ret = @rrd_create("/usr/share/artica-postfix/ressources/databases/rrd/load.rrd", $opts, count($opts)); if ($ret == 0) { $err = rrd_error(); echo "Create error: {$err}\n"; } } $array_load = sys_getloadavg(); $internal_load = $array_load[0]; $t = time(); echo "Load:{$internal_load}\n"; //$internal_load=str_replace(".", ",", $internal_load); $ret = rrd_update("/usr/share/artica-postfix/ressources/databases/rrd/load.rrd", "{$t}:{$internal_load}"); if ($ret == 0) { $err = rrd_error(); echo "update error: {$err}\n"; } create_graph("/usr/share/artica-postfix/ressources/logs/web/load.png", "-1h", "Load Hourly"); }
public function build($action, $settings) { global $config, $_theme, $argv; if (!$settings) { error('This theme is not currently installed.'); } $this->boards = explode(' ', $settings['boards']); $this->spans = array('hour', 'day', 'week', 'month', 'year'); // exclude boards from the "combined" graph $this->combined_exclude = array(); if ($action == 'cron') { if (!file_exists($settings['path'])) { mkdir($settings['path']); } if (!file_exists($settings['images'])) { mkdir($settings['images']); } foreach ($this->boards as &$board) { $file = $settings['path'] . '/' . $board . '.rrd'; if (!file_exists($file)) { // Create graph if (!rrd_create($file, array('-s 60', 'DS:posts:COUNTER:86400:0:10000', 'RRA:AVERAGE:0:1:60', 'RRA:AVERAGE:0:1:1440', 'RRA:AVERAGE:0:30:10080', 'RRA:AVERAGE:0:120:43829', 'RRA:AVERAGE:0:1440:525948', 'RRA:AVERAGE:0:2880:1051897', 'RRA:MAX:0:1:60', 'RRA:MAX:0:1:1440', 'RRA:MAX:0:30:10080', 'RRA:MAX:0:120:43829', 'RRA:MAX:0:1440:525948', 'RRA:MAX:0:2880:1051897'))) { error('RRDtool failed: ' . htmlentities(rrd_error())); } } // debug just the graphing (not updating) with the --debug switch if (!isset($argv[1]) || $argv[1] != '--debug') { // Update graph $query = query(sprintf("SELECT MAX(`id`) AS `count` FROM `posts_%s`", $board)); $count = $query->fetch(); $count = $count['count']; if (!rrd_update($file, array('-t', 'posts', 'N:' . $count))) { error('RRDtool failed: ' . htmlentities(rrd_error())); } } foreach ($this->spans as &$span) { // Graph graph if (!rrd_graph($settings['images'] . '/' . $board . '-' . $span . '.png', array('-s -1' . $span, '-t Posts on ' . sprintf($config['board_abbreviation'], $board) . ' this ' . $span, '--lazy', '-l 0', '-h', $settings['height'], '-w', $settings['width'], '-a', 'PNG', '-R', 'mono', '-W', 'Powered by Tinyboard', '-E', '-X', '0', '-Y', '-v posts/' . $settings['rate'], 'DEF:posts-second=' . $file . ':posts:AVERAGE', 'CDEF:posts-minute=posts-second,60,*', 'CDEF:posts-hour=posts-minute,60,*', 'CDEF:posts-day=posts-hour,24,*', 'CDEF:posts-week=posts-day,7,*', 'CDEF:posts-month=posts-day,28,*', 'CDEF:posts-year=posts-day,365,*', 'DEF:posts=' . $file . ':posts:AVERAGE', 'LINE2:posts-' . $settings['rate'] . '#663300:Posts', 'GPRINT:posts-' . $settings['rate'] . ':MAX:Max\\: %5.2lf', 'GPRINT:posts-' . $settings['rate'] . ':AVERAGE:Average\\: %5.2lf', 'GPRINT:posts-' . $settings['rate'] . ':LAST:Current\\: %5.2lf posts/' . $settings['rate'], 'HRULE:0#000000'))) { error('RRDtool failed: ' . htmlentities(rrd_error())); } } } // combined graph foreach ($this->spans as &$span) { $options = array('-s -1' . $span, '-t Posts this ' . $span, '--lazy', '-l 0', '-h', $settings['height'], '-w', $settings['width'], '-a', 'PNG', '-R', 'mono', '-W', 'Powered by Tinyboard', '-E', '-X', '0', '-Y', '-v posts/' . $settings['rate']); $red = 0; $green = 0; $blue = 0; $c = 0; $cc = 0; $c = 1; $cc = 0; $red = 2; foreach ($this->boards as &$board) { if (in_array($board, $this->combined_exclude)) { continue; } $color = str_pad(dechex($red * 85), 2, '0', STR_PAD_LEFT) . str_pad(dechex($green * 85), 2, '0', STR_PAD_LEFT) . str_pad(dechex($blue * 85), 2, '0', STR_PAD_LEFT); $options[] = 'DEF:posts' . $board . '-second=' . $settings['path'] . '/' . $board . '.rrd' . ':posts:AVERAGE'; $options[] = 'CDEF:posts' . $board . '-minute=posts' . $board . '-second,60,*'; $options[] = 'CDEF:posts' . $board . '-hour=posts' . $board . '-minute,60,*'; $options[] = 'CDEF:posts' . $board . '-day=posts' . $board . '-hour,24,*'; $options[] = 'CDEF:posts' . $board . '-week=posts' . $board . '-day,7,*'; $options[] = 'CDEF:posts' . $board . '-month=posts' . $board . '-day,28,*'; $options[] = 'CDEF:posts' . $board . '-year=posts' . $board . '-day,365,*'; $options[] = 'LINE2:posts' . $board . '-' . $settings['rate'] . '#' . $color . ':' . sprintf($config['board_abbreviation'], $board); // Randomize colors using this horrible undocumented algorithm I threw together while debugging if ($c == 0) { $red++; } elseif ($c == 1) { $green++; } elseif ($c == 2) { $blue++; } elseif ($c == 3) { $green--; } elseif ($c == 4) { $red--; } $cc++; if ($cc > 2) { $c++; $cc = 0; } if ($c > 4) { $c = 0; } if ($red > 3) { $red = 0; } if ($green > 3) { $green = 0; } if ($blue > 3) { $blue = 0; } } $options[] = 'HRULE:0#000000'; if (!rrd_graph($settings['images'] . '/combined-' . $span . '.png', $options)) { error('RRDtool failed: ' . htmlentities(rrd_error())); } } } }
public function fillHardwareRRDData() { if (!$this->checkHardwareRRDFile()) { $this->createHardwareRRDFile(); } $data = array(); $data[] = time(); $hardwareDS = RRD::getDSFromRRDFile($this->rrdHardwareFile); $tmphardware = array(); foreach ($this->nodeHardware as $key => $value) { $hardKey = $this->hardwareMapper->addNameToMapping($key); if (!in_array($hardKey, $hardwareDS)) { $hardwareDS[] = $key; RRD::addDS2RRDFile($this->rrdHardwareFile, $hardKey, "GAUGE", 600, 0, "U"); } $tmphardware[$hardKey] = $value; } foreach ($hardwareDS as $hard) { //echo $firm."\n"; $data[] = $tmphardware[$hard]; } $string = implode(":", $data); $ret = rrd_update($this->rrdHardwareFile, array($string)); echo rrd_error(); }
/** * Update data in RRD * * @param array $data * @param integer $timestamp UNIX TimeStamp * @return bool */ function Update($data, $timestamp = "N") { $arg = "{$timestamp}"; foreach ($data as $val) $arg .= ":{$val}"; if(rrd_update($this->DBPath, $arg)) return true; else Core::RaiseError(_("Cannot update RRD: ".rrd_error())); }
<?php $path = "/home/rrd/rrd/"; $password = '******'; $url = 'http://speedport.ip/'; if (!file_exists($path . 'dsl.rrd')) { $options = array("--step", "60", "DS:uactual:GAUGE:120:0:100000", "DS:dactual:GAUGE:120:0:200000", "DS:uattainable:GAUGE:120:0:100000", "DS:dattainable:GAUGE:120:0:200000", "DS:uSNR:GAUGE:120:0:1000", "DS:dSNR:GAUGE:120:0:1000", "DS:uSignal:GAUGE:120:0:1000", "DS:dSignal:GAUGE:120:0:200000", "DS:uLine:GAUGE:120:0:2000", "DS:dLine:GAUGE:120:0:2000", "DS:uCRC:DERIVE:120:0:10000000", "DS:dCRC:DERIVE:120:0:10000000", "DS:uHEC:DERIVE:120:0:10000000", "DS:dHEC:DERIVE:120:0:10000000", "DS:uFEC:DERIVE:120:0:10000000", "DS:dFEC:DERIVE:120:0:10000000", "RRA:AVERAGE:0.5:1:2880", "RRA:MAX:0.5:1:2880", "RRA:AVERAGE:0.5:10:144", "RRA:MAX:0.5:10:144"); rrd_create($path . 'dsl.rrd', $options); } if (!file_exists($path . 'lteinfo.rrd')) { $options = array("--step", "60", "DS:rsrp:GAUGE:120:-200:0", "DS:rsrq:GAUGE:120:-200:0", "RRA:AVERAGE:0.5:1:2880", "RRA:MAX:0.5:1:2880", "RRA:AVERAGE:0.5:10:144", "RRA:MAX:0.5:10:144"); rrd_create($path . 'lteinfo.rrd', $options); } require_once '../SpeedportHybrid.class.php'; $sp = new SpeedportHybrid($url); $sp->login($password); $data = $sp->getData('dsl'); $options = array(time() . ':' . $data['Line']['uactual'] . ':' . $data['Line']['dactual'] . ':' . $data['Line']['uattainable'] . ':' . $data['Line']['dattainable'] . ':' . $data['Line']['uSNR'] . ':' . $data['Line']['dSNR'] . ':' . $data['Line']['uSignal'] . ':' . $data['Line']['dSignal'] . ':' . $data['Line']['uLine'] . ':' . $data['Line']['dLine'] . ':' . $data['Line']['uCRC'] . ':' . $data['Line']['dCRC'] . ':' . $data['Line']['uHEC'] . ':' . $data['Line']['dHEC'] . ':' . $data['Line']['uFEC'] . ':' . $data['Line']['dFEC']); rrd_update($path . 'dsl.rrd', $options); $data = $sp->getData('lteinfo'); $options = array(time() . ':' . $data['rsrp'] . ':' . $data['rsrq']); rrd_update($path . 'lteinfo.rrd', $options); $sp->logout();
<?php #date_default_timezone_set("America/Los_Angeles"); $fname = "/home/pi/temperature.rrd"; $opts = array("-s", "300", "DS:temp:GAUGE:600:U:U", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797"); if (file_exists($fname)) { $datenow = date('U'); $temp = exec('sudo python /home/pi/readtemp.py'); $updatevalue = array($datenow . ":" . $temp); $ret = rrd_update($fname, $updatevalue); if ($ret == 0) { $err = rrd_error(); echo "ERROR occurred: {$err}\n"; } else { echo "Temperature " . $temp . " logged at " . $datenow; } } else { $ret = rrd_create($fname, $opts); if ($ret == 0) { $err = rrd_error(); echo "Create error: {$err}\n"; } else { echo "Tempearture database created"; } } ?>
public function fillRRDData() { if (!$this->checkRRDFileExists()) { $this->createRRDFile(); } $data = array(); $data[] = time(); //TODO: Memory Usage $memoryUsage = $this->getStatistics()->getMemoryUsage() * 100; $data[] = $memoryUsage; //$data[] = time(); //TODO: clients $clients = $this->getStatistics()->getClients(); $data[] = $clients; //TODO: rootfs_usage $rootfs = $this->getStatistics()->getRootfsUsage() * 100; $data[] = $rootfs; //TODO: loadavg $loadavg = $this->getStatistics()->getLoadavg(); $data[] = $loadavg; //TODO: traffic $trafficMgmtRxbytes = $this->getStatistics()->getTraffic()->getMgmtRx()->getBytes(); $data[] = $trafficMgmtRxbytes; $trafficMgmtRxpackets = $this->getStatistics()->getTraffic()->getMgmtRx()->getPackets(); $data[] = $trafficMgmtRxpackets; $trafficMgmtTxbytes = $this->getStatistics()->getTraffic()->getMgmtTx()->getBytes(); $data[] = $trafficMgmtTxbytes; $trafficMgmtTxpackets = $this->getStatistics()->getTraffic()->getMgmtTx()->getPackets(); $data[] = $trafficMgmtTxpackets; $trafficRxbytes = $this->getStatistics()->getTraffic()->getRx()->getBytes(); $data[] = $trafficRxbytes; $trafficRxpackets = $this->getStatistics()->getTraffic()->getRx()->getPackets(); $data[] = $trafficRxpackets; $trafficTxbytes = $this->getStatistics()->getTraffic()->getTx()->getBytes(); $data[] = $trafficTxbytes; $trafficTxpackets = $this->getStatistics()->getTraffic()->getTx()->getPackets(); $data[] = $trafficTxpackets; $trafficForwardedBytes = $this->getStatistics()->getTraffic()->getForward()->getBytes(); $data[] = $trafficForwardedBytes; $trafficForwardedPackets = $this->getStatistics()->getTraffic()->getForward()->getPackets(); $data[] = $trafficForwardedPackets; $string = implode(":", $data); $ret = rrd_update($this->getRRDFileName(), array($string)); }
public function update($arr, $time = false) { // Mimics the internal methods of the extension $ds_names = ''; $ds_vals = ''; if (!$time) { $time = 'N'; } $ds_count = count($arr); foreach ($arr as $k => $v) { if (strlen($ds_names) > 0) { $ds_names .= ':'; } else { $ds_names .= '--template='; } $ds_names .= $k; if (strlen($ds_vals) == 0) { $ds_vals .= $time; } $ds_vals .= ':'; $ds_vals .= $v; } $ret = rrd_update($this->path, array($ds_names, $ds_vals)); if (!$ret) { $this->error = rrd_error(); } return $ret; }
} $values = array(); $values = array_chunk($recData1, 2); $recData = array(); foreach ($values as $bytes) { array_push($recData, PhpType::bytes2signedInt($bytes)); } } // Get signed integer from INT interpretation $t = time(); $wert1 = array_merge((array) $t, (array) $recData); // zeit und daten zusammenfügen $wert2 = implode(":", $wert1); // ausgabe für rrd vorbereiten $wert3 = array($wert2); $ret = rrd_update($filename, $wert3); // rrd updaten if (!$ret) { $rrd_error = rrd_error(); System_Daemon::info('{appName} Graph error %s', $rrd_error); //echo "<b>Graph error, </b>".rrd_error()."\n"; } } else { // wenn das rrd file noch nicht vorhanden ist neues anlagen $options = array("--step", "5", "--start", "-30 days"); $zaehler = $start + $anzahl; //echo("Start: ".$start."Ende: ".$zaehler.""); for ($i = $start; $i < $zaehler; $i++) { // anzahl der trends Name ist aus Datenbanck IWx array_push($options, "DS:" . $art . $i . ":GAUGE:5:U:U"); }
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | +-------------------------------------------------------------------------+ | Swmon: Solution For Switch Edge-Core ES3528M, ES3552M and ES3510 | +-------------------------------------------------------------------------+ | This code is designed, written, and maintained by the X-sys Group. See | | about.php and/or the AUTHORS file for specific developer information. | +-------------------------------------------------------------------------+ | http://www.x-sys.com.ua/ | +-------------------------------------------------------------------------+ */ include dirname(__FILE__) . "/include/config.php"; /* Удалить все картинки с загрузками на портах */ system("rm {$homedir}/tmp/*"); /* Выводит список портов */ $sql = "SELECT d.id, d.ip, p.port\n\tFROM device d \n\tLEFT JOIN ports p \n\tON d.id=p.device_id \n\tWHERE d.state_id=1\n\tAND p.state_id=1\n\tAND p.trank=0\n\tAND p.name not like '%FAIL%' \n\tAND p.name not like '%rezerv%'"; $alldev = mysql_query($sql); while ($rowoct = mysql_fetch_row($alldev)) { if (@fopen("{$homedir}/rrd/" . $rowoct[0] . "_" . $rowoct[2] . ".rrd", "r")) { /* Получить данные с порта */ $getinoct = snmpget("{$rowoct['1']}", "public", "ifInOctets.{$rowoct['2']}"); $strinoct = substr($getinoct, 11, strlen($getinoct) - 11); $getoutoct = snmpget("{$rowoct['1']}", "public", "ifOutOctets.{$rowoct['2']}"); $stroutoct = substr($getoutoct, 11, strlen($getoutoct) - 11); /* Относительно пользователя, для относительно оборудования поменять местами $str*oct */ rrd_update("{$homedir}/rrd/" . $rowoct[0] . "_" . $rowoct[2] . ".rrd", "N:{$stroutoct}:{$strinoct}"); } else { $rrdadd = array("--step", "300", "--start", 0, "DS:in:COUNTER:600:U:U", "DS:out:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797"); rrd_create("{$homedir}/rrd/" . $rowoct[0] . "_" . $rowoct[2] . ".rrd", $rrdadd, count($rrdadd)); } }