feature: Add Postgres application support (#6004)

This commit is contained in:
VVelox
2017-03-01 23:46:03 +00:00
committed by Neil Lathwood
parent a2599115de
commit de6b1d9722
9 changed files with 337 additions and 0 deletions
+24
View File
@@ -29,6 +29,7 @@ Different applications support a variety of ways collect data: by direct connect
1. [Munin](#munin) - Agent
1. [PHP-FPM](#php-fpm) - SNMP extend
1. [Fail2ban](#fail2ban) - SNMP extend
1. [Postgres](#postgres) - SNMP extend
1. [Postfix](#postfix) - SNMP extend
### Apache
@@ -520,6 +521,29 @@ In regards to the totals graphed there are two variables banned and firewalled.
If you have more than a few jails configured, you may need to use caching as each jail needs to be polled and fail2ban-client can't do so in a timely manner for than a few. This can result in failure of other SNMP information being polled.
#### Postgres
##### SNMP Extend
1: Copy the shell script, postgres, to the desired host (the host must be added to LibreNMS devices) (wget https://github.com/librenms/librenms-agent/raw/master/snmp/postgres -O /etc/snmp/postgres)
2: Make the script executable (chmod +x /etc/snmp/postgres)
3: Edit your snmpd.conf file and add:
```
extend postgres /etc/snmp/postgres
```
4: Restart snmpd on your host
5: Install the Nagios check check_postgres.pl on your system.
6: Verify the path to check_postgres.pl in /etc/snmp/postgres is correct.
7: If you wish it to ignore the database postgres for totalling up the stats, set ignorePG to 1(the default) in /etc/snmp/postgres. If you are using netdata or the like, you may wish to set this or otherwise that total will be very skewed on systems with light or moderate usage.
8: On the device page in Librenms, edit your host and check `Postgres` under the Applications tab.
#### Postfix
##### SNMP Extend
@@ -0,0 +1,30 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
$scale_min = 0;
$colours = 'mixed';
$unit_text = '';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
if (is_file($rrd_filename)) {
$rrd_list = array(
array(
'filename' => $rrd_filename,
'descr' => 'Backends',
'ds' => 'backends',
'colour' => '582A72'
)
);
} else {
echo "file missing: $rrd_filename";
}
require 'includes/graphs/generic_multi_line_exact_numbers.inc.php';
@@ -0,0 +1,36 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
$scale_min = 0;
$colours = 'mixed';
$unit_text = 'Per Second';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
if (is_file($rrd_filename)) {
$rrd_list = array(
array(
'filename' => $rrd_filename,
'descr' => 'Rollbacks',
'ds' => 'rollbacks',
'colour' => '28774F'
),
array(
'filename' => $rrd_filename,
'descr' => 'Commits',
'ds' => 'commits',
'colour' => '28774F'
)
);
} else {
echo "file missing: $rrd_filename";
}
require 'includes/graphs/generic_v3_multiline.inc.php';
@@ -0,0 +1,37 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
$scale_min = 0;
$colours = 'mixed';
$unit_text = 'Per Second';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
if (is_file($rrd_filename)) {
$rrd_list = array(
array(
'filename' => $rrd_filename,
'descr' => 'Blocks Read',
'ds' => 'read',
'colour' => 'AA5439'
),
array(
'filename' => $rrd_filename,
'descr' => 'Buffer Hits',
'ds' => 'hit',
'colour' => '28774F'
)
);
} else {
echo "file missing: $rrd_filename";
}
require 'includes/graphs/generic_v3_multiline.inc.php';
@@ -0,0 +1,54 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
$scale_min = 0;
$colours = 'mixed';
$unit_text = 'Rows/Sec';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
if (is_file($rrd_filename)) {
$rrd_list = array(
array(
'filename' => $rrd_filename,
'descr' => 'Scans',
'ds' => 'idxscan',
'colour' => '582A72'
),
array(
'filename' => $rrd_filename,
'descr' => 'Tuples Read',
'ds' => 'idxtupread',
'colour' => 'AA6C39'
),
array(
'filename' => $rrd_filename,
'descr' => 'Tuples Fetched',
'ds' => 'idxtupfetch',
'colour' => 'FFD1AA'
),
array(
'filename' => $rrd_filename,
'descr' => 'Blocks Read',
'ds' => 'idxblksread',
'colour' => '88CC88'
),
array(
'filename' => $rrd_filename,
'descr' => 'Buffer Hits',
'ds' => 'idxblkshit',
'colour' => '28536C'
)
);
} else {
echo "file missing: $rrd_filename";
}
require 'includes/graphs/generic_v3_multiline.inc.php';
@@ -0,0 +1,54 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
$scale_min = 0;
$colours = 'mixed';
$unit_text = 'Rows/Sec';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
if (is_file($rrd_filename)) {
$rrd_list = array(
array(
'filename' => $rrd_filename,
'descr' => 'Returned',
'ds' => 'ret',
'colour' => '582A72'
),
array(
'filename' => $rrd_filename,
'descr' => 'Fetched',
'ds' => 'fetch',
'colour' => 'AA6C39'
),
array(
'filename' => $rrd_filename,
'descr' => 'Inserted',
'ds' => 'ins',
'colour' => 'FFD1AA'
),
array(
'filename' => $rrd_filename,
'descr' => 'Updated',
'ds' => 'upd',
'colour' => '88CC88'
),
array(
'filename' => $rrd_filename,
'descr' => 'Deleted',
'ds' => 'del',
'colour' => '28536C'
)
);
} else {
echo "file missing: $rrd_filename";
}
require 'includes/graphs/generic_v3_multiline.inc.php';
@@ -0,0 +1,36 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
$scale_min = 0;
$colours = 'mixed';
$unit_text = 'Rows/Sec';
$unitlen = 10;
$bigdescrlen = 15;
$smalldescrlen = 15;
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
if (is_file($rrd_filename)) {
$rrd_list = array(
array(
'filename' => $rrd_filename,
'descr' => 'Scans',
'ds' => 'seqscan',
'colour' => '582A72'
),
array(
'filename' => $rrd_filename,
'descr' => 'Tuples Read',
'ds' => 'seqtupread',
'colour' => '28536C'
)
);
} else {
echo "file missing: $rrd_filename";
}
require 'includes/graphs/generic_v3_multiline.inc.php';
+9
View File
@@ -65,6 +65,15 @@ $graphs['tinydns'] = array(
'other',
);
$graphs['postgres'] = array(
'backends',
'cr',
'rows',
'hr',
'index',
'sequential'
);
$graphs['powerdns'] = array(
'latency',
'fail',
@@ -0,0 +1,57 @@
<?php
$name = 'postgres';
$app_id = $app['app_id'];
use LibreNMS\RRD\RrdDefinition;
$options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutputFull.8.112.111.115.116.103.114.101.115';
$postgres = snmp_walk($device, $oid, $options, $mib);
list($backends, $commits, $rollbacks, $read, $hit, $idxscan, $idxtupread, $idxtupfetch, $idxblksread,
$idxblkshit, $seqscan, $seqtupread, $ret, $fetch, $ins, $upd, $del) = explode("\n", $postgres);
$rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()
->addDataset('backends', 'GAUGE', 0)
->addDataset('commits', 'DERIVE', 0)
->addDataset('rollbacks', 'DERIVE', 0)
->addDataset('read', 'DERIVE', 0)
->addDataset('hit', 'DERIVE', 0)
->addDataset('idxscan', 'DERIVE', 0)
->addDataset('idxtupread', 'DERIVE', 0)
->addDataset('idxtupfetch', 'DERIVE', 0)
->addDataset('idxblksread', 'DERIVE', 0)
->addDataset('idxblkshit', 'DERIVE', 0)
->addDataset('seqscan', 'DERIVE', 0)
->addDataset('seqtupread', 'DERIVE', 0)
->addDataset('ret', 'DERIVE', 0)
->addDataset('fetch', 'DERIVE', 0)
->addDataset('ins', 'DERIVE', 0)
->addDataset('upd', 'DERIVE', 0)
->addDataset('del', 'DERIVE', 0);
$fields = array(
'backends' => $backends,
'commits' => $commits,
'rollbacks' => $rollbacks,
'read' => $read,
'hit' => $hit,
'idxscan' => $idxscan,
'idxtupread' => $idxtupread,
'idxtupfetch' => $idxtupfetch,
'idxblksread' => $idxblksread,
'idxblkshit' => $idxblkshit,
'seqscan' => $seqscan,
'seqtupread' => $seqtupread,
'ret' => $ret,
'fetch' => $fetch,
'ins' => $ins,
'upd' => $upd,
'del' => $del
);
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);