new agent-based applications

git-svn-id: http://www.observium.org/svn/observer/trunk@3059 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2012-04-19 15:36:46 +00:00
parent 40e807a638
commit c09d5af16b
14 changed files with 1996 additions and 64 deletions

View File

@ -0,0 +1,21 @@
<?php
$scale_min = 0;
include("includes/graphs/common.inc.php");
$drbd_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd";
if (is_file($drbd_rrd))
{
$rrd_filename = $drbd_rrd;
}
$ds_in = "dr";
$ds_out = "dw";
$multiplier = "8";
include("includes/graphs/generic_bits.inc.php");
?>

View File

@ -0,0 +1,21 @@
<?php
$scale_min = 0;
include("includes/graphs/common.inc.php");
$drbd_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd";
if (is_file($drbd_rrd))
{
$rrd_filename = $drbd_rrd;
}
$ds_in = "nr";
$ds_out = "ns";
$multiplier = "8";
include("includes/graphs/generic_bits.inc.php");
?>

View File

@ -0,0 +1,37 @@
<?php
include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd";
$array = array(
'lo' => 'Local I/O',
'pe' => 'Pending',
'ua' => 'UnAcked',
'ap' => 'App Pending',
);
$i = 0;
if (is_file($rrd_filename))
{
foreach ($array as $ds => $vars)
{
$rrd_list[$i]['filename'] = $rrd_filename;
if (is_array($vars))
{
$rrd_list[$i]['descr'] = $vars['descr'];
} else {
$rrd_list[$i]['descr'] = $vars;
}
$rrd_list[$i]['ds'] = $ds;
$i++;
}
} else { echo("file missing: $file"); }
$colours = "mixed";
$nototal = 0;
$unit_text = "";
include("includes/graphs/generic_multi_simplex_seperated.inc.php");
?>

View File

@ -0,0 +1,28 @@
<?php
$scale_min = 0;
include("includes/graphs/common.inc.php");
$drbd_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd";
if (is_file($drbd_rrd))
{
$rrd_filename = $drbd_rrd;
}
$ds = "oos";
$colour_area = "CDEB8B";
$colour_line = "006600";
$colour_area_max = "FFEE99";
$graph_max = 1;
$multiplier = 8;
$unit_text = "Bytes";
include("includes/graphs/generic_simplex.inc.php");
?>

View File

@ -146,8 +146,10 @@ if ($error_msg) {
$dst_x = '0'; // destination x
$dst_y = '0'; // destination y
$dst_im = imagecreatetruecolor($src_w, $src_h);
imagesavealpha($dst_im, true);
$white = imagecolorallocate($dst_im, 255, 255, 255);
imagefill($dst_im, 0, 0, $white);
$trans_colour = imagecolorallocatealpha($dst_im, 0, 0, 0, 127);
imagefill($dst_im, 0, 0, $trans_colour);
imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
imagepng($dst_im);
imagedestroy($dst_im);

View File

@ -0,0 +1,29 @@
<?php
echo('<h2>'.$app['app_instance'].'</h2>');
$graphs = array('drbd_network_bits' => 'Network Traffic',
'drbd_disk_bits' => 'Disk Traffic',
'drbd_unsynced' => 'Unsynced Data',
'drbd_queue' => 'Queues');
foreach ($graphs as $key => $text)
{
$graph_array['height'] = "100";
$graph_array['width'] = "215";
$graph_array['to'] = $now;
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = "application_".$key;
echo('<h3>'.$text.'</h3>');
echo("<tr bgcolor='$row_colour'><td colspan=5>");
include("includes/print-quadgraphs.inc.php");
echo("</td></tr>");
}
?>

View File

@ -1,5 +1,24 @@
<?php
/**
* Observium Network Management and Monitoring System
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* See COPYING for more details.
*
* @package observium
* @subpackage config
* @author Adam Armstrong <adama@memetic.org>
* @copyright (C) 2006 - 2012 Adam Armstrong
* @license http://gnu.org/copyleft/gpl.html GNU GPL
*
*/
####
#### Please don't edit this file -- make changes to the configuration array in config.php
####
@ -413,7 +432,6 @@ $config['poller_modules']['bgp-peers'] = 1;
$config['poller_modules']['junose-atm-vp'] = 1;
$config['poller_modules']['toner'] = 1;
$config['poller_modules']['ucd-diskio'] = 1;
$config['poller_modules']['applications'] = 1;
$config['poller_modules']['wifi'] = 1;
$config['poller_modules']['ospf'] = 1;
$config['poller_modules']['cisco-ipsec-flow-monitor'] = 1;
@ -427,6 +445,8 @@ $config['poller_modules']['cisco-ace-serverfarms'] = 1;
$config['poller_modules']['netscaler-vsvr'] = 1;
$config['poller_modules']['entity-physical'] = 1;
$config['poller_modules']['unix-agent'] = 0;
$config['poller_modules']['applications'] = 1;
## List of discovery modules. Need to be in this array to be
## considered for execution.

View File

@ -2,16 +2,22 @@
## Polls Apache statistics from script via SNMP
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-apache-".$app['app_id'].".rrd";
if(!empty($agent_data['apache']))
{
$apache = $agent_data['apache'];
} else {
$options = "-O qv";
$oid = "nsExtendOutputFull.6.97.112.97.99.104.101";
$apache = snmp_get($device, $oid, $options);
}
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-apache-".$app['app_id'].".rrd";
echo(" apache");
list ($total_access, $total_kbyte, $cpuload, $uptime, $reqpersec, $bytespersec, $bytesperreq, $busyworkers, $idleworkers,
$score_wait, $score_start, $score_reading, $score_writing, $score_keepalive, $score_dns, $score_closing, $score_logging, $score_graceful, $score_idle, $score_open) = explode("\n", $apache);
$score_wait, $score_start, $score_reading, $score_writing, $score_keepalive, $score_dns, $score_closing, $score_logging,
$score_graceful, $score_idle, $score_open) = explode("\n", $apache);
if (!is_file($rrd_filename))
{

View File

@ -0,0 +1,48 @@
<?php
$drbd_dev = $app['app_instance'];
$drbd_data = $agent_data['drbd'][$drbd_dev];
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$drbd_dev.".rrd";
foreach(explode("|", $drbd_data) as $part)
{
list($stat, $val) = explode("=", $part);
if(!empty($stat))
{
$drbd[$stat] = $val;
}
}
if (!is_file($rrd_filename)) {
rrdtool_create ($rrd_filename, "--step 300 \
DS:ns:DERIVE:600:0:125000000000 \
DS:nr:DERIVE:600:0:125000000000 \
DS:dw:DERIVE:600:0:125000000000 \
DS:dr:DERIVE:600:0:125000000000 \
DS:al:DERIVE:600:0:125000000000 \
DS:bm:DERIVE:600:0:125000000000 \
DS:lo:GAUGE:600:0:125000000000 \
DS:pe:GAUGE:600:0:125000000000 \
DS:ua:GAUGE:600:0:125000000000 \
DS:ap:GAUGE:600:0:125000000000 \
DS:oos:GAUGE:600:0:125000000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:3:600 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797");
}
rrdtool_update($rrd_filename, "N:".$drbd['ns'].":".$drbd['nr'].":".$drbd['dw'].":".$drbd['dr'].":".$drbd['al'].":".$drbd['bm'].":".$drbd['lo'].":".$drbd['pe'].":".$drbd['ua'].":".$drbd['ap'].":".$drbd['oop']);
?>

View File

@ -1,14 +1,19 @@
<?php
### Fixme - this is lame
if(!empty($agent_data['mysql']))
{
$mysql = $agent_data['mysql'];
} else {
#Polls MySQL statistics from script via SNMP
$mysql_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-mysql-".$app['app_id'].".rrd";
$mysql_cmd = $config['snmpget'] ." -m NET-SNMP-EXTEND-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
$mysql_cmd .= " nsExtendOutputFull.5.109.121.115.113.108";
$mysql = shell_exec($mysql_cmd);
}
echo(" mysql...");
$mysql_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-mysql-".$app['app_id'].".rrd";
echo(" mysql");
$data = explode("\n", $mysql);

View File

@ -2,7 +2,7 @@
if($device['os_group'] == "unix") {
echo("Observium *nix Agent: ");
echo("Observium UNIX Agent: ");
$port='6556';
@ -27,9 +27,12 @@ if(!empty($agent_raw))
$agent_data[$section] = trim($data);
}
## FIXME - split these into separate modules which are "autoloaded" when the section exists.
### RPM
if (!empty($agent_data['rpm']))
{
echo("RPM Packages ");
echo("\nRPM Packages: ");
## Build array of existing packages
$manager = "rpm";
@ -60,7 +63,10 @@ if(!empty($agent_raw))
$text = $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
foreach ($pkgs_id as $pkg) {
$name = $pkg['name'];
$version = $pkg['version'];
@ -108,8 +114,8 @@ if(!empty($agent_raw))
}
unset($pkg_update);
}
}
## Packages
foreach ($pkgs_db_id as $id => $pkg)
{
dbDelete('packages', "`pkg_id` = ?", array($id));
@ -117,6 +123,60 @@ if(!empty($agent_raw))
log_event('Package removed: '.$pkg['name'].' '.$pkg['arch'].' '.$pkg['version'].'-'.$pkg['build'], $device, 'package');
}
### Processes
if (!empty($agent_data['ps']))
{
echo("\nProcesses: ");
foreach (explode("\n", $agent_data['ps']) as $process)
{
$process = preg_replace("/\((.*),([0-9]*),([0-9]*),([0-9\.]*)\)\ (.*)/", "\\1|\\2|\\3|\\4|\\5", $process);
list($user, $vsz, $rss, $pcpu, $command) = explode("|", $process, 5);
$processlist[] = array('user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'pcpu' => $pcpu, 'command' => $command);
}
#print_r($processlist);
}
### Apache
if (!empty($agent_data['apache']))
{
$app_found['apache'] = TRUE;
if(dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?", array($device['device_id'], 'apache')) == "0")
{
echo("Found new application 'Apache'\n");
dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'apache'), 'applications');
}
}
### MySQL
if (!empty($agent_data['mysql']))
{
$app_found['mysql'] = TRUE;
if(dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?", array($device['device_id'], 'mysql')) == "0")
{
echo("Found new application 'MySQL'\n");
dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'mysql'), 'applications');
}
}
### DRBd
if (!empty($agent_data['drbd']))
{
$agent_data['drbd_raw'] = $agent_data['drbd'];
$agent_data['drbd'] = array();
foreach (explode("\n", $agent_data['drbd_raw']) as $drbd_entry)
{
list($drbd_dev, $drbd_data) = explode(":", $drbd_entry);
if(preg_match("/^drbd/", $drbd_dev))
{
$agent_data['drbd'][$drbd_dev] = $drbd_data;
if(dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ? AND `app_instance` = ?", array($device['device_id'], 'drbd', $drbd_dev)) == "0")
{
echo("Found new application 'DRBd' $drbd_dev\n");
dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'drbd', 'app_instance' => $drbd_dev), 'applications');
}
}
}
}
}
unset($pkg);

372
scripts/agent-local/drbd Executable file
View File

@ -0,0 +1,372 @@
#!/usr/bin/perl
=head1 NAME
check_drbd - Nagios plugin for DRBD
=head1 SYNOPSIS
B<check_drbd> [B<--verbose> | B<-v>]
=head1 DESCRIPTION
B<check_drbd> is a Nagios plugin for DRBD. It checks the connection state,
resource roles and disk states for every configured DRBD resource, and
produces a WARNING or CRITICAL alert if anything is amiss. The states
of both the local and remote sides of each connection are monitored.
=head2 Nagios status information
The status information emitted by this plugin is similar to the information
in F</proc/drbd>:
drbd0: Connected Primary/Secondary UpToDate/UpToDate
| | | | | |
| | | | | Remote disk state
| | | | Local disk state
| | | Remote resource role
| | Local resource role
| Connection state
DRBD device
If more than one device is present, and all devices are OK, the output is
summarised:
drbd0: PriConUpT, drbd1: SecConUpT
If any devices are not OK, the output contains their statuses in full.
=head2 Nagios performance data
Complete performance data is emitted for all configured DRBD resources:
=over
=item drbdI<*>_ns
=item drbdI<*>_nr
The volume of network data sent to and received from the peer, in kiB.
=item drbdI<*>_dw
=item drbdI<*>_dr
The volume of network data written to and read from the local disk, in kiB.
=item drbdI<*>_al
The number of updates of the activity log area of the metadata.
=item drbdI<*>_lo
The number of open requests to the local I/O subsystem issued by DRBD.
=item drbdI<*>_pe
The number of requests sent to the peer but not yet been answered by the latter.
=item drbdI<*>_ua
The number of requests received by the peer but not yet been answered by the latter.
=item drbdI<*>_ap
The number of block I/O requests forwarded by DRBD, but not yet answered by DRBD.
=item drbdI<*>_ep
The number of epoch objects.
=item drbdI<*>_oos
The amount of storage currently out-of-sync, in kiB.
=back
=head1 OPTIONS
=over
=item B<-v>, B<--verbose>
Increase the verbosity of the output messages. This disables the Nagios status
information summarisation described above: all resources' statuses are printed
in full.
=back
=head1 EXIT STATUS
=over
=item 0
All resources are OK.
=item 1
Some resources are not OK, but do not need immediate attention.
=item 2
Some resources are not OK and need immediate attention.
=item 3
An error occurred while collecting the resources' statuses.
=back
=head1 FILES
F</proc/drbd>
=head1 SEE ALSO
L<The DRBD Home Page|http://www.drbd.org/>
=cut
use strict;
use warnings;
use constant BASENAME => ($0 =~ m{.*/([^/]+)})[0] || 'check_drbd';
use constant STATE_FILE => '/proc/drbd';
use constant {
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3,
};
use Getopt::Long;
use IO::File;
sub help;
sub usage;
sub perfdata;
sub ok;
sub warning;
sub critical;
sub unknown;
sub get_state;
$SIG{__DIE__} = sub {
die @_ if $^S;
print @_;
exit UNKNOWN;
};
my $verbose;
Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions(
'verbose|v+' => \$verbose,
'help|?' => sub { help; exit 0 },
'usage' => sub { usage; exit 0 },
) and @ARGV == 0
or do { usage; exit UNKNOWN };
my @state = get_state;
my $status = OK;
print "<<<drbd>>>\n";
foreach my $id (0 .. $#state) {
my $device = $state[$id]
or next;
# Assume CRITICAL by default
foreach (qw( cs )) {
$device->{"${_}_level"} = {
Connected => OK,
Unconfigured => OK,
StandAlone => WARNING,
SyncingAll => WARNING,
SyncingQuick => WARNING,
SyncSource => WARNING,
SyncTarget => WARNING,
VerifyS => WARNING,
VerifyT => WARNING,
Disconnecting => WARNING,
TearDown => WARNING,
StartingSyncS => WARNING,
StartingSyncT => WARNING,
WFSyncUUID => WARNING,
}->{$device->{$_}};
$device->{"${_}_level"} = CRITICAL unless defined $device->{"${_}_level"};
if ($device->{oos}) {
$device->{oos_level} = {
StartingSyncS => OK,
StartingSyncT => OK,
SyncSource => OK,
SyncTarget => OK,
PausedSyncS => OK,
PausedSyncT => OK,
}->{$device->{$_}};
$device->{oos_level} = CRITICAL unless defined $device->{oos_level};
}
}
foreach (qw( ro pro )) {
$device->{"${_}_level"} = {
Primary => OK,
Secondary => OK,
}->{$device->{$_}};
$device->{"${_}_level"} = CRITICAL unless defined $device->{"${_}_level"};
}
foreach (qw( ds pds )) {
$device->{"${_}_level"} = {
UpToDate => OK,
Consistent => OK,
Negotiating => WARNING,
Attaching => WARNING,
}->{$device->{$_}};
$device->{"${_}_level"} = CRITICAL unless defined $device->{"${_}_level"};
}
my @extra;
if ($device->{oos}) {
push @extra, sprintf '%d kiB out-of-sync', $device->{oos};
}
if ($device->{iof} !~ /^r.--(.(-)?)?$/) {
$device->{iof_level} = CRITICAL;
push @extra, sprintf 'I/O flags: %s', $device->{iof};
}
my $extra = @extra ? sprintf(' (%s)', join ', ', @extra) : '';
my $level = OK;
foreach (grep /_level$/, keys %$device) {
$level = $device->{$_} if $level < $device->{$_};
}
$status = $level if $status < $level;
$device->{level} = $level;
$device->{info} = sprintf 'drbd%d:cs=%s|ro=%s|pro=%s|ds=%s|pds=%s|extra=%s', $id, $device->{cs}, $device->{ro}, $device->{pro}, $device->{ds}, $device->{pds}, $extra;
$device->{short} = sprintf 'drbd%d: %0.3s%0.3s%0.3s%s', $id, $device->{ro}, $device->{cs}, $device->{ds}, $extra; # Role and connstate reversed, like old check_drbd
foreach (qw( ns nr dw dr al bm )) {
my $value = $device->{$_};
defined $value
or next;
perfdata "${_}=${value}";
}
foreach (qw( lo pe ua ap oos )) {
my $value = $device->{$_};
defined $value
or next;
perfdata "${_}=${value}";
}
}
@state
or critical 'No DRBD volumes present';
if ($status) {
my $message = join ', ', map $_->{info}, grep { defined and $_->{level} } @state;
if ($status == WARNING) {
warning $message;
} else {
critical $message;
}
} else {
my $message = join ', ', map { ($verbose || @state == 1) ? $_->{info} : $_->{short} } grep defined, @state;
ok $message;
}
die;
###########################################################################
sub help {
print <<EOF;
Usage: @{[BASENAME]} [OPTION...]
Check DRBD resources.
Plugin options:
-v, --verbose Increase verbosity
Help options:
-?, --help Give this help list
--usage Give a short usage message
EOF
}
sub usage {
print <<EOF;
Usage: @{[BASENAME]} [-v?] [--verbose] [--help] [--usage]
EOF
}
###########################################################################
{
my @perfdata;
sub perfdata { push @perfdata, @_ }
sub _exit {
my ($status, $message) = @_;
if (defined $message) {
print $message;
} else {
print qw( OK WARNING CRITICAL )[$status] || 'UNKNOWN';
}
if (my $perfdata = shift @perfdata) {
print "|$perfdata";
}
# print "\n";
if (@perfdata) {
print '|';
print map "$_|", @perfdata;
}
print "\n";
exit $status;
}
}
sub ok { _exit OK, @_ }
sub warning { _exit WARNING, @_ }
sub critical { _exit CRITICAL, @_ }
sub unknown { _exit UNKNOWN, @_ }
###########################################################################
sub get_state {
my $io = new IO::File(STATE_FILE)
or critical "Could not open @{[STATE_FILE]} for reading: $!";
# 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
# ns:0 nr:20492 dw:20480 dr:124 al:5 bm:1296 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
my @state;
my $device;
while (<$io>) {
if (m(^ \s* (\d+): \s* cs:(\w+) \s+ (?:ro|st):(\w+)/(\w+) \s+ ds:(\w+)/(\w+) \s+ \S+ \s+ (\S+))x) {
$device = $state[$1] = {
cs => $2,
ro => $3,
pro => $4,
ds => $5,
pds => $6,
iof => $7,
};
next;
};
$device or next;
$device->{$1} = $2 while /(\w+):(\S+)/g;
}
@state;
}

1246
scripts/agent-local/mysql Executable file

File diff suppressed because it is too large Load Diff

37
scripts/agent-local/nginx Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
import urllib2
import re
data = urllib2.urlopen('http://localhost/nginx-status').read()
params = {}
for line in data.split("\n"):
smallstat = re.match(r"\s?Reading:\s(.*)\sWriting:\s(.*)\sWaiting:\s(.*)$", line)
req = re.match(r"\s+(\d+)\s+(\d+)\s+(\d+)", line)
if smallstat:
params["Reading"] = smallstat.group(1)
params["Writing"] = smallstat.group(2)
params["Waiting"] = smallstat.group(3)
elif req:
params["Requests"] = req.group(3)
else:
pass
dataorder = [
"Active",
"Reading",
"Writing",
"Waiting",
"Requests"
]
for param in dataorder:
if param == "Active":
Active = int(params["Reading"]) + int(params["Writing"]) + int(params["Waiting"])
print Active
else:
print params[param]