1<?php
2
3/**
4 * Observium Network Management and Monitoring System
5 * Copyright (C) 2006-2015, Adam Armstrong - http://www.observium.org
6 *
7 * @package    observium
8 * @subpackage webui
9 * @author     Adam Armstrong <adama@observium.org>
10 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
11 *
12 */
13
14$graph_type = "processor_usage";
15
16$sql  = "SELECT * FROM `processors`";
17//$sql .= " LEFT JOIN `processors-state` USING(`processor_id`)";
18$sql .= " WHERE `processor_type` != 'hr-average' AND `device_id` = ?";
19
20$processors_db = dbFetchRows($sql, array($device['device_id']));
21
22if (count($processors_db))
23{
24  $processors = array();
25  // Combinate multiple same processors
26  foreach ($processors_db as $proc)
27  {
28    $text_descr = rewrite_entity_name($proc['processor_descr']);
29    $processors[$text_descr]['device_id'] = $device['device_id'];
30    $processors[$text_descr]['processor_id'] = $proc['processor_id'];
31    $processors[$text_descr]['id'][]   = $proc['processor_id'];
32    $processors[$text_descr]['usage'] += $proc['processor_usage'];
33    $processors[$text_descr]['count']++;
34  }
35
36  $box_args = array('title' => 'Processors',
37                    'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor')),
38                    'icon' => $config['icon']['processor'],
39                    );
40
41  echo generate_box_open($box_args);
42
43    $graph_array = array();
44    $graph_array['height'] = "100";
45    $graph_array['width']  = "512";
46    $graph_array['to']     = $config['time']['now'];
47    $graph_array['device'] = $device['device_id'];
48    $graph_array['type']   = (isset($device['graphs']['ucd_ss_cpu']) ? 'device_ucd_ss_cpu' : 'device_processor');
49    $graph_array['from']   = $config['time']['day'];
50    $graph_array['legend'] = "no";
51    $graph = generate_graph_tag($graph_array);
52
53    $link_array = $graph_array;
54    $link_array['page'] = "graphs";
55    unset($link_array['height'], $link_array['width']);
56    $graph_link = generate_url($link_array);
57
58    $link = generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor'));
59
60    $graph_array['width']  = "210";
61    $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Processor Usage");
62
63    //echo(overlib_link($graph_link, $graph, $overlib_content, NULL));
64
65    $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent.
66    $graph_array['style'][] = 'margin-top: -6px';
67
68    $minigraph = generate_graph_tag($graph_array);
69
70  echo('<table class="table table-condensed table-striped">');
71
72  echo('<tr><td colspan=3>');
73  echo(overlib_link($graph_link, $graph, $overlib_content, NULL));
74  echo('</td></tr>');
75
76  foreach ($processors as $text_descr => $proc)
77  {
78    # disable short hrDeviceDescr. need to make this prettier.
79    #$text_descr = rewrite_hrDevice($proc['processor_descr']);
80    $percent = round($proc['usage'] / $proc['count']);
81    $background = get_percentage_colours($percent);
82    $graph_colour = str_replace("#", "", $row_colour);
83
84    $graph_array           = array();
85    $graph_array['height'] = "100";
86    $graph_array['width']  = "210";
87    $graph_array['to']     = $config['time']['now'];
88    $graph_array['device'] = $device['device_id'];
89    $graph_array['id']     = $proc['id'];
90
91    if(is_array($proc['id']))
92    {
93      $graph_array['type']   = "multi-processor_usage";
94    } else {
95      $graph_array['type']   = $graph_type;
96    }
97    $graph_array['from']   = $config['time']['day'];
98    $graph_array['legend'] = "no";
99
100    $link_array = $graph_array;
101    $link_array['page'] = "graphs";
102    unset($link_array['height'], $link_array['width'], $link_array['legend']);
103    $link = generate_url($link_array);
104
105    $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr);
106
107    $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent.
108//    $graph_array['style'][] = 'margin-top: -6px';
109
110    $count_button = ($proc['count'] > 1 ? '<span class="label pull-right" style="margin-top: 2px;"><i class="icon-remove"></i> '.$proc['count'].'</span>' : '');
111    echo('<tr class="'.$background['class'].'">
112           <td class="state-marker"></td>
113           <td><span class="entity text-nowrap">'.generate_entity_link('processor', $proc, $text_descr).'</span>'.$count_button.'</td>
114           <td style="width: 200px">'.overlib_link($link, print_percentage_bar(200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content).'</td>
115         </tr>');
116  }
117  echo("</table>");
118  echo generate_box_close();
119}
120
121// EOF
122