예제 #1
0
 /**
  * Returns value for server role loadbar (thermometr)
  * @param $hostname
  * @param $roleId
  * @return bool|float
  * @throws \Bitrix\Main\ArgumentNullException
  * @throws \Exception
  * @throws \Bitrix\Main\IO\FileNotFoundException
  */
 public static function getLoadBarValue($hostname, $roleId)
 {
     if (!extension_loaded('rrd')) {
         throw new \Exception("Extension rrd not loaded!");
     }
     if (strlen($hostname) <= 0) {
         throw new \Bitrix\Main\ArgumentNullException("hostname");
     }
     if (strlen($roleId) <= 0) {
         throw new \Bitrix\Main\ArgumentNullException("roleId");
     }
     $role = RolesData::getRole($roleId);
     if (empty($role)) {
         throw new \Exception("Role with id = " . $roleId . " was not defined.");
     }
     if (!isset($role["LOADBAR_INFO"]) || strlen($role["LOADBAR_INFO"]) <= 0) {
         throw new \Exception("Role " . $roleId . " has no correctly defined LOADBAR_INFO param .");
     }
     $rrdFile = str_replace('##HOSTNAME##', $hostname, $role["LOADBAR_INFO"]);
     $rrdPath = "/var/lib/munin/" . $hostname . "/" . $rrdFile;
     $file = new \Bitrix\Main\IO\File($rrdPath);
     if (!$file->isExists()) {
         throw new \Bitrix\Main\IO\FileNotFoundException($rrdPath);
     }
     $data = \rrd_lastupdate($rrdPath);
     $result = static::extractRrdValue($data);
     return $result;
 }
예제 #2
0
 public function getLast($datasource)
 {
     $data = rrd_lastupdate($this->rrd_file);
     if (empty($data) || !isset($data['ds_navm']) || !isset($data['data'])) {
         return NAN;
     }
     $found = -1;
     for ($i = 0; $i < count($data['ds_navm']); $i++) {
         if ($data['ds_navm'][$i] == $datasource) {
             $found = $i;
         }
     }
     if ($found == -1) {
         // not found
         return NAN;
     }
     if (count($data['data']) < $found) {
         return NAN;
     }
     return $data['data'][$found];
 }
예제 #3
0
if (!file_exists($cfgfile)) {
    echo "Copy config.php.dist to config.php and adjust it\n";
    exit(1);
}
require $cfgfile;
if (!function_exists('rrd_lastupdate')) {
    echo "rrd PHP extension is missing\n";
    exit(2);
}
if (!is_array($filetemplate)) {
    $filetemplate = array_combine(array_keys($names), array_fill(0, count($names), $filetemplate));
}
$data = array();
foreach ($names as $id => $name) {
    $data[$id]['name'] = $name;
    foreach (array('humidity', 'temperature') as $item) {
        $lu = rrd_lastupdate(str_replace(array('{item}', '{id}'), array($item, $id), $filetemplate[$id]));
        if ($lu === false) {
            throw new Exception(rrd_error());
        }
        $data[$id][$item] = reset($lu['data']);
    }
}
foreach (glob(__DIR__ . '/templates/*.php') as $tplfile) {
    $outfile = $outdir . basename($tplfile, '.php');
    ob_start();
    include $tplfile;
    $content = ob_get_contents();
    ob_end_clean();
    file_put_contents($outfile, $content);
}