-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics.php
More file actions
75 lines (60 loc) · 2.16 KB
/
metrics.php
File metadata and controls
75 lines (60 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class dashlet_metrics {
function show() {
global $app;
/*
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
return '';
}
*/
//* Loading Template
$app->uses('tpl');
$tpl = new tpl;
$tpl->newTemplate("dashlets/templates/metrics.htm");
$wb = array();
$lng_file = 'lib/lang/' . $_SESSION['s']['language'] . '_dashlet_metrics.lng';
if (is_file($lng_file)) {
include $lng_file;
} elseif (is_file('lib/lang/en_dashlet_metrics.lng')) {
include 'lib/lang/en_dashlet_metrics.lng';
}
$tpl->setVar($wb);
// Get monitor data
$rec = $app->db->queryOneRecord("SELECT `data`FROM `monitor_data` WHERE `type` = 'sys_usage' ORDER BY `created` DESC LIMIT 0,1");
$data = unserialize($rec['data']);
if(isset($data['load']) && is_array($data['load'])) {
$tpl->setVar('loadchart_data', implode(', ',$data['load']));
}
if(isset($data['mem']) && is_array($data['mem'])) {
$tpl->setVar('memchart_data', implode(', ',$data['mem']));
}
$label = [];
$n = 1;
if(isset($data['net']) && is_array($data['net'])) {
$rx = [];
$tx = [];
foreach($data['net'] as $val) {
$rx[] = $val['rx'];
$tx[] = $val['tx'];
$label[] = $n;
$n++;
}
$tpl->setVar('rxchart_data', implode(', ',$rx));
$tpl->setVar('txchart_data', implode(', ',$tx));
}
//$tpl->setVar('label', implode(', ',$label));
if(isset($data['time']) && is_array($data['time'])) {
foreach($data['time'] as $key => $val) {
$data['time'][$key] = "'".$val."'";
}
$tpl->setVar('label', implode(', ',$data['time']));
}
$tpl->setVar('tablelayout', $_SESSION['s']['user']['table_layout']);
$tpl->setVar('loadchart_label',$wb['loadchart_label']);
$tpl->setVar('memchart_label',$wb['memchart_label']);
$tpl->setVar('rxchart_label',$wb['rxchart_label']);
$tpl->setVar('txchart_label',$wb['txchart_label']);
$tpl->setvar('label_chart_title',$wb['label_chart_title']);
return $tpl->grab();
}
}