-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetail.php
111 lines (91 loc) · 3.8 KB
/
detail.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
require_once 'conf/common.inc.php';
require_once 'inc/functions.inc.php';
require_once 'inc/html.inc.php';
require_once 'inc/collectd.inc.php';
# use width/height from config if nothing is given
if (empty($_GET['x']))
$_GET['x'] = $CONFIG['detail-width'];
if (empty($_GET['y']))
$_GET['y'] = $CONFIG['detail-heigth'];
$host = validate_get(GET('h'), 'host');
$plugin = validate_get(GET('p'), 'plugin');
$pinstance = validate_get(GET('pi'), 'pinstance');
$category = validate_get(GET('c'), 'category');
$type = validate_get(GET('t'), 'type');
$tinstance = validate_get(GET('ti'), 'tinstance');
$seconds = GET('s');
$selected_plugins = !$plugin ? $CONFIG['overview'] : array($plugin);
html_start();
printf('<fieldset id="%s">', $host);
printf('<legend>%s</legend>', $host);
$plugins = collectd_plugins($host);
if(!$plugins) {
echo "Unknown host\n";
return false;
}
plugins_list($host, $selected_plugins);
echo '<div class="graphs">';
plugin_header($host, $plugin);
$args = $_GET;
print '<ul class="time-range">' . "\n";
foreach($CONFIG['term'] as $key => $s) {
$args['s'] = $s;
$selected = selected_timerange($seconds, $s);
printf('<li><a %s href="%s%s">%s</a></li>'."\n",
$selected, $CONFIG['weburl'], build_url('detail.php', $args), $key);
}
print "</ul>\n";
if ($CONFIG['graph_type'] == 'canvas') {
chdir($CONFIG['webdir']);
include $CONFIG['webdir'].'/plugin/'.$plugin.'.php';
} else {
if ($CONFIG['graph_type'] == 'svg') {
// In order to get SVG images that are approximately the same size as PNG images, using the same
// $CONFIG['detail-width'] setting, we need to adjust the SVG width up by 1.114x.
// With a detail-width of 850, SVG files display as exactly 850px while PNG displays as 947px wide.
$svg_upscale_magic_number = 1.114;
$img_width = sprintf(' width="%s"', (is_numeric($CONFIG['detail-width']) ? ($CONFIG['detail-width']) : 400) * $svg_upscale_magic_number);
} else {
$img_width = '';
}
$graph_url = $CONFIG['weburl'] . build_url('graph.php', $_GET);
# Get seconds duration off of GET URL, or use default
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
$duration_seconds = $_GET['s'];
} else {
$duration_seconds = $CONFIG['time_range']['default'];
}
# sanity check on graph duration (minimum of 60 seconds)
if ($duration_seconds < 60) $duration_seconds = 60;
# Get the aggressiveness value, verify that it falls within 0-1000
if (isset($CONFIG['detail_graphs_refresh_aggressiveness']) && is_numeric($CONFIG['detail_graphs_refresh_aggressiveness'] )) {
if ($CONFIG['detail_graphs_refresh_aggressiveness'] < 0) $CONFIG['detail_graphs_refresh_aggressiveness'] = 0;
if ($CONFIG['detail_graphs_refresh_aggressiveness'] > 1000) $CONFIG['detail_graphs_refresh_aggressiveness'] = 1000;
} else {
$CONFIG['detail_graphs_refresh_aggressiveness'] = 400;
}
# If the aggressiveness value > 0, then we can use it to calculate the refresh rate (in milliseconds)
if ($CONFIG['detail_graphs_refresh_aggressiveness'] > 0) {
# Calculate refresh rate (in msec)
$graph_refresh_time_msec = ($duration_seconds * 1000) / $CONFIG['detail_graphs_refresh_aggressiveness'];
# Cache time should be <= refresh time
if (isset($CONFIG['cache']) && is_numeric($CONFIG['cache'])) {
if ($CONFIG['cache'] > ($graph_refresh_time_msec/1000)) $CONFIG['cache'] = intval($graph_refresh_time_msec/1000);
}
# create the refresh script for this graph
printf('<script>$(document).ready(function() { setInterval(function rrdGraphRefresh(){ console.log(\'refresh\'); $(\'#detailRRDGraph\').attr(\'src\', \'%s\' + \'&_ts=\' + new Date().getTime()); }, %d); });</script>'."\n",
$graph_url,
$graph_refresh_time_msec
);
}
# Generate the graph image tag
printf('<img class="rrd_graph" id="detailRRDGraph" src="%s"%s>'."\n",
$graph_url,
$img_width
);
}
echo '</div>';
echo "</fieldset>\n";
html_end();
?>