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 = "multi-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 26 // By first iteration detect all similar processor names 27 $processors_descr = array(); 28 foreach ($processors_db as $k => $proc) 29 { 30 $text_descr = rewrite_entity_name($proc['processor_descr']); 31 /* not required when find_similar() used 32 if ($device['os'] == "vmware") 33 { 34 list(, $text_descr) = explode(' ', $text_descr, 2); 35 list($text_descr) = explode(' @ ', $text_descr, 2); 36 } 37 */ 38 $processors_db[$k]['text_descr'] = $text_descr; // Just append to array for not do same later 39 40 $processors_descr[] = $text_descr; 41 } 42 $processors_descr = find_similar($processors_descr, TRUE); // Processor descr -> Similar part of 43 44 // Combine multiple same processors 45 foreach ($processors_db as $proc) 46 { 47 //$text_descr = rewrite_entity_name($proc['processor_descr']); 48 if (isset($processors_descr[$proc['text_descr']])) 49 { 50 // This is processor name with similar part only 51 $text_descr = $processors_descr[$proc['text_descr']]; 52 } else { 53 $text_descr = $proc['text_descr']; 54 } 55 56 $processors[$text_descr]['device_id'] = $device['device_id']; 57 $processors[$text_descr]['processor_id'] = $proc['processor_id']; 58 $processors[$text_descr]['id'][] = $proc['processor_id']; 59 $processors[$text_descr]['usage'] += $proc['processor_usage']; 60 $processors[$text_descr]['count']++; 61 } 62 63 $box_args = array('title' => 'Processors', 64 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor')), 65 'icon' => $config['icon']['processor'], 66 ); 67 echo generate_box_open($box_args); 68 69 echo('<table class="table table-condensed table-striped">'); 70 71 // Show this for everything. 72 if (TRUE) 73 { 74 $graph_array = array(); 75 $graph_array['height'] = "100"; 76 $graph_array['width'] = "512"; 77 $graph_array['to'] = $config['time']['now']; 78 $graph_array['device'] = $device['device_id']; 79 $graph_array['type'] = (isset($device['graphs']['ucd_ss_cpu']) ? 'device_ucd_ss_cpu' : 'device_processor'); 80 $graph_array['from'] = $config['time']['day']; 81 $graph_array['legend'] = "no"; 82 $graph = generate_graph_tag($graph_array); 83 84 $link_array = $graph_array; 85 $link_array['page'] = "graphs"; 86 unset($link_array['height'], $link_array['width']); 87 $graph_link = generate_url($link_array); 88 89 $link = generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor')); 90 91 $graph_array['width'] = "210"; 92 $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Processor Usage"); 93 94 //echo(overlib_link($graph_link, $graph, $overlib_content, NULL)); 95 96 $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. 97 $graph_array['style'][] = 'margin-top: -6px'; 98 99 $minigraph = generate_graph_tag($graph_array); 100 101 echo('<tr><td colspan=4>'); 102 echo(overlib_link($graph_link, $graph, $overlib_content, NULL)); 103 echo('</td></tr>'); 104 105 } 106 107 // Perhaps we should collapse this when it's too long. Perhaps we should do that for other things too. 108 109 foreach ($processors as $text_descr => $proc) 110 { 111 # disable short hrDeviceDescr. need to make this prettier. 112 #$text_descr = rewrite_hrDevice($proc['processor_descr']); 113 $percent = round($proc['usage'] / $proc['count']); 114 $background = get_percentage_colours($percent); 115 $graph_colour = str_replace("#", "", $row_colour); 116 117 $graph_array = array(); 118 $graph_array['height'] = "100"; 119 $graph_array['width'] = "210"; 120 $graph_array['to'] = $config['time']['now']; 121 $graph_array['id'] = implode(',', $proc['id']); 122 $graph_array['type'] = $graph_type; 123 $graph_array['from'] = $config['time']['day']; 124 $graph_array['legend'] = "no"; 125 126 if (count($proc['id']) > 1) 127 { 128 $graph_array['type'] = "multi-processor_usage"; 129 } else { 130 $graph_array['type'] = "processor_usage"; 131 } 132 133 $link_array = $graph_array; 134 $link_array['page'] = "graphs"; 135 unset($link_array['height'], $link_array['width'], $link_array['legend']); 136 $link = generate_url($link_array); 137 138 $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); 139 140 $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; 141// $graph_array['style'][] = 'margin-top: -6px'; 142 143 $minigraph = generate_graph_tag($graph_array); 144 145 $count_button = ($proc['count'] > 1 ? '<span class="label pull-right" style="margin-top: 2px;"><i class="icon-remove"></i> '.$proc['count'].'</span>' : ''); 146 echo('<tr class="'.$background['class'].'"> 147 <td class="state-marker"></td> 148 <td><span class="entity text-nowrap">'.generate_entity_link('processor', $proc, $text_descr).'</span>'.$count_button.'</td> 149 <td style="width: 90px">'.overlib_link($link, $minigraph, $overlib_content).'</td> 150 <td style="width: 200px">'.overlib_link($link, print_percentage_bar(200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content).'</td> 151 </tr>'); 152 } 153 154 echo("</table>"); 155 echo generate_box_close(); 156} 157 158// EOF 159