Exemple #1
0
function mysql_instance_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql();
    $search = '%';
    $table = "mysqlmulti";
    $page = 1;
    $FORCE_FILTER = "";
    if ($q->COUNT_ROWS($table, 'artica_backup') == 0) {
        writelogs("{$table}, no row", __FILE__, __FUNCTION__, __FILE__, __LINE__);
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        $data['rows'][] = array('id' => $ligne[time() + 1], 'cell' => array($q->mysql_error, "", "", ""));
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
        echo json_encode($data);
        return;
    }
    //if(mysql_num_rows($results)==0){$data['rows'][] = array('id' => $ligne[time()],'cell' => array($sql,"", "",""));}
    // http://www.techrepublic.com/blog/opensource/10-mysql-variables-that-you-should-monitor/56
    $sock = new sockets();
    while ($ligne = mysql_fetch_assoc($results)) {
        $id = $ligne["ID"];
        $RSS = null;
        $icon_status = "danger24.png";
        $icon_stop = imgsimple("24-stop.png", "{stop}", "Loadjs('{$MyPage}?mysql-server-service-js=yes&ID={$ligne["ID"]}&action=stop');");
        $icon_stopoff = imgsimple("24-stop-grey.png", "{stop}", "");
        $icon_run = imgsimple("24-run.png", "{run}", "Loadjs('{$MyPage}?mysql-server-service-js=yes&ID={$ligne["ID"]}&action=start');");
        $icon_stats = imgsimple("statistics-24.png", "{run}", "Loadjs('system.mysql.graphs.php?instance-id={$ligne["ID"]}');");
        if (!isset($ligne["usesocket"])) {
            $ligne["usesocket"] = 0;
        }
        $GBSTAT = trim($sock->getFrameWork("mysql.php?instance-status=yes&instance_id={$id}"));
        if ($GBSTAT == "ON") {
            $run = "{running}";
            $MEMAR = unserialize(base64_decode($sock->getFrameWork("mysql.php?instance-memory=yes&instance-id={$id}")));
            $RSS = "<br>{memory}: <strong>" . FormatBytes($MEMAR[0]) . "</strong><br>{virtual_memory}: <strong>" . FormatBytes($MEMAR[1]) . "</strong>";
            $icon_status = "ok24.png";
        } else {
            $icon_stop = $icon_run;
            $run = "{stopped}";
        }
        $qq = new mysql_multi($ligne["ID"]);
        $qr = $qq->GLOBAL_STATUS();
        $explain = "<strong>{$qr["Threads_created"]}</strong> {threads_created},\n\t\t<br><strong>{$qr["Threads_running"]}</strong> {threads_running}<br>{since}:" . UptimeString($qr["Uptime"]) . "{$RSS}";
        if ($GBSTAT != "ON") {
            $explain = "{stopped}";
        }
        $run = $tpl->_ENGINE_parse_body($run);
        $explain = $tpl->_ENGINE_parse_body($explain);
        $tt = @implode(",", $f);
        $js = "Loadjs('{$MyPage}?mysql-server-js=yes&ID={$ligne["ID"]}');";
        $delete = imgsimple("delete-24.png", "{delete} {$ligne["pattern"]}", "Loadjs('{$MyPage}?mysql-delete-js=yes&ID={$ligne["ID"]}');");
        $net = "{$ligne["listen_addr"]}:{$ligne["listen_port"]}";
        if ($ligne["usesocket"] == 0) {
            $net = ".../mysqld{$ligne["ID"]}.sock";
        }
        $member = imgsimple("members-priv-24.png", "{member}", "Loadjs('{$MyPage}?root-account-js=yes&instance-id={$ligne["ID"]}')");
        $browse = imgsimple("table-show-24.png", "{member}", "Loadjs('mysql.browse.php?instance-id={$ligne["ID"]}')");
        $data['rows'][] = array('id' => $id, 'cell' => array("<a href=\"javascript:blur();\" OnClick=\"javascript:{$js}\" style='font-size:16px;text-decoration:underline'>{$ligne["servername"]}</span></a><br><i>{$run}</i>", "<span style='font-size:16px'>{$net}</span>", "<span style='font-size:14px'>{$explain}</span>", "<div style=margin-top:15px>{$browse}</div>", "<div style=margin-top:15px>{$icon_stats}", "<div style=margin-top:15px>{$member}", "<div style=margin-top:15px><img src='img/{$icon_status}'></div>", "<div style=margin-top:15px><span id='animate-service-instance-{$ligne["ID"]}'>{$icon_stop}</span></div>", "<div style=margin-top:15px><span id='animate-service-instance-{$ligne["ID"]}'>{$delete}</div>"));
    }
    echo json_encode($data);
}