Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
5.0 KiB
PHP
Raw Permalink Normal View History

<?php
2011-05-16 12:48:50 +00:00
$processors = dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', [$device['device_id']]);
if (count($processors)) {
2018-11-29 19:23:40 -06:00
echo '
2014-02-26 22:33:45 +00:00
<div class="row">
<div class="col-md-12 ">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
2015-11-20 15:40:57 +00:00
';
2014-02-26 22:33:45 +00:00
echo '<a href="device/device=' . $device['device_id'] . '/tab=health/metric=processor/">';
echo '<i class="fa fa-microchip fa-lg icon-theme" aria-hidden="true"></i> <strong>Processors</strong></a>';
2015-11-20 15:40:57 +00:00
echo '</div>
<table class="table table-hover table-condensed table-striped">';
2015-11-23 09:37:58 +00:00
$graph_array = [];
2019-06-23 00:29:12 -05:00
$graph_array['to'] = \LibreNMS\Config::get('time.now');
2015-11-23 09:37:58 +00:00
$graph_array['type'] = 'processor_usage';
2019-06-23 00:29:12 -05:00
$graph_array['from'] = \LibreNMS\Config::get('time.day');
2015-11-23 09:37:58 +00:00
$graph_array['legend'] = 'no';
$total_percent = [];
2015-07-13 20:10:26 +02:00
2011-10-04 09:10:21 +00:00
foreach ($processors as $proc) {
2010-07-08 23:30:52 +00:00
$text_descr = rewrite_entity_descr($proc['processor_descr']);
2015-07-13 20:10:26 +02:00
$percent = $proc['processor_usage'];
2019-06-23 00:29:12 -05:00
if (\LibreNMS\Config::get('cpu_details_overview') === true) {
$background = \LibreNMS\Util\Color::percentage($percent, $proc['processor_perc_warn']);
2015-11-20 15:40:57 +00:00
$graph_array['id'] = $proc['processor_id'];
2015-11-23 09:37:58 +00:00
//Generate tooltip graphs
$graph_array['height'] = '100';
$graph_array['width'] = '210';
2015-11-20 15:40:57 +00:00
$link_array = $graph_array;
2015-11-20 15:48:44 +00:00
$link_array['page'] = 'graphs';
2015-11-20 15:40:57 +00:00
unset($link_array['height'], $link_array['width'], $link_array['legend']);
2021-03-28 17:25:30 -05:00
$link = \LibreNMS\Util\Url::generate($link_array);
2015-11-20 15:40:57 +00:00
$overlib_content = generate_overlib_content($graph_array, $device['hostname'] . ' - ' . $text_descr);
2015-11-23 09:37:58 +00:00
//Generate the minigraph
2015-11-20 15:48:44 +00:00
$graph_array['width'] = 80;
2015-11-20 15:40:57 +00:00
$graph_array['height'] = 20;
2015-11-23 09:37:58 +00:00
$graph_array['bg'] = 'ffffff00'; // the 00 at the end makes the area transparent.
2021-03-28 17:25:30 -05:00
$minigraph = \LibreNMS\Util\Url::lazyGraphTag($graph_array);
2015-11-20 15:40:57 +00:00
echo '<tr>
2021-03-28 17:25:30 -05:00
<td class="col-md-4">' . \LibreNMS\Util\Url::overlibLink($link, $text_descr, $overlib_content) . '</td>
<td class="col-md-4">' . \LibreNMS\Util\Url::overlibLink($link, $minigraph, $overlib_content) . '</td>
<td class="col-md-4">' . \LibreNMS\Util\Url::overlibLink($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']), $overlib_content) . '
2015-11-20 15:40:57 +00:00
</a></td>
2015-11-20 15:48:44 +00:00
</tr>';
2016-08-18 20:28:22 -05:00
} else {
if (! isset($total_percent[$proc['processor_type']])) {
$total_percent[$proc['processor_type']] = [
'usage' => 0,
'warn' => 0,
'descr' => $text_descr,
'count' => 0,
];
}
$total_percent[$proc['processor_type']]['usage'] += $percent;
$total_percent[$proc['processor_type']]['warn'] += $proc['processor_perc_warn'];
$total_percent[$proc['processor_type']]['count'] += 1;
2015-11-20 15:48:44 +00:00
}
}//end foreach
2019-06-23 00:29:12 -05:00
if (\LibreNMS\Config::get('cpu_details_overview') === false) {
2020-11-23 15:35:35 -06:00
$graph_array = \App\Http\Controllers\Device\Tabs\OverviewController::setGraphWidth($graph_array);
2015-11-23 09:37:58 +00:00
//Generate average cpu graph
$graph_array['device'] = $device['device_id'];
$graph_array['type'] = 'device_processor';
2021-03-28 17:25:30 -05:00
$graph = \LibreNMS\Util\Url::lazyGraphTag($graph_array);
2015-07-13 20:10:26 +02:00
2015-11-23 09:37:58 +00:00
//Generate link to graphs
2011-09-17 19:14:44 +00:00
$link_array = $graph_array;
$link_array['page'] = 'graphs';
unset($link_array['height'], $link_array['width']);
2021-03-28 17:25:30 -05:00
$link = \LibreNMS\Util\Url::generate($link_array);
2015-07-13 20:10:26 +02:00
2015-11-23 09:37:58 +00:00
//Generate tooltip
$graph_array['width'] = 210;
$graph_array['height'] = 100;
$overlib_content = generate_overlib_content($graph_array, $device['hostname'] . ' - CPU usage');
2015-07-13 20:10:26 +02:00
2014-02-26 22:33:45 +00:00
echo '<tr>
<td colspan="4">';
2021-03-28 17:25:30 -05:00
echo \LibreNMS\Util\Url::overlibLink($link, $graph, $overlib_content);
echo ' </td>
</tr>';
foreach ($total_percent as $type => $values) {
//Add a row with CPU desc, count and percent graph
$percent_usage = ceil($values['usage'] / $values['count']);
$percent_warn = $values['warn'] / $values['count'];
$background = \LibreNMS\Util\Color::percentage($percent_usage, $percent_warn);
echo '
<tr>
2021-03-28 17:25:30 -05:00
<td class="col-md-4">' . \LibreNMS\Util\Url::overlibLink($link, $values['descr'], $overlib_content) . '</td>
<td class="col-md-4">' . \LibreNMS\Util\Url::overlibLink($link, 'x' . $values['count'], $overlib_content) . '</td>
<td class="col-md-4">' . \LibreNMS\Util\Url::overlibLink($link, print_percentage_bar(200, 20, $percent_usage, null, 'ffffff', $background['left'], $percent_usage . '%', 'ffffff', $background['right']), $overlib_content) . '</td>
</tr>';
}
}
2014-02-26 22:33:45 +00:00
echo '</table>
</div>
</div>
</div>';
}//end if