From 71accc61eb6474935434e2973e360a63dec8112e Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Thu, 05 Sep 2013 09:51:06 -0400
Subject: [PATCH] - Added DB size report in monitor. Thanks to Florian for the patch!
---
interface/web/monitor/lib/lang/en.lng | 5 ++
interface/lib/classes/tools_monitor.inc.php | 38 +++++++++++++++++++
interface/web/monitor/lib/module.conf.php | 5 ++
interface/lib/classes/functions.inc.php | 10 ++++-
interface/web/monitor/show_data.php | 7 +++
5 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php
index 74f8400..661e557 100644
--- a/interface/lib/classes/functions.inc.php
+++ b/interface/lib/classes/functions.inc.php
@@ -322,7 +322,13 @@
return intval($string);
}
}
-
+
+ public function formatBytes($size, $precision = 2) {
+ $base=log($size)/log(1024);
+ $suffixes=array('','k','M','G','T');
+ return round(pow(1024,$base-floor($base)),$precision).$suffixes[floor($base)];
+ }
+
/** IDN converter wrapper.
* all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
*/
@@ -395,4 +401,4 @@
}
-?>
\ No newline at end of file
+?>
diff --git a/interface/lib/classes/tools_monitor.inc.php b/interface/lib/classes/tools_monitor.inc.php
index 42defa0..cb389c8 100644
--- a/interface/lib/classes/tools_monitor.inc.php
+++ b/interface/lib/classes/tools_monitor.inc.php
@@ -118,6 +118,44 @@
return $html;
}
+ function showDatabaseSize () {
+ global $app;
+ /* fetch the Data from the DB */
+ $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'database_size' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
+ if(isset($record['data'])) {
+ $data = unserialize($record['data']);
+ /*
+ Format the data
+ */
+ $html =
+ '<div class="systemmonitor-state state-'.$record['state'].'">
+ <div class="systemmonitor-content icons32 ico-'.$record['state'].'">
+ <table>
+ <thead>
+ <tr>
+ <td>'.$app->lng("monitor_database_name_txt").'</td>
+ <td>'.$app->lng("monitor_database_size_txt").'</td>
+ <td>'.$app->lng("monitor_database_client_txt").'</td>
+ </tr>';
+ foreach($data as $line) {
+ $html .= '<tr>';
+ if ($line['size'] > 0) $line['size'] = $app->functions->formatBytes($line['size']);
+ $t=$app->db->queryOneRecord("SELECT username FROM client WHERE sys_groupid = ".$line['client_id']);
+ $line['client_id']=$t['username'];
+ unset($t);
+ foreach ($line as $item) {
+ $html .= '<td>' . $item . '</td>';
+ }
+ $html .= '</tr></tmpl loop>';
+ }
+ $html .= '</tbody></table>';
+ $html .= '</div></div>';
+ } else {
+ $html = '<p>'.$app->lng("no_data_database_size_txt").'</p>';
+ }
+ return $html;
+ }
+
function showMemUsage () {
global $app;
diff --git a/interface/web/monitor/lib/lang/en.lng b/interface/web/monitor/lib/lang/en.lng
index ec5ca73..aa6472e 100644
--- a/interface/web/monitor/lib/lang/en.lng
+++ b/interface/web/monitor/lib/lang/en.lng
@@ -10,6 +10,7 @@
$wb['no_data_serverload_txt'] = 'No data about the server load available at the moment. Please check again later.';
$wb['no_data_memusage_txt'] = 'No data about the memory usage available at the moment. Please check again later.';
$wb['no_data_diskusage_txt'] = 'No data about the disk usage available at the moment. Please check again later.';
+$wb['no_data_database_size_txt'] = 'No data about the database usage available at the moment. Please check again later.';
$wb['no_data_cpuinfo_txt'] = 'No data about the CPU available at the moment. Please check again later.';
$wb['no_data_services_txt'] = 'No data about the services available at the moment. Please check again later.';
$wb['no_data_updates_txt'] = 'No data about updates available at the moment. Please check again later.';
@@ -58,6 +59,10 @@
$wb['monitor_diskusage_available_txt'] = 'Available';
$wb['monitor_diskusage_usage_txt'] = 'Use%';
$wb['monitor_diskusage_mounted_txt'] = 'Mounted on';
+$wb['monitor_database_name_txt'] = 'Database';
+$wb['monitor_database_size_txt'] = 'Size';
+$wb['monitor_database_client_txt'] = 'Client';
+$wb['monitor_database_domain_txt'] = 'Domain';
$wb['monitor_logs_mail_txt'] = 'Mail - Log';
$wb['monitor_logs_mailwarn_txt'] = 'Mail-Warn - Log';
$wb['monitor_logs_mailerr_txt'] = 'Mail-Error - Log';
diff --git a/interface/web/monitor/lib/module.conf.php b/interface/web/monitor/lib/module.conf.php
index c019b84..ca68ade 100644
--- a/interface/web/monitor/lib/module.conf.php
+++ b/interface/web/monitor/lib/module.conf.php
@@ -106,6 +106,11 @@
'link' => 'monitor/show_data.php?type=disk_usage',
'html_id' => 'disk_usage');
+$items[] = array( 'title' => "Show MySQL Database size",
+ 'target' => 'content',
+ 'link' => 'monitor/show_data.php?type=database_size',
+ 'html_id' => 'database_usage');
+
$items[] = array( 'title' => "Show Memory usage",
'target' => 'content',
'link' => 'monitor/show_data.php?type=mem_usage',
diff --git a/interface/web/monitor/show_data.php b/interface/web/monitor/show_data.php
index 92c66a4..42f4766 100644
--- a/interface/web/monitor/show_data.php
+++ b/interface/web/monitor/show_data.php
@@ -61,6 +61,13 @@
$title = $app->lng("Disk usage").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')';
$description = '';
break;
+ case 'database_size':
+ $template = 'templates/show_data.htm';
+ $output .= $app->tools_monitor->showDatabaseSize();
+ $time = $app->tools_monitor->getDataTime('database_size');
+ $title = $app->lng("Database size").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')';
+ $description = '';
+ break;
case 'mem_usage':
$template = 'templates/show_data.htm';
$output .= $app->tools_monitor->showMemUsage();
--
Gitblit v1.9.1