Zabbix:尝试监控我的 php 网站上 IT 服务的运行时间

Zabbix:尝试监控我的 php 网站上 IT 服务的运行时间

目前只有服务的 SLA,但我不想显示其运行时间(正常运行时间)。

这是页面:

$sql = "SELECT servicedownid FROM services_links WHERE serviceupid='$hid'";
$resu = mysqli_query($mysqli, $sql);
if (mysqli_num_rows($resu) > 0) {

    while ($row = mysqli_fetch_assoc($resu)) {
        $mysqli2 = mysqli_connect("localhost", "root", "pasword", "zabbix");
        $serviceid = $row['servicedownid'];
        $sq = "SELECT name FROM services WHERE serviceid = '$serviceid'";
        $result = mysqli_query($mysqli2, $sq);
        if (mysqli_num_rows($result) > 0) {
            while ($row2 = mysqli_fetch_assoc($result)) {
                $id = $row['servicedownid'];
                echo "<tr><td class='tablename'> " . $row2['name'] . "</td>";
                try {
                    $api = new ZabbixApi($apiurl, $user, $passwd);
                    $api->setDefaultParams(array(
                        'output' => 'extend',
                        'serviceids' => $id,
                        'intervals' => array(
                            'from' => time() - 3600,
                            'to' => time()
                        )
                    ));
                    $sla = $api->serviceGetSla();
                    $array = json_encode($sla, true);
                    $jsonArr = json_decode($array, true);
                    $StringData = $jsonArr[$id]['sla'][0]['sla'];
                    if ($StringData > 99) {
                        echo "<td bgcolor=\"#5CE65C\"> " . round($StringData, 2) . "%" . "</td>";
                    } else if ($StringData > 95 && $StringData < 99) {
                        echo "<td bgcolor=\"yellow\"> " . round($StringData, 2) . "%" . "</td>";
                    } else {
                        echo "<td bgcolor=\"red\"> " . round($StringData, 2) . "%" . "</td>";
                    }
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
                try {
                    $api = new ZabbixApi($apiurl, $user, $passwd);
                    $api->setDefaultParams(array(
                        'output' => 'extend',
                        'serviceids' => $id,
                        'intervals' => array(
                            'from' => time() - 86400,
                            'to' => time()
                        )
                    ));
                    $sla = $api->serviceGetSla();
                    $array = json_encode($sla, true);
                    $jsonArr = json_decode($array, true);
                    $StringData = $jsonArr[$id]['sla'][0]['sla'];
                    if ($StringData > 99) {
                        echo "<td bgcolor=\"#5CE65C\"> " . round($StringData, 2) . "%" . "</td>";
                    } else if ($StringData > 95 && $StringData < 99) {
                        echo "<td bgcolor=\"yellow\"> " . round($StringData, 2) . "%" . "</td>";
                    } else {
                        echo "<td bgcolor=\"red\"> " . round($StringData, 2) . "%" . "</td>";
                    }
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
                try {
                    $api = new ZabbixApi($apiurl, $user, $passwd);
                    $api->setDefaultParams(array(
                        'output' => 'extend',
                        'serviceids' => $id,
                        'intervals' => array(
                            'from' => time() - 604800,
                            'to' => time()
                        )
                    ));
                    $sla = $api->serviceGetSla();
                    $array = json_encode($sla, true);
                    $jsonArr = json_decode($array, true);
                    $StringData = $jsonArr[$id]['sla'][0]['sla'];
                    if ($StringData > 99) {
                        echo "<td bgcolor=\"#5CE65C\"> " . round($StringData, 2) . "%" . "</td>";
                    } else if ($StringData > 95 && $StringData < 99) {
                        echo "<td bgcolor=\"yellow\"> " . round($StringData, 2) . "%" . "</td>";
                    } else {
                        echo "<td bgcolor=\"red\"> " . round($StringData, 2) . "%" . "</td>";
                    }
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
                try {
                    $api = new ZabbixApi($apiurl, $user, $passwd);
                    $api->setDefaultParams(array(
                        'output' => 'extend',
                        'serviceids' => $id,
                        'intervals' => array(
                            'from' => time() - 2678400,
                            'to' => time()
                        )
                    ));
                    $sla = $api->serviceGetSla();
                    $array = json_encode($sla, true);
                    $jsonArr = json_decode($array, true);
                    $StringData = $jsonArr[$id]['sla'][0]['sla'];
                    if ($StringData > 99) {
                        echo "<td bgcolor=\"#5CE65C\"> " . round($StringData, 2) . "%" . "</td>";
                    } else if ($StringData > 95 && $StringData < 99) {
                        echo "<td bgcolor=\"yellow\"> " . round($StringData, 2) . "%" . "</td>";
                    } else {
                        echo "<td bgcolor=\"red\"> " . round($StringData, 2) . "%" . "</td>";
                    }
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
                try {
                    $api = new ZabbixApi($apiurl, $user, $passwd);
                    $api->setDefaultParams(array(
                        'output' => 'extend',
                        'serviceids' => $id,
                        'intervals' => array(
                            'from' => time() - 31536000,
                            'to' => time()
                        )
                    ));
                    $sla = $api->serviceGetSla();
                    $array = json_encode($sla, true);
                    $jsonArr = json_decode($array, true);
                    $StringData = $jsonArr[$id]['sla'][0]['sla'];
                    if ($StringData > 99) {
                        echo "<td bgcolor=\"#5CE65C\"> " . round($StringData, 2) . "%" . "</td>";
                    } else if ($StringData > 95 && $StringData < 99) {
                        echo "<td bgcolor=\"yellow\"> " . round($StringData, 2) . "%" . "</td>";
                    } else {
                        echo "<td bgcolor=\"red\"> " . round($StringData, 2) . "%" . "</td>";
                    }
                } catch (Exception $e) {
                    echo $e->getMessage();
                }

相关内容