More updates to tune rrdfiles

This commit is contained in:
laf
2015-11-17 05:14:41 -08:00
parent 01435cc4d8
commit 253b27d403
7 changed files with 87 additions and 30 deletions

View File

@@ -1,28 +1,32 @@
function override_config(event, state, tmp_this) {
event.preventDefault();
var $this = tmp_this;
var attrib = $this.data('attrib');
var device_id = $this.data('device_id');
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: 'override-config', device_id: device_id, attrib: attrib, state: state },
dataType: 'json',
success: function(data) {
if (data.status == 'ok') {
toastr.success(data.message);
}
else {
toastr.error(data.message);
}
},
error: function() {
toastr.error('Could not set this override');
}
});
}
$(document).ready(function() { $(document).ready(function() {
// Device override ajax calls // Device override ajax calls
$("[name='override_config']").bootstrapSwitch('offColor','danger'); $("[name='override_config']").bootstrapSwitch('offColor','danger');
$('input[name="override_config"]').on('switchChange.bootstrapSwitch', function(event, state) { $('input[name="override_config"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault(); override_config(event,state,$(this));
var $this = $(this);
var attrib = $this.data('attrib');
var device_id = $this.data('device_id');
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: 'override-config', device_id: device_id, attrib: attrib, state: state },
dataType: 'json',
success: function(data) {
if (data.status == 'ok') {
toastr.success(data.message);
}
else {
toastr.error(data.message);
}
},
error: function() {
toastr.error('Could not set this override');
}
});
}); });
// Device override for text inputs // Device override for text inputs

View File

@@ -3,23 +3,29 @@
echo ' echo '
<form class="form-horizontal"> <form class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label for="icmp" class="col-sm-2 control-label">Disable ICMP Test?</label> <label for="icmp" class="col-sm-4 control-label">Disable ICMP Test?</label>
<div class="col-sm-10"> <div class="col-sm-8">
'.dynamic_override_config('checkbox','override_icmp_disable', $device).' '.dynamic_override_config('checkbox','override_icmp_disable', $device).'
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="oxidized" class="col-sm-2 control-label">Exclude from Oxidized?</label> <label for="oxidized" class="col-sm-4 control-label">Exclude from Oxidized?</label>
<div class="col-sm-10"> <div class="col-sm-8">
'.dynamic_override_config('checkbox','override_Oxidized_disable', $device).' '.dynamic_override_config('checkbox','override_Oxidized_disable', $device).'
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="unixagent" class="col-sm-2 control-label">Unix agent port</label> <label for="unixagent" class="col-sm-4 control-label">Unix agent port</label>
<div class="col-sm-10"> <div class="col-sm-8">
'.dynamic_override_config('text','override_Unixagent_port', $device).' '.dynamic_override_config('text','override_Unixagent_port', $device).'
</div> </div>
</div> </div>
<div class="form-group">
<label for="unixagent" class="col-sm-4 control-label">Enable RRD Tune for all ports?</label>
<div class="col-sm-8">
'.dynamic_override_config('checkbox','override_rrdtool_tune', $device).'
</div>
</div>
</form> </form>
'; ';

View File

@@ -34,6 +34,17 @@ $unixagent_conf = array(
), ),
); );
$rrdtool_conf = array(
array('name' => 'rrdtool',
'descr' => 'Path to rrdtool binary',
'type' => 'text',
),
array('name' => 'rrdtool.tune',
'descr' => 'Tune all rrd port files to use max values',
'type' => 'checkbox',
),
);
echo ' echo '
<div class="panel-group" id="accordion"> <div class="panel-group" id="accordion">
<form class="form-horizontal" role="form" action="" method="post"> <form class="form-horizontal" role="form" action="" method="post">
@@ -41,6 +52,7 @@ echo '
echo generate_dynamic_config_panel('Oxidized integration',true,$config_groups,$oxidized_conf); echo generate_dynamic_config_panel('Oxidized integration',true,$config_groups,$oxidized_conf);
echo generate_dynamic_config_panel('Unix-agent integration',true,$config_groups,$unixagent_conf); echo generate_dynamic_config_panel('Unix-agent integration',true,$config_groups,$unixagent_conf);
echo generate_dynamic_config_panel('RRDTool Setup',true,$config_groups,$rrdtool_conf);
echo ' echo '
</form> </form>

View File

@@ -336,7 +336,7 @@ foreach ($ports as $port) {
} }
else if ($port[$oid] != $this_port[$oid]) { else if ($port[$oid] != $this_port[$oid]) {
$port_tune = get_dev_attrib($device, 'ifName_tune:'.$port['ifName']); $port_tune = get_dev_attrib($device, 'ifName_tune:'.$port['ifName']);
$device_tune = get_dev_attrib($device,'device_rrdtool_tune'); $device_tune = get_dev_attrib($device,'override_rrdtool_tune');
if ($port_tune == "true" || if ($port_tune == "true" ||
($device_tune == "true" && $port_tune != 'false') || ($device_tune == "true" && $port_tune != 'false') ||
($config['rrdtool']['tune'] == "true" && $port_tune != 'false' && $device_tune != 'false')) { ($config['rrdtool']['tune'] == "true" && $port_tune != 'false' && $device_tune != 'false')) {

View File

@@ -166,7 +166,7 @@ function rrdtool_graph($graph_file, $options) {
function rrdtool($command, $filename, $options) { function rrdtool($command, $filename, $options) {
global $config, $debug, $rrd_pipes, $console_color; global $config, $debug, $rrd_pipes, $console_color;
if ($config['rrdcached'] && ($config['rrdtool_version'] >= 1.5 || ($command != "create" && $command != 'tune'))) { if ($config['rrdcached'] && ($config['rrdtool_version'] >= 1.5 || ($command != "create" && $command != "tune"))) {
if (isset($config['rrdcached_dir']) && $config['rrdcached_dir'] !== false) { if (isset($config['rrdcached_dir']) && $config['rrdcached_dir'] !== false) {
$filename = str_replace($config['rrd_dir'].'/', './'.$config['rrdcached_dir'].'/', $filename); $filename = str_replace($config['rrd_dir'].'/', './'.$config['rrdcached_dir'].'/', $filename);
$filename = str_replace($config['rrd_dir'], './'.$config['rrdcached_dir'].'/', $filename); $filename = str_replace($config['rrd_dir'], './'.$config['rrdcached_dir'].'/', $filename);
@@ -304,7 +304,7 @@ function rrdtool_tune($type, $filename, $max) {
$fields = array( $fields = array(
'INOCTETS','OUTOCTETS','INERRORS','OUTERRORS','INUCASTPKTS','OUTUCASTPKTS','INNUCASTPKTS','OUTNUCASTPKTS','INDISCARDS','OUTDISCARDS','INUNKNOWNPROTOS','INBROADCASTPKTS','OUTBROADCASTPKTS','INMULTICASTPKTS','OUTMULTICASTPKTS' 'INOCTETS','OUTOCTETS','INERRORS','OUTERRORS','INUCASTPKTS','OUTUCASTPKTS','INNUCASTPKTS','OUTNUCASTPKTS','INDISCARDS','OUTDISCARDS','INUNKNOWNPROTOS','INBROADCASTPKTS','OUTBROADCASTPKTS','INMULTICASTPKTS','OUTMULTICASTPKTS'
); );
$options = "--maxium " . implode(":$max --maximum ", $fields). ":$max"; $options = "--maximum " . implode(":$max --maximum ", $fields). ":$max";
rrdtool('tune', $filename, $options); rrdtool('tune', $filename, $options);
} }
} }

34
scripts/tune_port.php Executable file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env php
<?php
require 'includes/defaults.inc.php';
require 'config.php';
require 'includes/definitions.inc.php';
require 'includes/functions.php';
$options = getopt('h:p:');
$hosts = $options['h'];
$ports = $options['p'];
if (empty($hosts) && empty($ports)) {
echo "-h <device hostname wildcard> Device(s) to match\n";
echo "-p <ifName widcard> Port(s) to match using ifName\n";
echo "\n";
}
echo "TEST $hosts and $ports\n";
$debug=1;
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` WHERE `hostname` LIKE ?", array('%'.$hosts.'%')) as $device) {
echo "Found hostname " . $device['hostname'].".......\n";
foreach (dbFetchRows("SELECT `ifIndex`,`ifName`,`ifSpeed` FROM `ports` WHERE `ifName` LIKE ? AND `device_id` = ?", array('%'.$ports.'%',$device['device_id'])) as $port) {
echo "Tuning port " . $port['ifName'].".......\n";
$host_rrd = $config['rrd_dir'].'/'.$device['hostname'];
$rrdfile = $host_rrd.'/port-'.safename($port['ifIndex'].'.rrd');
rrdtool_tune('port',$rrdfile,$port['ifSpeed']);
}
}

1
sql-schema/077.sql Normal file
View File

@@ -0,0 +1 @@
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('rrdtool','/usr/bin/rrdtool','/usr/bin/rrdtool','Path to rrdtool','external',0,'rrdtool',0,'0','0'), ('rrdtool.tune','false','false','Auto tune maximum value for rrd port files','external',0,'rrdtool',0,'0','0');