#365 Collect and display DB size at MySQL Module

This commit is contained in:
Ulrich Block 2014-03-30 12:54:42 +02:00
parent f8a4f1ab12
commit ec5495e9ff
9 changed files with 116 additions and 18 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<sprache>
<active>Aktivieren</active>
<dbSize>Datenbankgröße</dbSize>
<interface>phpMyAdmin</interface>
<ips>Erlaubte IPs</ips>
<dbname>Datenbankname</dbname>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<sprache>
<active>Active</active>
<dbSize>Database size</dbSize>
<interface>phpMyAdmin</interface>
<ips>Allowed IPs</ips>
<dbname>Databasename</dbname>

View File

@ -50,7 +50,7 @@ if (isset($argv)) {
$args = array();
foreach ($argv as $a) {
if ($a == 'gs' or $a == 'vs') {
if ($a == 'gs' or $a == 'vs' or $a == 'my') {
$checkTypeOfServer = $a;
} else if (is_numeric($a)) {
$sleep = $a;
@ -73,14 +73,24 @@ include(EASYWIDIR . '/stuff/methods/functions_gs.php');
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
include(EASYWIDIR . '/stuff/methods/class_ts3.php');
include(EASYWIDIR . '/third_party/gameq/GameQ.php');
include(EASYWIDIR . '/stuff/methods/class_mysql.php');
include(EASYWIDIR . '/stuff/keyphrasefile.php');
set_time_limit($timelimit);
$query = $sql->prepare("UPDATE `settings` SET `lastCronStatus`=UNIX_TIMESTAMP()");
$query->execute();
if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip, ipstoarray($rSA['cronjob_ips']))) {
if (isset($checkTypeOfServer)) {
print ($checkTypeOfServer == 'gs') ? 'Checking Gameserver' . "\r\n" : 'Checking Voiceserver' . "\r\n";
if ($checkTypeOfServer == 'gs') {
print 'Checking Gameserver' . "\r\n";
} else if ($checkTypeOfServer == 'vs') {
print 'Checking Voiceserver' . "\r\n";
} else {
print 'Getting MySQL DB sizes' . "\r\n";
}
} else {
$checkTypeOfServer='all';
print 'Checking Gameserver and Voiceserver' . "\r\n";
@ -1056,19 +1066,24 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
$query2->execute(array($usedslots, $uptime, $newnotified, $newtraffic, $newtrafficdata, $queryName,((isset($server['virtualserver_clientsonline'])) ? $server['virtualserver_clientsonline'] : 0 - 1),(isset($server['virtualserver_maxclients'])) ? $server['virtualserver_maxclients'] : 0, $flagPassword, $ts3id, $resellerid));
}
if (isset($args['coolDown'])) {
$nano = time_nanosleep(0, $args['coolDown']);
if ($nano === true) {
echo 'Slept for '.$args['coolDown'].' microseconds' . "\r\n";
echo 'Slept for ' . $args['coolDown'] . ' microseconds' . "\r\n";
} elseif ($nano === false) {
echo 'Sleeping failed' . "\r\n";
} elseif (is_array($nano)) {
echo 'Interrupted by a signal' . "\r\n";
echo 'Time remaining: '.$nano['seconds'].' seconds, '.$nano['nanoseconds'].' nanoseconds' . "\r\n";
echo 'Time remaining: ' . $nano['seconds'] . ' seconds, ' . $nano['nanoseconds'] . ' nanoseconds' . "\r\n";
}
}
}
} else print "Error: ".$serverlist[0]['msg'] . "\r\n";
} else {
print "Error: " . $serverlist[0]['msg'] . "\r\n";
}
}
if (isset($connection)) {
$connection->CloseConnection();
sleep(1);
@ -1076,9 +1091,57 @@ if (!isset($ip) or $ui->escaped('SERVER_ADDR', 'server') == $ip or in_array($ip,
}
}
}
flush();
# MySQL table sizes
if ($checkTypeOfServer == 'all' or $checkTypeOfServer == 'my') {
$query = $sql->prepare("SELECT `id`,`ip`,`port`,`user`,AES_DECRYPT(`password`,?) AS `decryptedpassword` FROM `mysql_external_servers` WHERE `active`='Y'");
$query2 = $sql->prepare("SELECT `id` FROM `mysql_external_dbs` WHERE `sid`=? AND `dbname`=? LIMIT 1");
$query3 = $sql->prepare("UPDATE `mysql_external_dbs` SET `dbSize`=? WHERE `id`=? LIMIT 1");
$query->execute(array($aeskey));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$remotesql = new ExternalSQL ($row['ip'], $row['port'], $row['user'], $row['decryptedpassword']);
if ($remotesql->error == 'ok') {
$list = $remotesql->getDBSizeList();
if (is_array($list)) {
foreach ($list as $db) {
$query2->execute(array($row['id'], $db['dbName']));
$dbID = $query2->fetchColumn();
if (isid($dbID, 10)) {
echo 'Found DB ' . $db['dbName'] . ' with size ' . $db['dbSize'] . "\r\n";
$query3->execute(array(round($db['dbSize']), $dbID));
} else {
echo 'Cannot find DB ' . $db['dbName'] . ' with size ' . $db['dbSize'] . "\r\n";
}
}
} else {
echo 'Error getting DB list for DB Server ' . $row['ip'] . ':' . $row['port'] . ': ' . $list . "\r\n";
}
} else {
echo 'Error connecting to DB Server ' . $row['ip'] . ':' . $row['port'] . ': ' . $remotesql->error . "\r\n";
}
}
}
$query = $sql->prepare("UPDATE `settings` SET `lastCronStatus`=UNIX_TIMESTAMP()");
$query->execute();
} else {
header('Location: login.php');
die('Statuscheck can only be run via console or a cronjob');

View File

@ -63,7 +63,10 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
} else if ($ui->st('d', 'get') == 'ms' and !$ui->id('id', 10, 'get') and $pa['mysql_settings']) {
$table = array();
$o = $ui->st('o', 'get');
if ($ui->st('o', 'get') == 'ap') {
$orderby = '`ip` ASC';
} else if ($ui->st('o', 'get') == 'af') {
@ -82,11 +85,16 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$query = $sql->prepare("SELECT COUNT(`id`) AS `amount` FROM `mysql_external_servers` WHERE `resellerid`=?");
$query->execute(array($reseller_id));
$colcount = $query->fetchColumn();
if ($start>$colcount) {
$start = $colcount-$amount;
if ($start<0)$start = 0;
if ($start > $colcount) {
$start = $colcount - $amount;
if ($start < 0) {
$start = 0;
}
}
$table = array();
$query = $sql->prepare("SELECT * FROM `mysql_external_servers` WHERE `resellerid`=? ORDER BY $orderby LIMIT $start,$amount");
$query2 = $sql->prepare("SELECT `id`,`active`,`dbname` FROM `mysql_external_dbs` WHERE `sid`=? AND `resellerid`=?");
$query->execute(array($reseller_id));
@ -107,6 +115,7 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
}
$table[] = array('id' => $row['id'], 'img' => $imgName,'alt' => $imgAlt,'max_databases' => $row['max_databases'], 'dbcount' => $i,'ip' => $row['ip'], 'interface' => $row['interface'], 'active' => $row['active'], 'server' => $ds);
}
$next = $start+$amount;
$vor=($colcount>$next) ? $start+$amount : $start;
$back = $start - $amount;
@ -444,7 +453,11 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$template_file = 'admin_404.tpl';
}
} else if ($pa['mysql']) {
$table = array();
$o = $ui->st('o', 'get');
if ($ui->st('o', 'get') == 'as') {
$orderby = 'e.`active` ASC';
} else if ($ui->st('o', 'get') == 'ds') {
@ -479,9 +492,9 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$orderby = 'e.`dbname` ASC';
$o = 'an';
}
$table = array();
#https://github.com/easy-wi/developer/issues/42 column description added
$query = $sql->prepare("SELECT e.`id`,e.`uid`,e.`active`,e.`dbname`,e.`description`,e.`jobPending`,s.`ip`,s.`interface`,u.`cname`,u.`name`,u.`vname` FROM `mysql_external_dbs` e LEFT JOIN `mysql_external_servers` s ON e.`sid`=s.`id` LEFT JOIN `userdata` u ON e.`uid`=u.`id` WHERE e.`resellerid`=? ORDER BY $orderby LIMIT $start,$amount");
$query = $sql->prepare("SELECT e.`id`,e.`uid`,e.`active`,e.`dbname`,e.`description`,e.`jobPending`,e.`dbSize`,s.`ip`,s.`interface`,u.`cname`,u.`name`,u.`vname` FROM `mysql_external_dbs` e LEFT JOIN `mysql_external_servers` s ON e.`sid`=s.`id` LEFT JOIN `userdata` u ON e.`uid`=u.`id` WHERE e.`resellerid`=? ORDER BY $orderby LIMIT $start,$amount");
$query2 = $sql->prepare("SELECT `action`,`extraData` FROM `jobs` WHERE `affectedID`=? AND `resellerID`=? AND `type`='my' AND (`status` IS NULL OR `status`=1) ORDER BY `jobID` DESC LIMIT 1");
$query->execute(array($reseller_id));
foreach ($query->fetchall(PDO::FETCH_ASSOC) as $row) {
@ -507,7 +520,7 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$dbname = $row['dbname'];
$jobPending=($row['jobPending'] == 'Y') ? $gsprache->yes: $gsprache->no;
#https://github.com/easy-wi/developer/issues/42 column description added
$table[] = array('id' => $row['id'], 'uid' => $row['uid'], 'img' => $imgName,'description' => $row['description'], 'alt' => $imgAlt,'dbname' => $dbname,'cname' => $row['cname'], 'names' => trim($row['name'] . ' ' . $row['vname']),'ip' => $row['ip'], 'interface' => $row['interface'], 'jobPending' => $jobPending,'active' => $row['active']);
$table[] = array('id' => $row['id'], 'uid' => $row['uid'], 'img' => $imgName, 'description' => $row['description'], 'alt' => $imgAlt, 'dbname' => $dbname ,'dbSize' => $row['dbSize'], 'cname' => $row['cname'], 'names' => trim($row['name'] . ' ' . $row['vname']),'ip' => $row['ip'], 'interface' => $row['interface'], 'jobPending' => $jobPending,'active' => $row['active']);
}
$next = $start+$amount;
$countp = $sql->prepare("SELECT COUNT(`id`) AS `amount` FROM `mysql_external_dbs` WHERE `resellerid`=?");

View File

@ -57,6 +57,24 @@ class ExternalSQL {
}
}
public function getDBSizeList () {
if ($this->error != 'ok') {
return $this->error;
}
try {
$query = $this->remotesql->prepare("SELECT `table_schema` AS `dbName`,ROUND(SUM(`data_length` + `index_length`)/1048576, 1) AS `dbSize` FROM `information_schema`.`tables` GROUP BY `table_schema`");
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $error) {
return $error->getMessage();
}
}
public function AddUser ($username, $password, $max_queries_per_hour, $max_connections_per_hour, $max_updates_per_hour, $max_userconnections_per_hour) {
if ($this->error != 'ok') {

View File

@ -536,6 +536,7 @@ $query = "CREATE TABLE IF NOT EXISTS `mysql_external_dbs` (
`max_updates_per_hour` bigint(19) unsigned DEFAULT 0,
`max_connections_per_hour` bigint(19) unsigned DEFAULT 0,
`max_userconnections_per_hour` bigint(19) unsigned DEFAULT 0,
`dbSize` int(10) unsigned DEFAULT 0,
`externalID` varchar(255) DEFAULT NULL,
`jobPending` enum('Y','N') DEFAULT 'N',
`resellerid` int(10) unsigned DEFAULT 0,

View File

@ -536,6 +536,7 @@ $defined['mysql_external_dbs'] = array(
'max_updates_per_hour' => array("Type"=>"bigint(19) unsigned","Null"=>"YES","Key"=>"","Default"=>"0","Extra"=>""),
'max_connections_per_hour' => array("Type"=>"bigint(19) unsigned","Null"=>"YES","Key"=>"","Default"=>"0","Extra"=>""),
'max_userconnections_per_hour' => array("Type"=>"bigint(19) unsigned","Null"=>"YES","Key"=>"","Default"=>"0","Extra"=>""),
'dbSize' => array("Type"=>"int(10) unsigned","Null"=>"YES","Key"=>"","Default"=>"0","Extra"=>""),
'externalID' => array("Type"=>"varchar(255)","Null"=>"YES","Key"=>"","Default"=>"0","Extra"=>""),
'jobPending' => array("Type"=>"enum('Y','N')","Null"=>"YES","Key"=>"","Default"=>"N","Extra"=>""),
'resellerid' => array("Type"=>"int(10) unsigned","Null"=>"YES","Key"=>"MUL","Default"=>"0","Extra"=>"")

View File

@ -117,7 +117,7 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
#https://github.com/easy-wi/developer/issues/42 column description added
$query = $sql->prepare("UPDATE `mysql_external_dbs` SET `description`=?,`password`=AES_ENCRYPT(?,?),`ips`=? WHERE `id`=? AND `uid`=? AND `resellerid`=? LIMIT 1");
$query->execute(array($ui->names('description',255, 'post'), $password, $aeskey, $ips, $id, $user_id, $reseller_id));
$query->execute(array($ui->startparameter('description', 'post'), $password, $aeskey, $ips, $id, $user_id, $reseller_id));
$remotesql->ModDB($dbname, $password, $ips, $max_queries_per_hour, $max_connections_per_hour, $max_updates_per_hour, $max_userconnections_per_hour);
@ -147,11 +147,11 @@ if ($ui->w('action', 4, 'post') and !token(true)) {
$table = array();
$query = $sql->prepare("SELECT e.`id`,e.`dbname`,e.`description`,s.`ip`,s.`interface` FROM `mysql_external_dbs` e INNER JOIN `mysql_external_servers` s ON e.`sid`=s.`id` WHERE e.`active`='Y' AND s.`active`='Y' AND e.`uid`=? AND e.`resellerid`=?");
$query = $sql->prepare("SELECT e.`id`,e.`dbname`,e.`description`,e.`dbSize`,s.`ip`,s.`port`,s.`interface` FROM `mysql_external_dbs` e INNER JOIN `mysql_external_servers` s ON e.`sid`=s.`id` WHERE e.`active`='Y' AND s.`active`='Y' AND e.`uid`=? AND e.`resellerid`=?");
$query->execute(array($user_id, $reseller_id));
foreach ($query->fetchall(PDO::FETCH_ASSOC) as $row) {
if (!isset($_SESSION['sID']) or in_array($row['id'], $substituteAccess['db'])) {
$table[] = array('id' => $row['id'], 'dbname' => $row['dbname'], 'ip' => $row['ip'], 'description' => $row['description'], 'interface' => $row['interface']);
$table[] = array('id' => $row['id'], 'dbname' => $row['dbname'], 'dbSize' => $row['dbSize'], 'ip' => $row['ip'], 'port' => $row['port'], 'description' => $row['description'], 'interface' => $row['interface']);
}
}

View File

@ -33,10 +33,10 @@
<th data-hide="phone,tablet"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='dd') { echo 'ad'; } else { echo 'dd'; } ?>"><?php echo $sprache->description;?></a></th>
<th data-hide="phone,tablet"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='di') { echo 'ai'; } else { echo 'di'; } ?>">ID</a></th>
<th data-hide="phone"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='ds') { echo 'as'; } else { echo 'ds'; } ?>"><?php echo $gsprache->status;?></a></th>
<th data-hide="phone"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='du') { echo 'au'; } else { echo 'du'; } ?>"><?php echo $gsprache->user; ?></a></th>
<th data-hide="phone,tablet"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='df') { echo 'af'; } else { echo 'df'; } ?>"><?php echo $gsprache->user; ?></a></th>
<th data-hide="phone"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='du') { echo 'au'; } else { echo 'du'; } ?>"><?php echo $gsprache->user;?></a></th>
<th data-hide="phone,tablet"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='dp') { echo 'ap'; } else { echo 'dp'; } ?>">IP</a></th>
<th data-hide="phone,tablet"><a href="admin.php?w=my&amp;d=md&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $start;?>&amp;o=<?php if ($o=='aj') { echo 'dj'; } else { echo 'aj'; } ?>"><?php echo $gsprache->jobPending;?></a></th>
<th data-hide="phone,tablet"><?php echo $sprache->dbSize; ?></th>
<th><?php echo $gsprache->del;?></th>
<th><?php echo $gsprache->mod;?></th>
</tr>
@ -49,9 +49,9 @@
<td><?php echo $table_row['id'];?></td>
<td><i class="<?php if($table_row['active']=='Y') echo 'icon-ok'; else echo 'icon-ban-circle';?>"></i></td>
<td><a href="switch.php?id=<?php echo $table_row['uid'];?>"><?php echo $table_row['cname'];?></a></td>
<td><?php echo $table_row['names'];?></td>
<td><a href="<?php echo $table_row['interface'];?>" target="_blank"><?php echo $table_row['ip'];?></a></td>
<td><?php echo $table_row['jobPending'];?></td>
<td><?php echo $table_row['dbSize'];?>MB</td>
<td><a href="admin.php?w=my&amp;d=dd&amp;id=<?php echo $table_row['id'];?>" ><span class="btn btn-mini btn-danger"><i class="fa fa-trash-o"></i></span></a></td>
<td><a href="admin.php?w=my&amp;d=md&amp;id=<?php echo $table_row['id'];?>" ><span class="btn btn-mini btn-primary"><i class="icon-white icon-edit"></i></span></a></td>
</tr>