unify sensor rrd filenaming, move to fuction.

git-svn-id: http://www.observium.org/svn/observer/trunk@2168 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-04-26 15:07:52 +00:00
parent 8fa88ade9f
commit f80ecae2e3
12 changed files with 51 additions and 33 deletions

View File

@@ -9,7 +9,8 @@ if (is_numeric($id))
$device = device_by_id_cache($sensor['device_id']); $device = device_by_id_cache($sensor['device_id']);
### This doesn't quite work for all yet. ### This doesn't quite work for all yet.
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename($sensor['sensor_class']."-" . $sensor['sensor_type'] . "-".$sensor['sensor_index'].".rrd"); #$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename($sensor['sensor_class']."-" . $sensor['sensor_type'] . "-".$sensor['sensor_index'].".rrd");
$rrd_filename = get_sensor_rrd($device, $sensor);
$title = generate_device_link($device); $title = generate_device_link($device);
$title .= " :: Sensor :: " . htmlentities($sensor['sensor_descr']); $title .= " :: Sensor :: " . htmlentities($sensor['sensor_descr']);
@@ -17,4 +18,4 @@ if (is_numeric($id))
} }
} }
?> ?>

View File

@@ -4,8 +4,6 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("current-" . $sensor['sensor_descr'] . ".rrd");
$rrd_options .= " COMMENT:' Min Last Max\\n'"; $rrd_options .= " COMMENT:' Min Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 18),0,18); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 18),0,18);
@@ -19,4 +17,4 @@ $rrd_options .= " GPRINT:sensor:MAX:%5.2lfA\\\\l";
if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";
?> ?>

View File

@@ -4,8 +4,6 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fanspeed-" . $sensor['sensor_type'] .'-'. $sensor['sensor_index'] . ".rrd");
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 20),0,20); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 20),0,20);
@@ -18,4 +16,4 @@ $rrd_options .= " GPRINT:sensor:MAX:%3.0lfrpm\\\\l";
if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";
?> ?>

View File

@@ -4,8 +4,6 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("frequency-" . $sensor['sensor_descr'] . ".rrd");
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28);
@@ -18,4 +16,4 @@ $rrd_options .= " GPRINT:sensor:MAX:%3.0lfHz\\\\l";
if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";
?> ?>

View File

@@ -5,8 +5,6 @@ $scale_max = "40";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("humidity-" . $sensor['sensor_descr'] . ".rrd");
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28);
@@ -30,4 +28,4 @@ $rrd_options .= " GPRINT:sensor:MAX:%3.0lf%%\\\\l";
if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";
?> ?>

View File

@@ -4,8 +4,6 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/power-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_options .= " -A "; $rrd_options .= " -A ";
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";

View File

@@ -5,8 +5,6 @@ $scale_max = "60";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/temperature-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_options .= " COMMENT:' Min Last Max\\n'"; $rrd_options .= " COMMENT:' Min Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 21),0,21); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 21),0,21);
@@ -34,4 +32,4 @@ $rrd_options .= " GPRINT:sensor_max:MAX:%4.1lfC\\\\l";
if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";
?> ?>

View File

@@ -4,8 +4,6 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/voltage-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_options .= " -A "; $rrd_options .= " -A ";
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
@@ -27,4 +25,4 @@ $rrd_options .= " GPRINT:sensor:MAX:%6.2lfV\\\\l";
if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if (is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if (is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";
?> ?>

View File

@@ -2,6 +2,21 @@
## Common Functions ## Common Functions
function get_sensor_rrd($device, $sensor)
{
global $config;
if($config['os'][$device['os']]['sensor_descr'] || $sensor['poller_type'] == "ipmi")
{
$rrd_file = $config['rrd_dir']."/".$device['hostname']."/".safename("sensor-".$sensor['sensor_class']."-".$sensor['sensor_type']."-".$sensor['sensor_descr'] . ".rrd");
} else {
$rrd_file = $config['rrd_dir']."/".$device['hostname']."/".safename("sensor-".$sensor['sensor_class']."-".$sensor['sensor_type']."-".$sensor['sensor_index'] . ".rrd");
}
return($rrd_file);
}
function get_port_by_id($port_id) function get_port_by_id($port_id)
{ {
if (is_numeric($port_id)) if (is_numeric($port_id))

View File

@@ -16,20 +16,35 @@ function poll_sensor($device, $class, $unit)
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; } if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; } if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("$class-" . $sensor['sensor_descr'] . ".rrd"); $rrd_file = get_sensor_rrd($device, $sensor);
#$rrd_file = $config['rrd_dir']."/".$device['hostname']."/".safename("sensor-".$sensor['sensor_class']."-".$sensor['sensor_type']."-".$sensor['sensor_index'] . ".rrd");
## FIXME - sensor name format change 2011/04/26 - remove this in $amount_of_time.
## We don't want to reduce performance forever because douchebags don't svn up!
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("$class-" . $sensor['sensor_descr'] . ".rrd");
$old_rrd_file_b = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("$class-" . $sensor['sensor_index'] . ".rrd");
if (is_file($old_rrd_file) && is_file($old_rrd_file_b))
{
rename($old_rrd_file, $rrd_file);
unlink($old_rrd_file_b);
} elseif (is_file($old_rrd_file)) {
rename($old_rrd_file, $rrd_file);
} elseif (is_file($old_rrd_file_b)) {
rename($old_rrd_file_b, $rrd_file);
}
if (!is_file($rrd_file)) if (!is_file($rrd_file))
{ {
rrdtool_create($rrd_file,"--step 300 \ rrdtool_create($rrd_file,"--step 300 \
DS:sensor:GAUGE:600:-20000:20000 \ DS:sensor:GAUGE:600:-20000:20000 \
RRA:AVERAGE:0.5:1:1200 \ RRA:AVERAGE:0.5:1:1200 \
RRA:AVERAGE:0.5:12:2400 \ RRA:AVERAGE:0.5:12:2400 \
RRA:AVERAGE:0.5:288:750 \ RRA:AVERAGE:0.5:288:1200 \
RRA:MAX:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \
RRA:MAX:0.5:288:750 \ RRA:MAX:0.5:288:1200 \
RRA:MIN:0.5:12:2400 \ RRA:MIN:0.5:12:2400 \
RRA:MIN:0.5:288:750"); RRA:MIN:0.5:288:1200");
} }
echo("$sensor_value $unit\n"); echo("$sensor_value $unit\n");

View File

@@ -23,8 +23,9 @@ while ($sensor = mysql_fetch_assoc($sensor_data))
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; } if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; } if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("$class-" . $sensor['sensor_descr'] . ".rrd"); $old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/$class-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/$class-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_file = get_sensor_rrd($device, $sensor);
if (is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); } if (is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); }
@@ -62,4 +63,4 @@ while ($sensor = mysql_fetch_assoc($sensor_data))
mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'"); mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'");
} }
?> ?>

View File

@@ -15,8 +15,8 @@ while ($sensor = mysql_fetch_assoc($sensor_data))
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; } if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; } if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("$class-" . $sensor['sensor_descr'] . ".rrd"); $old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/$class-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/$class-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd"; $rrd_file = get_sensor_rrd($device, $sensor);
if (is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); } if (is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); }
@@ -53,4 +53,4 @@ while ($sensor = mysql_fetch_assoc($sensor_data))
mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'"); mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'");
} }
?> ?>