Skip to content
Snippets Groups Projects
Commit e6b83d1b authored by Jelle van der Waa's avatar Jelle van der Waa :construction:
Browse files

Add postgresql performance metrics monitoring

parent ac3fc8c8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
use JSON;
my $mode = $ARGV[0];
my $dbname = $ARGV[1];
if (!($mode eq "userstat" or $mode eq "discover")) {
print STDERR "mode is not userstat or discover\n";
die;
}
if ($mode eq "userstat" and not defined $dbname) {
print STDERR "userstat requires dbname to be defined\n";
die;
}
my $db = DBI->connect("DBI:Pg:");
if ($mode eq "userstat") {
print encode_json($db->selectrow_hashref("SELECT tup_fetched,tup_returned,tup_inserted,tup_deleted,tup_updated,numbackends,deadlocks from pg_stat_database where datname = ?;", undef, $dbname));
} elsif ($mode eq "discover") {
print encode_json({
data => $db->selectall_arrayref("SELECT datname \"{#DATNAME}\" FROM pg_database;", {Slice => {}})
});
} else {
die "unhandled mode";
}
......@@ -82,6 +82,7 @@
- zabbix-borg-timestamps.pl
- mysql-dbsize-stats.pl
- postgresql-dbsize-stats.pl
- postgresql-user-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
zabbix-agent ALL=(postgres) NOPASSWD: /usr/local/bin/postgresql-dbsize-stats.pl, /usr/local/bin/postgresql-user-stats.pl
......@@ -20,6 +20,9 @@ UserParameter=mysql.dbsize_discover,sudo /usr/local/bin/mysql-dbsize-stats.pl "/
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=postgresql.userstats[*],sudo -u postgres /usr/local/bin/postgresql-dbsize-user-stats.pl userstat '$1'
UserParameter=postgresql.userstats_discover,sudo -u postgres /usr/local/bin/postgresql-user-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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment