2014-05-05 Sergio Martin <sergio.martin@artica.es>
* extensions/realtime_graphs extensions/realtime_graphs/ajax.php extensions/realtime_graphs/realtime_graphs.css extensions/realtime_graphs/realtime_graphs.js extensions/realtime_graphs.php: Added real time graphs extension for ticket #736 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9857 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
3f400c6b42
commit
3657f939f5
|
@ -1,3 +1,12 @@
|
|||
2014-05-05 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* extensions/realtime_graphs
|
||||
extensions/realtime_graphs/ajax.php
|
||||
extensions/realtime_graphs/realtime_graphs.css
|
||||
extensions/realtime_graphs/realtime_graphs.js
|
||||
extensions/realtime_graphs.php: Added real time graphs
|
||||
extension for ticket #736
|
||||
|
||||
2014-05-05 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2014 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
include_once('include/graphs/fgraph.php');
|
||||
include_once('include/functions_snmp_browser.php');
|
||||
|
||||
function pandora_realtime_graphs () {
|
||||
global $config;
|
||||
check_login ();
|
||||
|
||||
$id_network = get_parameter('id_network', 0);
|
||||
$action = get_parameter('action', 'list');
|
||||
|
||||
$onheader = array();
|
||||
|
||||
ui_print_page_header (__("Realtime graphs"), "images/extensions.png", false, "", false, $onheader);
|
||||
|
||||
$chart[time()]['graph'] = '0';
|
||||
$interactive_graph = true;
|
||||
$color = array();
|
||||
$legend = '';
|
||||
$long_index = array();
|
||||
$no_data_image = '';
|
||||
|
||||
$canvas = '<div id="graph_container">';
|
||||
$canvas .= '<div id="chartLegend"></div>';
|
||||
$canvas .= area_graph($interactive_graph, $chart, 800, 300, $color, $legend, $long_index, $no_data_image, "", "", "",
|
||||
"", '', '', '', 1, array(), array(), 0, 0, '', false, '', false);
|
||||
$canvas .= '</div>';
|
||||
echo $canvas;
|
||||
|
||||
$table->width = '99%';
|
||||
$table->id = 'table-form';
|
||||
$table->class = 'databox';
|
||||
$table->style = array ();
|
||||
$table->style[0] = 'font-weight: bold;';
|
||||
$table->style[1] = 'font-weight: bold;';
|
||||
$table->style[2] = 'font-weight: bold;';
|
||||
$table->data = array ();
|
||||
|
||||
$graph_fields['cpu_load'] = __('Pandora Server CPU');
|
||||
$graph_fields['pending_packets'] = __('Pandora Server Pending packets');
|
||||
$graph_fields['disk_io_wait'] = __('Pandora Server Disk IO Wait');
|
||||
$graph_fields['apache_load'] = __('Pandora Server Apache load');
|
||||
$graph_fields['mysql_load'] = __('Pandora Server MySQL load');
|
||||
$graph_fields['server_load'] = __('Pandora Server load');
|
||||
$graph_fields['snmp_interface'] = __('SNMP Interface throughput');
|
||||
|
||||
$graph = get_parameter('graph', 'cpu_load');
|
||||
$refresh = get_parameter('refresh', '1000');
|
||||
|
||||
$data['graph'] = __('Graph') . '<br>' . html_print_select ($graph_fields, 'graph', $graph, '', '', 0, true);
|
||||
$data['reset'] = html_print_button(__('Clear graph'), 'reset', false, 'clearGraph()', 'class="sub delete"', true);
|
||||
|
||||
$refresh_fields[1000] = human_time_description_raw(1, true, 'large');
|
||||
$refresh_fields[5000] = human_time_description_raw(5, true, 'large');
|
||||
$refresh_fields[10000] = human_time_description_raw(10, true, 'large');
|
||||
$refresh_fields[30000] = human_time_description_raw(30, true, 'large');
|
||||
|
||||
$data['refresh'] = __('Refresh interval') . '<br>' . html_print_select ($refresh_fields, 'refresh', $refresh, '', '', 0, true);
|
||||
$data['incremental'] = __('Incremental') . '<br>' . html_print_checkbox ('incremental', 1, 0, true);
|
||||
|
||||
$table->data[] = $data;
|
||||
|
||||
|
||||
if ($graph == 'snmp_interface') {
|
||||
$snmp_address = '';
|
||||
$snmp_community = '';
|
||||
$snmp_oid = '';
|
||||
$snmp_ver = '1';
|
||||
$snmp_inc = false;
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['snmp_address'] = __('Target IP') . '<br>' . html_print_input_text ('ip_target', $snmp_address, '', 50, 255, true);
|
||||
$table->colspan[1]['snmp_address'] = 2;
|
||||
|
||||
$data['snmp_community'] = __('Community') . '<br>' . html_print_input_text ('snmp_community', $snmp_community, '', 50, 255, true);
|
||||
$table->colspan[1]['snmp_community'] = 2;
|
||||
|
||||
$table->data[] = $data;
|
||||
|
||||
$snmp_versions = array();
|
||||
$snmp_versions['1'] = '1';
|
||||
$snmp_versions['2'] = '2';
|
||||
$snmp_versions['2c'] = '2c';
|
||||
|
||||
$data = array();
|
||||
$data['snmp_oid'] = __('OID') . '<br>' . html_print_input_text ('snmp_oid', $snmp_oid, '', 100, 255, true);
|
||||
$data['snmp_oid'] .= html_print_button (__('SNMP walk'), 'snmp_walk', false, 'snmpBrowserWindow()', 'class="sub next"', true);
|
||||
$table->colspan[2]['snmp_oid'] = 2;
|
||||
|
||||
$data['snmp_ver'] = __('Version') . '<br>' . html_print_select ($snmp_versions, 'snmp_version', $snmp_ver, '', '', 0, true);
|
||||
|
||||
$table->colspan[2]['snmp_ver'] = 2;
|
||||
|
||||
$table->data[] = $data;
|
||||
|
||||
snmp_browser_print_container (false, '100%', '60%', 'none');
|
||||
}
|
||||
|
||||
echo '<form id="realgraph" method="post">';
|
||||
html_print_table($table);
|
||||
echo '</form>';
|
||||
|
||||
// Define a custom action to save the OID selected in the SNMP browser to the form
|
||||
html_print_input_hidden ('custom_action', urlencode (base64_encode(' <a href="javascript:setOID()"><img src="' . ui_get_full_url("images") . '/hand_point.png" title="' . __("Use this OID") . '" style="vertical-align: middle;"></img></a>')), false);
|
||||
html_print_input_hidden ('incremental_base', '0');
|
||||
|
||||
echo '<script type="text/javascript" src="extensions/realtime_graphs/realtime_graphs.js"></script>';
|
||||
echo '<script type="text/javascript" src="include/javascript/pandora_snmp_browser.js"></script>';
|
||||
echo '<link rel="stylesheet" type="text/css" href="extensions/realtime_graphs/realtime_graphs.css"></style>';
|
||||
}
|
||||
|
||||
extensions_add_operation_menu_option (__('Realtime graphs'), null, null, "v1r1");
|
||||
extensions_add_main_function ('pandora_realtime_graphs');
|
||||
|
||||
$db = NULL;
|
||||
?>
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2014 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
require_once ('../../include/functions_html.php');
|
||||
|
||||
$graph = $_POST['graph'];
|
||||
$graph_title = $_POST['graph_title'];
|
||||
$refresh = $_POST['refresh'];
|
||||
|
||||
switch($graph) {
|
||||
case 'cpu_load':
|
||||
$data = exec("top -bn 2 -d 0.01 | grep '^Cpu' | tail -n 1 | awk '{print $2+$4+$6}'");
|
||||
break;
|
||||
case 'pending_packets':
|
||||
$data = exec("find /var/spool/pandora/data_in/*.data | wc -l");
|
||||
break;
|
||||
case 'disk_io_wait':
|
||||
$data = exec("vmstat 1 3 | tail -1 | awk '{ print $16 }'");
|
||||
break;
|
||||
case 'mysql_load':
|
||||
$data = exec("ps aux | grep mysqld | grep -v safe | grep -v grep | awk '{ print $3 }'");
|
||||
break;
|
||||
case 'apache_load':
|
||||
$data = exec("ps aux | grep apache2 | grep -v safe | grep -v grep | awk '{ print $3 }'");
|
||||
break;
|
||||
case 'server_load':
|
||||
$data = exec("ps aux | grep pandora_server | grep -v grep | awk '{print $3}'");
|
||||
break;
|
||||
case 'snmp_interface':
|
||||
$snmp_address = $_POST['snmp_address'];
|
||||
$snmp_community = $_POST['snmp_community'];
|
||||
$snmp_ver = $_POST['snmp_ver'];
|
||||
$snmp_oid = $_POST['snmp_oid'];
|
||||
|
||||
if (empty($snmp_address) || empty($snmp_oid)) {
|
||||
$data = 0;
|
||||
}
|
||||
else {
|
||||
$data = get_snmpwalk($snmp_address, $snmp_ver, $snmp_community, '', '', '', '', '', '', 0, $snmp_oid);
|
||||
$data_index = array_keys($data);
|
||||
$graph_title = $data_index[0];
|
||||
if (!empty($data)) {
|
||||
$data_array = explode(' ', reset($data));
|
||||
if (count($data_array) > 1) {
|
||||
$data = $data_array[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$data = 0;
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
$data = 0;
|
||||
}
|
||||
|
||||
$graph_title .= ' (' . $refresh/1000 . ' ' . __('Seconds') . ')';
|
||||
echo '{
|
||||
"label": "' . $graph_title . '",
|
||||
"data": [["' . time() . '", ' . $data . ']]
|
||||
}';
|
||||
?>
|
|
@ -0,0 +1,15 @@
|
|||
#chartLegend {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
#chartLegend table {
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
#graph_container {
|
||||
width: 800px;
|
||||
margin: 20px auto !important;
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
var max_data_plot = 100;
|
||||
|
||||
var options = {
|
||||
legend: { container: $("#chartLegend") },
|
||||
xaxis: {
|
||||
tickFormatter: function (timestamp, axis) {
|
||||
var date = new Date(timestamp * 1000);
|
||||
var hours = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
|
||||
var minutes = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
|
||||
var seconds = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
|
||||
var formattedTime = hours + ':' + minutes + ':' + seconds;
|
||||
return formattedTime;
|
||||
}
|
||||
},
|
||||
series: {
|
||||
lines: {
|
||||
lineWidth: 2,
|
||||
fill: true
|
||||
}
|
||||
},
|
||||
colors: ['#6db431']
|
||||
}
|
||||
|
||||
var data = [];
|
||||
|
||||
var id = $('.graph').attr('id');
|
||||
var plot = $.plot("#" + id, data, options);
|
||||
|
||||
|
||||
var refresh = parseInt($('#refresh').val());
|
||||
var incremental = $('#checkbox-incremental').is(':checked');
|
||||
var incremental_base = 0;
|
||||
var last_inc = 0;
|
||||
|
||||
refresh_graph();
|
||||
|
||||
function refresh_graph () {
|
||||
var refresh = parseInt($('#refresh').val());
|
||||
|
||||
var postvars = new Array();
|
||||
var postvars = {};
|
||||
postvars['graph'] = $('#graph :selected').val();
|
||||
postvars['graph_title'] = $('#graph :selected').html();
|
||||
|
||||
postvars['snmp_community'] = $('#text-snmp_community').val();
|
||||
postvars['snmp_oid'] = $('#text-snmp_oid').val();
|
||||
postvars['snmp_ver'] = $('#snmp_version :selected').val();
|
||||
postvars['snmp_address'] = $('#text-ip_target').val();
|
||||
|
||||
postvars['refresh'] = refresh;
|
||||
|
||||
$.ajax({
|
||||
url: "extensions/realtime_graphs/ajax.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: postvars,
|
||||
success: function(serie) {
|
||||
var timestamp = serie.data[0][0];
|
||||
data = plot.getData();
|
||||
if (data.length == 0) {
|
||||
for(i = 0; i < max_data_plot; i ++) {
|
||||
step = i * (refresh/1000);
|
||||
serie.data.unshift([timestamp-step, 0]);
|
||||
}
|
||||
|
||||
serie = [serie];
|
||||
plot = $.plot("#" + id, serie, options);
|
||||
return;
|
||||
}
|
||||
data[0].label = serie.label;
|
||||
if (data[0].data.length >= max_data_plot) {
|
||||
data[0].data.shift();
|
||||
}
|
||||
|
||||
if (incremental) {
|
||||
var last_item = parseInt(data[0].data.length)-1;
|
||||
var last_value = data[0].data[last_item][1];
|
||||
|
||||
var current_value = serie.data[0][1];
|
||||
|
||||
serie.data[0][1] = current_value - last_inc;
|
||||
|
||||
last_inc = current_value;
|
||||
|
||||
// Incremental is always positive
|
||||
if (serie.data[0][1] < 0) {
|
||||
serie.data[0][1] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data[0].data.push(serie.data[0]);
|
||||
$.plot("#" + id, data, options);
|
||||
}
|
||||
});
|
||||
window.setTimeout(refresh_graph, refresh);
|
||||
}
|
||||
|
||||
$('#graph').change(function() {
|
||||
$('form#realgraph').submit();
|
||||
});
|
||||
|
||||
$('#refresh').change(function() {
|
||||
//refresh_graph();
|
||||
});
|
||||
|
||||
// Show the SNMP browser window
|
||||
function snmpBrowserWindow () {
|
||||
|
||||
// Keep elements in the form and the SNMP browser synced
|
||||
$('#text-target_ip').val($('#text-ip_target').val());
|
||||
$('#text-community').val($('#text-snmp_community').val());
|
||||
$('#snmp_browser_version').val($('#snmp_version').val());
|
||||
$('#snmp3_browser_auth_user').val($('#snmp3_auth_user').val());
|
||||
$('#snmp3_browser_security_level').val($('#snmp3_security_level').val());
|
||||
$('#snmp3_browser_auth_method').val($('#snmp3_auth_method').val());
|
||||
$('#snmp3_browser_auth_pass').val($('#snmp3_auth_pass').val());
|
||||
$('#snmp3_browser_privacy_method').val($('#snmp3_privacy_method').val());
|
||||
$('#snmp3_browser_privacy_pass').val($('#snmp3_privacy_pass').val());
|
||||
|
||||
$("#snmp_browser_container").show().dialog ({
|
||||
title: '',
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
},
|
||||
width: 730,
|
||||
height: 430
|
||||
});
|
||||
}
|
||||
|
||||
// Set the form OID to the value selected in the SNMP browser
|
||||
function setOID () {
|
||||
$('#text-snmp_oid').val($('#snmp_selected_oid').text());
|
||||
|
||||
// Close the SNMP browser
|
||||
$('.ui-dialog-titlebar-close').trigger('click');
|
||||
}
|
||||
|
||||
$('#checkbox-incremental').change(function() {
|
||||
incremental = $('#checkbox-incremental').is(':checked');
|
||||
clearGraph();
|
||||
});
|
||||
|
||||
function firstNotZero(data) {
|
||||
var notZero = 0;
|
||||
for(i = 0; i < data[0].data.length; i ++) {
|
||||
if (data[0].data[i][1] != 0) {
|
||||
return data[0].data[i][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setOnIncremental() {
|
||||
|
||||
}
|
||||
|
||||
function clearGraph() {
|
||||
data = plot.getData();
|
||||
if (data.length == 0) {
|
||||
return;
|
||||
}
|
||||
console.log(data);
|
||||
|
||||
for(i = 0; i < data[0].data.length; i ++) {
|
||||
data[0].data[i][1] = 0;
|
||||
}
|
||||
|
||||
$.plot("#" + id, data, options);
|
||||
}
|
Loading…
Reference in New Issue