Skip to content

Commit 00cc402

Browse files
author
Till Brehm
committed
Merge branch '6820-show-system-metric-graphs-on-dashboard' into 'develop'
Implements #6820 Show System metric graphs on dashboard Closes #6820 See merge request ispconfig/ispconfig3!1973
2 parents 5b49c92 + 7c149ef commit 00cc402

File tree

136 files changed

+37591
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+37591
-2
lines changed

interface/web/dashboard/dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174

175175
/* Which dashlets in which column */
176176
/******************************************************************************/
177-
$default_leftcol_dashlets = array('modules', 'invoices', 'quota', 'mailquota', 'databasequota');
177+
$default_leftcol_dashlets = array('modules', 'metrics', 'invoices', 'quota', 'mailquota', 'databasequota');
178178
$default_rightcol_dashlets = array('customer', 'products', 'shop', 'limits');
179179

180180
$app->uses('getconf');
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
class dashlet_metrics {
4+
5+
function show() {
6+
global $app;
7+
8+
/*
9+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
10+
return '';
11+
}
12+
*/
13+
14+
//* Loading Template
15+
$app->uses('tpl');
16+
17+
$tpl = new tpl;
18+
$tpl->newTemplate("dashlets/templates/metrics.htm");
19+
20+
$wb = array();
21+
$lng_file = 'lib/lang/' . $_SESSION['s']['language'] . '_dashlet_metrics.lng';
22+
if (is_file($lng_file)) {
23+
include $lng_file;
24+
} elseif (is_file('lib/lang/en_dashlet_metrics.lng')) {
25+
include 'lib/lang/en_dashlet_metrics.lng';
26+
}
27+
$tpl->setVar($wb);
28+
29+
// Get monitor data
30+
$rec = $app->db->queryOneRecord("SELECT `data`FROM `monitor_data` WHERE `type` = 'sys_usage' ORDER BY `created` DESC LIMIT 0,1");
31+
$data = unserialize($rec['data']);
32+
33+
if(isset($data['load']) && is_array($data['load'])) {
34+
$tpl->setVar('loadchart_data', implode(', ',$data['load']));
35+
}
36+
37+
if(isset($data['mem']) && is_array($data['mem'])) {
38+
$tpl->setVar('memchart_data', implode(', ',$data['mem']));
39+
}
40+
41+
$label = [];
42+
$n = 1;
43+
if(isset($data['net']) && is_array($data['net'])) {
44+
$rx = [];
45+
$tx = [];
46+
foreach($data['net'] as $val) {
47+
$rx[] = $val['rx'];
48+
$tx[] = $val['tx'];
49+
$label[] = $n;
50+
$n++;
51+
}
52+
$tpl->setVar('rxchart_data', implode(', ',$rx));
53+
$tpl->setVar('txchart_data', implode(', ',$tx));
54+
}
55+
//$tpl->setVar('label', implode(', ',$label));
56+
57+
if(isset($data['time']) && is_array($data['time'])) {
58+
foreach($data['time'] as $key => $val) {
59+
$data['time'][$key] = "'".$val."'";
60+
}
61+
$tpl->setVar('label', implode(', ',$data['time']));
62+
}
63+
64+
$tpl->setVar('tablelayout', $_SESSION['s']['user']['table_layout']);
65+
66+
$tpl->setVar('loadchart_label',$wb['loadchart_label']);
67+
$tpl->setVar('memchart_label',$wb['memchart_label']);
68+
$tpl->setVar('rxchart_label',$wb['rxchart_label']);
69+
$tpl->setVar('txchart_label',$wb['txchart_label']);
70+
$tpl->setvar('label_chart_title',$wb['label_chart_title']);
71+
72+
return $tpl->grab();
73+
}
74+
75+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--<div class="{tmpl_var name='tablelayout'}">-->
2+
<div>
3+
<div><h3>{tmpl_var name="label_chart_title"}</h3></div>
4+
<div style="padding-bottom:10px;"><canvas height="30" id="loadchart" style="background-color: white;"></canvas></div>
5+
<div style="padding-bottom:10px;"><canvas height="30" id="memchart" style="background-color: white;"></canvas></div>
6+
<div style="padding-bottom:10px;"><canvas height="30" id="rxchart" style="background-color: white;"></canvas></div>
7+
<div style="padding-bottom:10px;"><canvas height="30" id="txchart" style="background-color: white;"></canvas></div>
8+
</div>
9+
10+
<script>
11+
createChart('loadchart', '{tmpl_var name="loadchart_label"}', [{tmpl_var name='label'}], [{tmpl_var name='loadchart_data'}]);
12+
createChart('memchart', '{tmpl_var name="memchart_label"}', [{tmpl_var name='label'}], [{tmpl_var name='memchart_data'}]);
13+
createChart('rxchart', '{tmpl_var name="rxchart_label"}', [{tmpl_var name='label'}], [{tmpl_var name='rxchart_data'}]);
14+
createChart('txchart', '{tmpl_var name="txchart_label"}', [{tmpl_var name='label'}], [{tmpl_var name='txchart_data'}]);
15+
16+
function createChart(chartname, label, labels, data) {
17+
var ctx = document.getElementById(chartname).getContext('2d');
18+
var chart = new Chart(ctx, {
19+
type: 'line', // Type of chart
20+
data: {
21+
labels: labels, // Empty array to remove labels
22+
datasets: [{
23+
label: label, // Name of the dataset
24+
data: data, // Data points
25+
borderWidth: 1,
26+
tension: 0.4, // Tension for cubic interpolation
27+
cubicInterpolationMode: 'default', // Can be 'default' or 'monotone'
28+
borderColor: 'rgb(75, 192, 192)', // Color of the line
29+
backgroundColor: 'rgba(75, 192, 192, 0.2)', // Color for filling the area below the line
30+
fill: true // Enable fill below the line
31+
}]
32+
},
33+
options: {
34+
scales: {
35+
x: {
36+
display: false, // Hide the x-axis
37+
},
38+
y: {
39+
beginAtZero: true // Start y-axis at zero
40+
}
41+
},
42+
plugins: {
43+
legend: {
44+
labels: {
45+
generateLabels: function(chart) {
46+
const data = chart.data;
47+
return data.datasets.map(function(dataset, i) {
48+
return {
49+
text: dataset.label,
50+
fillStyle: 'white', // Set to empty string to hide the colored box
51+
hidden: !chart.isDatasetVisible(i),
52+
lineCap: dataset.borderCapStyle,
53+
lineDash: dataset.borderDash,
54+
lineDashOffset: dataset.borderDashOffset,
55+
lineJoin: dataset.borderJoinStyle,
56+
lineWidth: dataset.borderWidth,
57+
strokeStyle: 'white',
58+
pointStyle: 'white', // Set to empty string to hide the point style
59+
datasetIndex: i
60+
};
61+
});
62+
}
63+
}
64+
}
65+
}
66+
}
67+
});
68+
}
69+
</script>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = 'Métricas del sistema';
3+
$wb['loadchart_label'] = 'Carga del sistema %';
4+
$wb['memchart_label'] = 'Uso de memoria %';
5+
$wb['rxchart_label'] = 'Red entrada/kB';
6+
$wb['txchart_label'] = 'Red salida/kB';
7+
$wb['label_chart_title'] = 'Métricas del sistema';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = 'Системни метрики';
3+
$wb['loadchart_label'] = 'Натоварване на системата %';
4+
$wb['memchart_label'] = 'Използване на паметта %';
5+
$wb['rxchart_label'] = 'Мрежа входяща/kB';
6+
$wb['txchart_label'] = 'Мрежа изходяща/kB';
7+
$wb['label_chart_title'] = 'Системни метрики';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = 'Métricas do sistema';
3+
$wb['loadchart_label'] = 'Carga do sistema %';
4+
$wb['memchart_label'] = 'Uso de memória %';
5+
$wb['rxchart_label'] = 'Rede entrada/kB';
6+
$wb['txchart_label'] = 'Rede saída/kB';
7+
$wb['label_chart_title'] = 'Métricas do sistema';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = 'Mètriques del sistema';
3+
$wb['loadchart_label'] = 'Càrrega del sistema %';
4+
$wb['memchart_label'] = 'Ús de memòria %';
5+
$wb['rxchart_label'] = 'Xarxa entrada/kB';
6+
$wb['txchart_label'] = 'Xarxa sortida/kB';
7+
$wb['label_chart_title'] = 'Mètriques del sistema';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = '系统指标';
3+
$wb['loadchart_label'] = '系统负载 %';
4+
$wb['memchart_label'] = '内存使用 %';
5+
$wb['rxchart_label'] = '网络入站/kB';
6+
$wb['txchart_label'] = '网络出站/kB';
7+
$wb['label_chart_title'] = '系统指标';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = 'Systémové metriky';
3+
$wb['loadchart_label'] = 'Zatížení systému %';
4+
$wb['memchart_label'] = 'Využití paměti %';
5+
$wb['rxchart_label'] = 'Síť příchozí/kB';
6+
$wb['txchart_label'] = 'Síť odchozí/kB';
7+
$wb['label_chart_title'] = 'Systémové metriky';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb['metrics_txt'] = 'Systemmetriken';
3+
$wb['loadchart_label'] = 'Systembelastung %';
4+
$wb['memchart_label'] = 'Speicherbelastung %';
5+
$wb['rxchart_label'] = 'Netzwerk In/kB';
6+
$wb['txchart_label'] = 'Netzwerk Out/kB';
7+
$wb['label_chart_title'] = 'Systemmetriken';

0 commit comments

Comments
 (0)