Esempio n. 1
0
function GenerateGraph($nopid = false)
{
    if (!is_file("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs", 1);
    }
    $unix = new unix();
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $time = $unix->file_time_min($pidtime);
    if (!$GLOBALS["FORCE"]) {
        if ($time < 60) {
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $q = new mysql();
    $EnableDNSPerfs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs"));
    if ($EnableDNSPerfs == 0) {
        $q->QUERY_SQL("DROP TABLE dashboard_dnsperf_day", "artica_events");
        die;
    }
    $q = new mysql();
    $q->QUERY_SQL("DROP TABLE dashboard_dnsperf_day", "artica_events");
    $q = new postgres_sql();
    $q->QUERY_SQL("DROP TABLE dashboard_dnsperf_day");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS dashboard_dnsperf_day (time timestamp,DNS VARCHAR(128), percent FLOAT(5), response FLOAT(5) )");
    $q->create_index("dashboard_dnsperf_day", "ikey", array("time", "dns", "percent", "response"));
    $hostname = $unix->hostname_g();
    $now = strtotime("-24 hour");
    $q = new postgres_sql();
    $sql = "SELECT AVG(PERCENT) as PERCENT,AVG(RESPONSE) as RESPONSE,DNS FROM dnsperfs  where PROXYNAME='{$hostname}' and time > {$now}s GROUP BY DNS,time(10m) ORDER BY ASC";
    $results = $q->QUERY_SQL($sql);
    while ($ligne = @pg_fetch_assoc($results)) {
        $zDate = $ligne["zDate"];
        $PERCENT = $ligne["PERCENT"];
        if (!is_numeric($PERCENT)) {
            continue;
        }
        $RESPONSE = $ligne["RESPONSE"];
        $DNS = $ligne["DNS"];
        $f[] = "('{$zDate}','{$DNS}','{$RESPONSE}','{$PERCENT}')";
    }
    if (count($f) > 0) {
        print_r($f);
        $q->QUERY_SQL("INSERT INTO dashboard_dnsperf_day (time,dns,response,percent) \n\t\t\t\tVALUES " . @implode(",", $f), "artica_events");
    }
    $hostname = $unix->hostname_g();
    $now = date("Y-m-d H:i:s", strtotime("-30 day"));
    $influx = new influx();
    $sql = "SELECT MEAN(PERCENT) as PERCENT,MEAN(RESPONSE) as RESPONSE,\n\tDNS FROM dnsperfs  where PROXYNAME='{$hostname}' and time > '{$now}' GROUP BY DNS,time(1d) ORDER BY ASC";
    $main = $influx->QUERY_SQL($sql);
    $f = array();
    foreach ($main as $row) {
        $time = InfluxToTime($row->time);
        if (!is_numeric($row->PERCENT)) {
            continue;
        }
        $PERCENT = $row->PERCENT;
        $RESPONSE = $row->RESPONSE;
        $DNS = $row->DNS;
        $zDate = date("Y-m-d", $time);
        $f[] = "('{$zDate}','{$DNS}','{$RESPONSE}','{$PERCENT}')";
    }
    $sql = "SELECT AVG(PERCENT) as PERCENT FROM dashboard_dnsperf_day";
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
    $sock = new sockets();
    $sock->SET_INFO("DashBoardDNSPerfsStats", $ligne["PERCENT"]);
    $q->QUERY_SQL("DROP TABLE dashboard_dnsperf_month", "artica_events");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS dashboard_dnsperf_month (`TIME` timestamp,`DNS` VARCHAR(128),`PERCENT` FLOAT(5),`RESPONSE` FLOAT(5)");
    $q->create_index("dashboard_dnsperf_month", "ikey", array("time", "dns", "percent", "response"));
    if (count($f) > 0) {
        print_r($f);
        $q->QUERY_SQL("INSERT INTO dashboard_dnsperf_month (`TIME`,`DNS`,`RESPONSE`,`PERCENT`)\n\t\t\t\tVALUES " . @implode(",", $f), "artica_events");
    }
}