From de6b1d9722bf91195d123045d0a3deed442daa24 Mon Sep 17 00:00:00 2001 From: VVelox Date: Wed, 1 Mar 2017 17:46:03 -0600 Subject: [PATCH] feature: Add Postgres application support (#6004) --- doc/Extensions/Applications.md | 24 ++++++++ .../application/postgres_backends.inc.php | 30 ++++++++++ .../graphs/application/postgres_cr.inc.php | 36 ++++++++++++ .../graphs/application/postgres_hr.inc.php | 37 ++++++++++++ .../graphs/application/postgres_index.inc.php | 54 ++++++++++++++++++ .../graphs/application/postgres_rows.inc.php | 54 ++++++++++++++++++ .../application/postgres_sequential.inc.php | 36 ++++++++++++ html/pages/apps.inc.php | 9 +++ .../polling/applications/postgres.inc.php | 57 +++++++++++++++++++ 9 files changed, 337 insertions(+) create mode 100644 html/includes/graphs/application/postgres_backends.inc.php create mode 100644 html/includes/graphs/application/postgres_cr.inc.php create mode 100644 html/includes/graphs/application/postgres_hr.inc.php create mode 100644 html/includes/graphs/application/postgres_index.inc.php create mode 100644 html/includes/graphs/application/postgres_rows.inc.php create mode 100644 html/includes/graphs/application/postgres_sequential.inc.php create mode 100644 includes/polling/applications/postgres.inc.php diff --git a/doc/Extensions/Applications.md b/doc/Extensions/Applications.md index 309b155f04..138d37d479 100644 --- a/doc/Extensions/Applications.md +++ b/doc/Extensions/Applications.md @@ -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 diff --git a/html/includes/graphs/application/postgres_backends.inc.php b/html/includes/graphs/application/postgres_backends.inc.php new file mode 100644 index 0000000000..1ba4b2f59b --- /dev/null +++ b/html/includes/graphs/application/postgres_backends.inc.php @@ -0,0 +1,30 @@ + $rrd_filename, + 'descr' => 'Backends', + 'ds' => 'backends', + 'colour' => '582A72' + ) + ); +} else { + echo "file missing: $rrd_filename"; +} + +require 'includes/graphs/generic_multi_line_exact_numbers.inc.php'; diff --git a/html/includes/graphs/application/postgres_cr.inc.php b/html/includes/graphs/application/postgres_cr.inc.php new file mode 100644 index 0000000000..02429f9b69 --- /dev/null +++ b/html/includes/graphs/application/postgres_cr.inc.php @@ -0,0 +1,36 @@ + $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'; diff --git a/html/includes/graphs/application/postgres_hr.inc.php b/html/includes/graphs/application/postgres_hr.inc.php new file mode 100644 index 0000000000..c215874567 --- /dev/null +++ b/html/includes/graphs/application/postgres_hr.inc.php @@ -0,0 +1,37 @@ + $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'; diff --git a/html/includes/graphs/application/postgres_index.inc.php b/html/includes/graphs/application/postgres_index.inc.php new file mode 100644 index 0000000000..d6cdb85b1a --- /dev/null +++ b/html/includes/graphs/application/postgres_index.inc.php @@ -0,0 +1,54 @@ + $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'; diff --git a/html/includes/graphs/application/postgres_rows.inc.php b/html/includes/graphs/application/postgres_rows.inc.php new file mode 100644 index 0000000000..41c3a70aa4 --- /dev/null +++ b/html/includes/graphs/application/postgres_rows.inc.php @@ -0,0 +1,54 @@ + $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'; diff --git a/html/includes/graphs/application/postgres_sequential.inc.php b/html/includes/graphs/application/postgres_sequential.inc.php new file mode 100644 index 0000000000..5514d29316 --- /dev/null +++ b/html/includes/graphs/application/postgres_sequential.inc.php @@ -0,0 +1,36 @@ + $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'; diff --git a/html/pages/apps.inc.php b/html/pages/apps.inc.php index 1766918adc..045df040d9 100644 --- a/html/pages/apps.inc.php +++ b/html/pages/apps.inc.php @@ -65,6 +65,15 @@ $graphs['tinydns'] = array( 'other', ); +$graphs['postgres'] = array( + 'backends', + 'cr', + 'rows', + 'hr', + 'index', + 'sequential' +); + $graphs['powerdns'] = array( 'latency', 'fail', diff --git a/includes/polling/applications/postgres.inc.php b/includes/polling/applications/postgres.inc.php new file mode 100644 index 0000000000..3b72d449c1 --- /dev/null +++ b/includes/polling/applications/postgres.inc.php @@ -0,0 +1,57 @@ +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);