add agent sensor capacity, hddtemp script in agent-local as demo, possibly needs a little more work

git-svn-id: http://www.observium.org/svn/observer/trunk@3213 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2012-05-20 18:23:40 +00:00
parent 964259210c
commit f2be2f33d2
9 changed files with 232 additions and 157 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
$sensors = dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND device_id = ? ORDER BY `sensor_index`", array($sensor_class, $device['device_id'])); $sensors = dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND device_id = ? ORDER BY `poller_type`, `sensor_index`", array($sensor_class, $device['device_id']));
if (count($sensors)) if (count($sensors))
{ {

View File

@ -116,7 +116,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
{ {
global $config, $debug; global $config, $debug;
if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $precision, $entPhysicalIndex\n"); } if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); }
if (is_null($low_warn_limit) || !is_null($warn_limit)) if (is_null($low_warn_limit) || !is_null($warn_limit))
{ {
@ -314,9 +314,9 @@ function sensor_limit($class, $current)
return $limit; return $limit;
} }
function check_valid_sensors($device, $class, $valid) function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp')
{ {
$entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ?", array($class, $device['device_id'])); $entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?", array($class, $device['device_id'], $poller_type));
if (count($entries)) if (count($entries))
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
## IPMI ## IPMI - We can discover this on poll!
if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname')) if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname'))
{ {
echo("IPMI : "); echo("IPMI : ");

View File

@ -0,0 +1,23 @@
<?php
global $agent_sensors;
include_once("includes/discovery/functions.inc.php");
$disks = explode('||',trim($agent_data['app']['hddtemp'],'|'));
if (count($disks))
{
echo "hddtemp: ";
foreach ($disks as $disk)
{
list($blockdevice,$descr,$temperature,$unit) = explode('|',$disk,4);
$diskcount++;
discover_sensor($valid['sensor'], 'temperature', $device, '', $diskcount, 'hddtemp', "$blockdevice: $descr", '1', '1', NULL, NULL, NULL, NULL, $temperature, 'agent');
$agent_sensors['temperature']['hddtemp'][$diskcount] = array('description' => "$blockdevice: $descr", 'current' => $temperature, 'index' => $diskcount);
}
echo "\n";
}
?>

View File

@ -2,12 +2,14 @@
function poll_sensor($device, $class, $unit) function poll_sensor($device, $class, $unit)
{ {
global $config, $memcache; global $config, $memcache, $agent_sensors;
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `poller_type` = 'snmp'", array($class, $device['device_id'])) as $sensor) foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ?", array($class, $device['device_id'])) as $sensor)
{ {
echo("Checking $class " . $sensor['sensor_descr'] . "... "); echo("Checking (" . $sensor['poller_type'] . ") $class " . $sensor['sensor_descr'] . "... ");
if ($sensor['poller_type'] == "snmp")
{
if ($class == "temperature") if ($class == "temperature")
{ {
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
@ -21,6 +23,23 @@ function poll_sensor($device, $class, $unit)
} else { } else {
$sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB"))); $sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB")));
} }
} else if ($sensor['poller_type'] == "agent")
{
if (isset($agent_sensors))
{
$sensor_value = $agent_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current'];
}
else
{
echo "no agent data!\n";
break;
}
}
else
{
echo "unknown poller type!\n";
break;
}
if ($sensor_value == -32768) { echo("Invalid (-32768) "); $sensor_value = 0; } if ($sensor_value == -32768) { echo("Invalid (-32768) "); $sensor_value = 0; }

View File

@ -33,10 +33,6 @@ if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname'))
$rrd_file = get_sensor_rrd($device, $ipmisensors); $rrd_file = get_sensor_rrd($device, $ipmisensors);
## 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($ipmisensors['sensor_class'].'-'.$ipmisensors['sensor_type'].'-'.$ipmisensors['sensor_index'] . ".rrd");
if (is_file($old_rrd_file)) if (is_file($old_rrd_file))
{ {
rename($old_rrd_file, $rrd_file); rename($old_rrd_file, $rrd_file);

View File

@ -1,12 +1,12 @@
<?php <?php
if($device['os_group'] == "unix") global $debug;
{
if ($device['os_group'] == "unix")
{
echo("Observium UNIX Agent: "); echo("Observium UNIX Agent: ");
### FIXME - this should be in config and overridable in database ### FIXME - this should be in config and overridable in database
$agent_port='6556'; $agent_port='6556';
$agent_start = utime(); $agent_start = utime();
@ -36,7 +36,6 @@ if($device['os_group'] == "unix")
foreach (explode("<<<", $agent_raw) as $section) foreach (explode("<<<", $agent_raw) as $section)
{ {
list($section, $data) = explode(">>>", $section); list($section, $data) = explode(">>>", $section);
list($sa, $sb) = explode("-", $section, 2); list($sa, $sb) = explode("-", $section, 2);
@ -53,15 +52,33 @@ if($device['os_group'] == "unix")
} }
} }
# print_r($agent_data); if ($debug) { print_r($agent_data); }
include("unix-agent/packages.inc.php"); include("unix-agent/packages.inc.php");
include("unix-agent/munin-plugins.inc.php"); include("unix-agent/munin-plugins.inc.php");
foreach (array_keys($agent_data) as $key)
{
if (file_exists("includes/polling/unix-agent/$key.inc.php"))
{
if ($debug) { echo("Including: unix-agent/$key.inc.php"); }
include("unix-agent/$key.inc.php");
}
}
foreach (array_keys($agent_data['app']) as $key)
{
if (file_exists("includes/polling/applications/$key.inc.php"))
{
if ($debug) { echo("Including: applications/$key.inc.php"); }
include("applications/$key.inc.php");
}
}
### Processes ### Processes
if (!empty($agent_data['ps'])) if (!empty($agent_data['ps']))
{ {
echo("\nProcesses: "); echo("Processes: ");
foreach (explode("\n", $agent_data['ps']) as $process) foreach (explode("\n", $agent_data['ps']) as $process)
{ {
$process = preg_replace("/\((.*),([0-9]*),([0-9]*),([0-9\.]*)\)\ (.*)/", "\\1|\\2|\\3|\\4|\\5", $process); $process = preg_replace("/\((.*),([0-9]*),([0-9]*),([0-9\.]*)\)\ (.*)/", "\\1|\\2|\\3|\\4|\\5", $process);
@ -69,6 +86,7 @@ if($device['os_group'] == "unix")
$processlist[] = array('user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'pcpu' => $pcpu, 'command' => $command); $processlist[] = array('user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'pcpu' => $pcpu, 'command' => $command);
} }
#print_r($processlist); #print_r($processlist);
echo("\n");
} }
### Apache ### Apache
@ -127,6 +145,13 @@ if($device['os_group'] == "unix")
} }
} }
if (!empty($agent_sensors))
{
echo("Sensors: ");
check_valid_sensors($device, 'temperature', $valid['sensor'], 'agent');
echo("\n");
}
echo("\n"); echo("\n");
} }

View File

@ -1,8 +1,8 @@
<?php <?php
### RPM ### RPM
if (!empty($agent_data['rpm'])) if (!empty($agent_data['rpm']))
{ {
echo("\nRPM Packages: "); echo("\nRPM Packages: ");
## Build array of existing packages ## Build array of existing packages
$manager = "rpm"; $manager = "rpm";
@ -34,11 +34,11 @@
$text = $manager."-".$name."-".$arch."-".$version."-".$build; $text = $manager."-".$name."-".$arch."-".$version."-".$build;
$pkgs_id[] = $pkgs[$manager][$name][$arch][$version][$build]; $pkgs_id[] = $pkgs[$manager][$name][$arch][$version][$build];
} }
} }
### DPKG ### DPKG
if (!empty($agent_data['dpkg'])) if (!empty($agent_data['dpkg']))
{ {
echo("\nDEB Packages: "); echo("\nDEB Packages: ");
## Build array of existing packages ## Build array of existing packages
$manager = "deb"; $manager = "deb";
@ -71,11 +71,11 @@
$text = $manager."-".$name."-".$arch."-".$version."-".$build; $text = $manager."-".$name."-".$arch."-".$version."-".$build;
$pkgs_id[] = $pkgs[$manager][$name][$arch][$version][$build]; $pkgs_id[] = $pkgs[$manager][$name][$arch][$version][$build];
} }
} }
## This is run for all "packages" and is common to RPM/DEB/etc ## This is run for all "packages" and is common to RPM/DEB/etc
foreach ($pkgs_id as $pkg) foreach ($pkgs_id as $pkg)
{ {
$name = $pkg['name']; $name = $pkg['name'];
$version = $pkg['version']; $version = $pkg['version'];
$build = $pkg['build']; $build = $pkg['build'];
@ -124,21 +124,23 @@
} }
} }
unset($pkg_update); unset($pkg_update);
} }
## Packages ## Packages
foreach ($pkgs_db_id as $id => $pkg) foreach ($pkgs_db_id as $id => $pkg)
{ {
dbDelete('packages', "`pkg_id` = ?", array($id)); dbDelete('packages', "`pkg_id` = ?", array($id));
echo("-".$pkg['text']); echo("-".$pkg['text']);
log_event('Package removed: '.$pkg['name'].' '.$pkg['arch'].' '.$pkg['version']. ($pkg['build'] != '' ? "-".$pkg['build'] : ''), $device, 'package'); log_event('Package removed: '.$pkg['name'].' '.$pkg['arch'].' '.$pkg['version']. ($pkg['build'] != '' ? "-".$pkg['build'] : ''), $device, 'package');
} }
unset($pkg); echo "\n";
unset($pkgs_db_id);
unset($pkg_c); unset($pkg);
unset($pkgs); unset($pkgs_db_id);
unset($pkgs_db); unset($pkg_c);
unset($pkgs_db_db); unset($pkgs);
unset($pkgs_db);
unset($pkgs_db_db);
?> ?>

10
scripts/agent-local/hddtemp Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# hddtemp sensor readings
# needs hddtemp daemon listening on (at least) localhost
# requires netcat to be installed and in the path
# (c) 2012, Tom Laermans for Observium
echo '<<<app-hddtemp>>>'
nc localhost 7634
echo