Skip to content

Commit 71accc6

Browse files
committed
- Added DB size report in monitor. Thanks to Florian for the patch!
1 parent 073273c commit 71accc6

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,13 @@ public function intval($string, $force_numeric = false) {
322322
return intval($string);
323323
}
324324
}
325-
325+
326+
public function formatBytes($size, $precision = 2) {
327+
$base=log($size)/log(1024);
328+
$suffixes=array('','k','M','G','T');
329+
return round(pow(1024,$base-floor($base)),$precision).$suffixes[floor($base)];
330+
}
331+
326332
/** IDN converter wrapper.
327333
* all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
328334
*/
@@ -395,4 +401,4 @@ public function idn_decode($domain) {
395401

396402
}
397403

398-
?>
404+
?>

interface/lib/classes/tools_monitor.inc.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,44 @@ function showDiskUsage () {
118118
return $html;
119119
}
120120

121+
function showDatabaseSize () {
122+
global $app;
123+
/* fetch the Data from the DB */
124+
$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");
125+
if(isset($record['data'])) {
126+
$data = unserialize($record['data']);
127+
/*
128+
Format the data
129+
*/
130+
$html =
131+
'<div class="systemmonitor-state state-'.$record['state'].'">
132+
<div class="systemmonitor-content icons32 ico-'.$record['state'].'">
133+
<table>
134+
<thead>
135+
<tr>
136+
<td>'.$app->lng("monitor_database_name_txt").'</td>
137+
<td>'.$app->lng("monitor_database_size_txt").'</td>
138+
<td>'.$app->lng("monitor_database_client_txt").'</td>
139+
</tr>';
140+
foreach($data as $line) {
141+
$html .= '<tr>';
142+
if ($line['size'] > 0) $line['size'] = $app->functions->formatBytes($line['size']);
143+
$t=$app->db->queryOneRecord("SELECT username FROM client WHERE sys_groupid = ".$line['client_id']);
144+
$line['client_id']=$t['username'];
145+
unset($t);
146+
foreach ($line as $item) {
147+
$html .= '<td>' . $item . '</td>';
148+
}
149+
$html .= '</tr></tmpl loop>';
150+
}
151+
$html .= '</tbody></table>';
152+
$html .= '</div></div>';
153+
} else {
154+
$html = '<p>'.$app->lng("no_data_database_size_txt").'</p>';
155+
}
156+
return $html;
157+
}
158+
121159
function showMemUsage () {
122160
global $app;
123161

interface/web/monitor/lib/lang/en.lng

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $wb['Memory usage'] = 'Memory Usage';
1010
$wb['no_data_serverload_txt'] = 'No data about the server load available at the moment. Please check again later.';
1111
$wb['no_data_memusage_txt'] = 'No data about the memory usage available at the moment. Please check again later.';
1212
$wb['no_data_diskusage_txt'] = 'No data about the disk usage available at the moment. Please check again later.';
13+
$wb['no_data_database_size_txt'] = 'No data about the database usage available at the moment. Please check again later.';
1314
$wb['no_data_cpuinfo_txt'] = 'No data about the CPU available at the moment. Please check again later.';
1415
$wb['no_data_services_txt'] = 'No data about the services available at the moment. Please check again later.';
1516
$wb['no_data_updates_txt'] = 'No data about updates available at the moment. Please check again later.';
@@ -58,6 +59,10 @@ $wb['monitor_diskusage_used_txt'] = 'Used';
5859
$wb['monitor_diskusage_available_txt'] = 'Available';
5960
$wb['monitor_diskusage_usage_txt'] = 'Use%';
6061
$wb['monitor_diskusage_mounted_txt'] = 'Mounted on';
62+
$wb['monitor_database_name_txt'] = 'Database';
63+
$wb['monitor_database_size_txt'] = 'Size';
64+
$wb['monitor_database_client_txt'] = 'Client';
65+
$wb['monitor_database_domain_txt'] = 'Domain';
6166
$wb['monitor_logs_mail_txt'] = 'Mail - Log';
6267
$wb['monitor_logs_mailwarn_txt'] = 'Mail-Warn - Log';
6368
$wb['monitor_logs_mailerr_txt'] = 'Mail-Error - Log';

interface/web/monitor/lib/module.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
'link' => 'monitor/show_data.php?type=disk_usage',
107107
'html_id' => 'disk_usage');
108108

109+
$items[] = array( 'title' => "Show MySQL Database size",
110+
'target' => 'content',
111+
'link' => 'monitor/show_data.php?type=database_size',
112+
'html_id' => 'database_usage');
113+
109114
$items[] = array( 'title' => "Show Memory usage",
110115
'target' => 'content',
111116
'link' => 'monitor/show_data.php?type=mem_usage',

interface/web/monitor/show_data.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
$title = $app->lng("Disk usage").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')';
6262
$description = '';
6363
break;
64+
case 'database_size':
65+
$template = 'templates/show_data.htm';
66+
$output .= $app->tools_monitor->showDatabaseSize();
67+
$time = $app->tools_monitor->getDataTime('database_size');
68+
$title = $app->lng("Database size").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')';
69+
$description = '';
70+
break;
6471
case 'mem_usage':
6572
$template = 'templates/show_data.htm';
6673
$output .= $app->tools_monitor->showMemUsage();

0 commit comments

Comments
 (0)