mirror of
https://github.com/librenms/librenms.git
synced 2024-09-22 02:48:37 +00:00
webui: Added diskusage to top devices widget (#7903)
* webui: added diskusage to top devices widget * Update top-devices.inc.php
This commit is contained in:
parent
00f2abfad4
commit
79c42743a6
@ -36,6 +36,7 @@ $selected_ping = '';
|
||||
$selected_cpu = '';
|
||||
$selected_ram = '';
|
||||
$selected_poller = '';
|
||||
$selected_storage = '';
|
||||
|
||||
switch ($top_query) {
|
||||
case "traffic":
|
||||
@ -73,6 +74,13 @@ switch ($top_query) {
|
||||
$selected_poller = 'selected';
|
||||
$graph_type = 'device_poller_perf';
|
||||
$graph_params = array('tab' => 'graphs', 'group' => 'poller');
|
||||
break;
|
||||
case "storage":
|
||||
$table_header = 'Disk usage';
|
||||
$selected_storage = 'selected';
|
||||
$graph_type = 'device_storage';
|
||||
$graph_params = array('tab' => 'health', 'metric' => 'storage');
|
||||
break;
|
||||
}
|
||||
|
||||
$widget_settings['device_count'] = $widget_settings['device_count'] > 0 ? $widget_settings['device_count'] : 5;
|
||||
@ -101,6 +109,7 @@ if (defined('SHOW_SETTINGS') || empty($widget_settings)) {
|
||||
<option value="poller" ' . $selected_poller . '>Poller duration</option>
|
||||
<option value="cpu" ' . $selected_cpu . '>Processor load</option>
|
||||
<option value="ram" ' . $selected_ram . '>Memory usage</option>
|
||||
<option value="storage" ' . $selected_storage . '>Disk usage</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@ -241,6 +250,24 @@ if (defined('SHOW_SETTINGS') || empty($widget_settings)) {
|
||||
ORDER BY `mempool_perc` ' . $sort_order . '
|
||||
LIMIT :count';
|
||||
}
|
||||
} elseif ($top_query === 'storage') {
|
||||
if (is_admin() || is_read()) {
|
||||
$query = 'SELECT `hostname`, `last_polled`, `d`.`device_id`, `storage_perc`, `d`.`sysName`, `storage_descr`, `storage_perc_warn`, `storage_id`
|
||||
FROM `storage` as `disk`, `devices` as `d`
|
||||
WHERE `d`.`device_id` = `disk`.`device_id`
|
||||
AND `d`.`type` = \'server\'
|
||||
AND unix_timestamp() - UNIX_TIMESTAMP(`last_polled`) < :interval
|
||||
ORDER BY `storage_perc` ' . $sort_order . '
|
||||
LIMIT :count';
|
||||
} else {
|
||||
$query = 'SELECT `hostname`, `last_polled`, `d`.`device_id`, `storage_perc`, `d`.`sysName`, `storage_descr`, `storage_perc_warn`, `storage_id`
|
||||
FROM `storage` as `disk`, `devices` as `d`, `devices_perms` AS `P`
|
||||
WHERE `P`.`user_id` = :user AND `P`.`device_id` = `disk`.`device_id`
|
||||
AND `d`.`type` = \'server\'
|
||||
AND unix_timestamp() - UNIX_TIMESTAMP(`last_polled`) < :interval
|
||||
ORDER BY `storage_perc` ' . $sort_order . '
|
||||
LIMIT :count';
|
||||
}
|
||||
} elseif ($top_query === 'poller') {
|
||||
if (is_admin() || is_read()) {
|
||||
$query = 'SELECT `last_polled_timetaken`, `hostname`, `last_polled`, `device_id`, `sysName`
|
||||
@ -265,8 +292,11 @@ if (defined('SHOW_SETTINGS') || empty($widget_settings)) {
|
||||
<table class="table table-hover table-condensed table-striped bootgrid-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-left">Device</th>
|
||||
<th class="text-left">' . $table_header . '</a></th>
|
||||
<th class="text-left">Device</th>';
|
||||
if ($top_query == 'storage') {
|
||||
$common_output[] = '<th class="text-left">Storage Device</th>';
|
||||
}
|
||||
$common_output[] = ' <th class="text-left">' . $table_header . '</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
@ -275,8 +305,32 @@ if (defined('SHOW_SETTINGS') || empty($widget_settings)) {
|
||||
$common_output[] = '
|
||||
<tr>
|
||||
<td class="text-left">' . generate_device_link($result, shorthost($result['hostname'])) . '</td>
|
||||
<td class="text-left">' . generate_device_link($result, generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], $graph_type, 'no', 150, 21), $graph_params, 0, 0, 0) . '</td>
|
||||
</tr>';
|
||||
<td class="text-left">';
|
||||
if ($top_query == 'storage') {
|
||||
$graph_array = array();
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '210';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $drive['storage_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['legend'] = 'no';
|
||||
|
||||
$overlib_content = generate_overlib_content($graph_array, $result['hostname'].' - '.$result['storage_descr']);
|
||||
|
||||
$link_array = $graph_array;
|
||||
$link_array['page'] = 'graphs';
|
||||
unset($link_array['height'], $link_array['width'], $link_array['legend']);
|
||||
$link = generate_url($link_array);
|
||||
|
||||
$percent = $result['storage_perc'];
|
||||
$background = get_percentage_colours($percent, $result['storage_perc_warn']);
|
||||
$common_output[] = shorten_text($result['storage_descr'], 50).'</td><td class="text-left">';
|
||||
$common_output[] = overlib_link($link, print_percentage_bar(150, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content);
|
||||
} else {
|
||||
$common_output[] = generate_device_link($result, generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], $graph_type, 'no', 150, 21), $graph_params, 0, 0, 0);
|
||||
}
|
||||
$common_output[] = '</td></tr>';
|
||||
}
|
||||
$common_output[] = '
|
||||
</tbody>
|
||||
|
@ -595,13 +595,13 @@ function print_percentage_bar($width, $height, $percent, $left_text, $left_colou
|
||||
}
|
||||
|
||||
$output = '
|
||||
<div class="container" style="width:' . $width . 'px; height:' . $height . 'px;">
|
||||
<div class="container" style="width:' . $width . 'px; height:' . $height . 'px; position: relative;">
|
||||
<div class="progress" style="min-width: 2em; background-color:#' . $right_background . '; height:' . $height . 'px;">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="' . $size_percent . '" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width:' . $size_percent . '%; background-color: #' . $left_background . ';">
|
||||
</div>
|
||||
</div>
|
||||
<b class="pull-left" style="padding-left: 4px; height: ' . $height . 'px;margin-top:-' . ($height * 2) . 'px; color:#' . $left_colour . ';">' . $left_text . '</b>
|
||||
<b class="pull-right" style="padding-right: 4px; height: ' . $height . 'px;margin-top:-' . ($height * 2) . 'px; color:#' . $right_colour . ';">' . $right_text . '</b>
|
||||
<b style="padding-left: 10%; position: absolute; top: 0px; left: 0px; color:#' . $left_colour . ';">' . $left_text . '</b>
|
||||
<b style="padding-right: 10%; position: absolute; top: 0px; right: 0px; color:#' . $right_colour . ';">' . $right_text . '</b>
|
||||
</div>
|
||||
';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user