/** * 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; }