Commit c9eb2209 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

zabbix-agent: add PostgreSQL DB size monitoring

Add monitoring for our PostgreSQL DB size using a similiar construct as
the MySQL DB size monitoring with a perl script.
parent 0777baea
......@@ -30,6 +30,7 @@ zabbix_agent_templates:
- Template App SMTP Service
- Template App SSH Service
- Template App Zabbix Server
- Template App PostgreSQL
zabbix_agent_host_groups:
- Linux servers
......
......@@ -17,6 +17,7 @@ archweb_version: release_2018-11-23
zabbix_agent_templates:
- Template OS Linux
- Template App PostgreSQL
configure_firewall: true
ansible_python_interpreter: /usr/bin/python3.7
......@@ -15,6 +15,7 @@ zabbix_agent_templates:
- Template OS Linux
- Template App Borg Backup
- Template App Syncrepo
- Template App PostgreSQL
configure_firewall: true
......
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
use JSON;
my $mode = $ARGV[0];
my $dbname = $ARGV[1];
if (!($mode eq "dbsize" or $mode eq "discover")) {
print STDERR "mode is not dbsize or discover\n";
die;
}
if ($mode eq "dbsize" and not defined $dbname) {
print STDERR "dbsize requires dbname to be defined\n";
die;
}
my $db = DBI->connect("DBI:Pg:");
if ($mode eq "dbsize") {
print encode_json($db->selectrow_hashref("SELECT pg_database_size(?) AS dbsize;", undef, $dbname));
} elsif ($mode eq "discover") {
print encode_json({
data => $db->selectall_arrayref("SELECT datname \"{#DATNAME}\" FROM pg_database;", {Slice => {}})
});
} else {
die "unhandled mode";
}
......@@ -12,7 +12,7 @@
when: "'nginx' in group_names"
- name: install mysql userstats monitoring packages
pacman: name=perl-dbi,perl-dbd-mysql,perl-json
pacman: name=perl-dbi,perl-dbd-mysql,perl-dbd-pg,perl-json
when: "'mysql-servers' in group_names"
- file: path=/etc/zabbix state=directory owner=root group=root mode=755
......@@ -71,6 +71,7 @@
- systemd-discover-accounting-units.py
- zabbix-borg-timestamps.pl
- mysql-dbsize-stats.pl
- postgresql-dbsize-stats.pl
- name: Install helper scripts
copy: src=nginx-zabbix.pl dest=/usr/local/bin/nginx-zabbix.pl mode=0755 owner=root group=root
......
zabbix-agent ALL=(root) NOPASSWD: /usr/local/bin/borg list --json --format {start}{end} --sort-by timestamp --last 1, /usr/local/bin/mysql-dbsize-stats.pl
zabbix-agent ALL=(postgres) NOPASSWD: /usr/local/bin/postgresql-dbsize-stats.pl
......@@ -17,6 +17,9 @@ UserParameter=mysql.userstats_discover,/usr/local/bin/mysql-user-stats.pl "/etc/
UserParameter=mysql.dbsize[*],sudo /usr/local/bin/mysql-dbsize-stats.pl "/root/.my.cnf" dbsize '$1'
UserParameter=mysql.dbsize_discover,sudo /usr/local/bin/mysql-dbsize-stats.pl "/root/.my.cnf" discover
UserParameter=postgresql.dbsize[*],sudo -u postgres /usr/local/bin/postgresql-dbsize-stats.pl dbsize '$1'
UserParameter=postgresql.dbsize_discover,sudo -u postgres /usr/local/bin/postgresql-dbsize-stats.pl discover
UserParameter=systemd.unit.is-active[*],systemctl is-active --quiet '$1' && echo 1 || echo 0
UserParameter=systemd.unit.is-failed[*],systemctl is-failed --quiet '$1' && echo 1 || echo 0
UserParameter=systemd.unit.is-enabled[*],systemctl is-enabled --quiet '$1' && echo 1 || echo 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment