예제 #1
0
function get_load_heatmap($hosts_up, $host_regex, $metrics, $data, $sort)
{
    foreach ($hosts_up as $host => $val) {
        // If host_regex is defined
        if (isset($host_regex) && !preg_match("/" . $host_regex . "/", $host)) {
            continue;
        }
        $load = get_load($host, $metrics);
        $host_load[$host] = $load;
    }
    $num_hosts = count($host_load);
    if ($num_hosts == 0) {
        return;
    }
    switch ($sort) {
        case "descending":
            arsort($host_load);
            break;
        case "by name":
            uksort($host_load, "strnatcmp");
            break;
        default:
        case "ascending":
            asort($host_load);
            break;
    }
    $num_cols = ceil(sqrt($num_hosts));
    $col_index = 0;
    $row_index = 0;
    $heatmap = '[';
    foreach ($host_load as $host => $load) {
        if ($col_index == 0) {
            if ($row_index > 0) {
                $heatmap .= ',';
            }
            $heatmap .= '[';
        }
        if ($col_index > 0) {
            $heatmap .= ',';
        }
        $heatmap .= "{host:\"{$host}\",load:{$load}}";
        if ($col_index == $num_cols - 1) {
            $heatmap .= ']';
            $col_index = 0;
            $row_index++;
        } else {
            $col_index++;
        }
    }
    if ($col_index != 0) {
        for ($i = 0; $i < $num_cols * $num_cols - $num_hosts; $i++) {
            $heatmap .= ",{host:\"unused\",load:0}";
        }
        $heatmap .= ']';
    }
    $heatmap .= ']';
    $data->assign("heatmap_data", $heatmap);
}
예제 #2
0
function get_load_heatmap($hosts_up, $user, $metrics, $data)
{
    foreach ($hosts_up as $host => $val) {
        // If host_regex is defined
        if (isset($user['host_regex']) && !preg_match("/" . $user['host_regex'] . "/", $host)) {
            continue;
        }
        $load = get_load($host, $metrics);
        $host_load[$host] = $load;
    }
    $num_hosts = count($host_load);
    $matrix = ceil(sqrt($num_hosts));
    $xindex = 0;
    $yindex = 0;
    foreach ($host_load as $key => $value) {
        if ($xindex >= $matrix) {
            $string_array[] = "[" . join(",", $matrix_array[$yindex]) . "]";
            $yindex++;
            $xindex = 0;
        }
        $matrix_array[$yindex][$xindex] = $value;
        $xindex++;
    }
    $string_array[] = "[" . join(",", $matrix_array[$yindex]) . "]";
    $conf['heatmap_size'] = 200;
    $heatmap = join(",", $string_array);
    $data->assign("heatmap", $heatmap);
    $data->assign("heatmap_size", floor($conf['heatmap_size'] / $matrix));
}
예제 #3
0
{
    $errno = 0;
    $errstr = '';
    $conn = @fsockopen($server, 22, $errno, $errstr, TIMEOUT);
    if (is_resource($conn)) {
        fclose($conn);
        return true;
    } else {
        return false;
    }
}
if (count($argv) <= 1) {
    die("Please provide me with the server name or address as the first input argument");
}
// only argument is our server name (or IP)
$server = $argv[1];
if (!has_open_ssh_port($server)) {
    die("OFFLINE");
}
$load = get_load($server);
if ($load === false) {
    die("ONLINE");
}
// Extract the 1min load:
preg_match('/load1=([0-9.]+);/', $load, $matches);
if (count($matches) >= 1) {
    die(doubleval($matches[1]));
} else {
    // This shouldn't happen but we can just return online then. No harm
    die("ONLINE");
}
예제 #4
0
            <tr>
              <td><img src='icons/up-alt-icon.png' alt='Uptime' />Server Uptime :</td>
              <td><?php 
if (isset($ch2) && $ch2 == 'selected') {
    echo get_uptime();
} else {
    echo "Not selected";
}
?>
</td>
            </tr>
            <tr>
              <td><img src='icons/loaded-truck.png' alt='Load' />Average Load :</td>
              <td><?php 
if (isset($ch3) && $ch3 == 'selected') {
    echo get_load();
} else {
    echo "Not selected";
}
?>
</td>
            </tr>
            <tr>
              <td><img src="icons/intel-2-icon.png" alt="CPU" />Server CPU Info :</td>
              <td><?php 
if (isset($ch4) && $ch4 == 'selected') {
    echo get_cpuinfo();
} else {
    echo "Not selected";
}
?>
예제 #5
0
파일: get.php 프로젝트: heweida/mmonitor
/**
 * 服务器探针.测试支持CENTOS.REDHAT.
 *  - 获取服务器负载
 *  - 获取所有网卡状态
 *  - 获取CPU使用率
 *  - 获取磁盘使用率
 *  - 获取内存使用率
 * 该探针需要PHP支持EXEC函数,可以在CGI模式下运行,依赖系统内置的IFCONFI,TOP,UPTIME,DF工具获取数据.
 * 
 * @copyright (c) 2013, mMonitor.org
 * @version 1.0.1
 * @author Actrace
 * @date 2013-11-26 14:48:41
 */
if (runtime_check()) {
    echo json_encode(array('Load' => get_load(), 'Network' => get_network_status(), 'Memory' => get_mem_status(), 'Disk' => get_disk_status(), 'Cpu' => get_cpu_status()));
} else {
    echo 'need function[exec]';
}
function get_load()
{
    exec('uptime', $return, $res);
    preg_match_all('|load average: (.*), (.*), (.*)|', $return[0], $macth);
    return $macth;
}
function get_network()
{
    exec('ifconfig', $return, $res);
    $tmp = '';
    $res = array();
    $content = array();
예제 #6
0
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
require_once 'lib_statistics.php';
require_once 'config.inc';
$jobs = get_job_infos();
echo '<?xml version="1.0" standalone="yes"?>' . PHP_EOL;
echo '<statistics>' . PHP_EOL;
echo '  <performance_idx>' . $performance_idx . '</performance_idx>' . PHP_EOL;
echo '  <max_num_threads>' . get_max_num_threads() . '</max_num_threads>' . PHP_EOL;
echo '  <max_num_jobs>' . get_max_num_jobs() . '</max_num_jobs>' . PHP_EOL;
echo '  <num_jobs>' . get_num_jobs() . '</num_jobs>' . PHP_EOL;
echo '  <load>' . get_load() . '</load>' . PHP_EOL;
echo '  <encoding_pgm>' . $encoding_pgm['name'] . '</encoding_pgm>' . PHP_EOL;
echo '  <encoding_desc>' . $encoding_pgm['description'] . '</encoding_desc>' . PHP_EOL;
echo '  <jobs>' . PHP_EOL;
foreach ($jobs as $job) {
    echo '      <job>' . PHP_EOL;
    echo '          <pid>' . $job['pid'] . '</pid>' . PHP_EOL;
    echo '          <time>' . $job['time'] . '</time>' . PHP_EOL;
    echo '          <state>' . $job['state'] . '</state>' . PHP_EOL;
    echo '      </job>' . PHP_EOL;
}
echo '  </jobs>' . PHP_EOL;
echo '</statistics>' . PHP_EOL;