From 97ab640be8dc9e75b097f3b436cc7c95ceb91f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20de=20Kock?= Date: Tue, 3 Oct 2017 08:27:04 +0200 Subject: [PATCH 1/6] Change commit and rollback types to "COUNTER" By doing this, munin knows to take the difference of each request, thereby showing you a true commit and rollback "per minute" --- plugins/postgresql/postgresql_transactions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/postgresql/postgresql_transactions b/plugins/postgresql/postgresql_transactions index f13740a5..d5d68a0c 100755 --- a/plugins/postgresql/postgresql_transactions +++ b/plugins/postgresql/postgresql_transactions @@ -33,10 +33,12 @@ if [ "$1" = "config" ]; then echo 'commits.label commits' echo 'commits.min 0' + echo 'commits.type COUNTER' echo 'commits.info Number of transaction commits.' echo 'rollbacks.label rollbacks' echo 'rollbacks.min 0' + echo 'rollbacks.type COUNTER' echo 'rollbacks.info Number of transaction rollbacks.' exit 0 fi From 93a567afbc2bd79ce19863344317d91489161bf5 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 10 Jun 2018 13:54:35 +0200 Subject: [PATCH 2/6] postgresql_transactions: use DERIVE instead of COUNTER --- plugins/postgresql/postgresql_transactions | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/postgresql/postgresql_transactions b/plugins/postgresql/postgresql_transactions index d5d68a0c..c127e633 100755 --- a/plugins/postgresql/postgresql_transactions +++ b/plugins/postgresql/postgresql_transactions @@ -29,17 +29,17 @@ if [ "$1" = "config" ]; then echo 'graph_category db' echo 'graph_info Shows summarized commits and rollbacks in transactions on the PostgreSQL Server.' echo 'graph_title PostgreSQL Transactions' - echo 'graph_vlabel Number of Commits and Rollbacks' + echo 'graph_vlabel Commits and Rollbacks per second' echo 'commits.label commits' echo 'commits.min 0' - echo 'commits.type COUNTER' - echo 'commits.info Number of transaction commits.' + echo 'commits.type DERIVE' + echo 'commits.info Number of transaction commits per second.' echo 'rollbacks.label rollbacks' echo 'rollbacks.min 0' - echo 'rollbacks.type COUNTER' - echo 'rollbacks.info Number of transaction rollbacks.' + echo 'rollbacks.type DERIVE' + echo 'rollbacks.info Number of transaction rollbacks per second.' exit 0 fi psql -h ${dbserver} -U ${dbuser} -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align From fdf6cea2b146233d8b5f4b3fbbb123a12a85d71b Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 10 Jun 2018 13:56:07 +0200 Subject: [PATCH 3/6] postgresql_transactions: change from bash to sh; fix shellcheck issues --- plugins/postgresql/postgresql_transactions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/postgresql/postgresql_transactions b/plugins/postgresql/postgresql_transactions index c127e633..47db7b64 100755 --- a/plugins/postgresql/postgresql_transactions +++ b/plugins/postgresql/postgresql_transactions @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Plugin to monitor PostgreSQL Commits and Rollbacks in Transactions # @@ -42,4 +42,4 @@ if [ "$1" = "config" ]; then echo 'rollbacks.info Number of transaction rollbacks per second.' exit 0 fi -psql -h ${dbserver} -U ${dbuser} -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align +psql -h "$dbserver" -U "$dbuser" -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align From 154cef14c57f9ae424995b59fda2c08c0fd7de37 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 10 Jun 2018 13:58:31 +0200 Subject: [PATCH 4/6] postgresql_transactions: add support for DIRTYCONFIG --- plugins/postgresql/postgresql_transactions | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/postgresql/postgresql_transactions b/plugins/postgresql/postgresql_transactions index 47db7b64..e21708ab 100755 --- a/plugins/postgresql/postgresql_transactions +++ b/plugins/postgresql/postgresql_transactions @@ -24,7 +24,8 @@ dbserver='localhost' dbuser='postgres' -if [ "$1" = "config" ]; then + +do_config() { echo 'graph_args --base 1000 --lower-limit 0' echo 'graph_category db' echo 'graph_info Shows summarized commits and rollbacks in transactions on the PostgreSQL Server.' @@ -40,6 +41,17 @@ if [ "$1" = "config" ]; then echo 'rollbacks.min 0' echo 'rollbacks.type DERIVE' echo 'rollbacks.info Number of transaction rollbacks per second.' - exit 0 +} + + +do_fetch() { + psql -h "$dbserver" -U "$dbuser" -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align +} + + +if [ "$1" = "config" ]; then + do_config + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then do_fetch; fi +else + do_fetch fi -psql -h "$dbserver" -U "$dbuser" -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align From 3c10c360cd2e4282886e1a2b88b5e58df55a0b18 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 10 Jun 2018 14:06:30 +0200 Subject: [PATCH 5/6] postgresql_transactions: configurable host and user --- plugins/postgresql/postgresql_transactions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/postgresql/postgresql_transactions b/plugins/postgresql/postgresql_transactions index e21708ab..82e01619 100755 --- a/plugins/postgresql/postgresql_transactions +++ b/plugins/postgresql/postgresql_transactions @@ -21,8 +21,8 @@ # Log info: # -dbserver='localhost' -dbuser='postgres' +dbhost=${dbhost:-localhost} +dbuser=${dbuser:-postgres} do_config() { @@ -45,7 +45,7 @@ do_config() { do_fetch() { - psql -h "$dbserver" -U "$dbuser" -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align + psql -h "$dbhost" -U "$dbuser" -tc "SELECT 'commits.value '||SUM(xact_commit)::TEXT||E'\\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;" --no-align } From e93a46bc76df5a94e66f196212334d7bc4d0b84e Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 10 Jun 2018 14:06:48 +0200 Subject: [PATCH 6/6] postgresql_transactions: use perldoc documentation header --- plugins/postgresql/postgresql_transactions | 56 ++++++++++++++-------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/plugins/postgresql/postgresql_transactions b/plugins/postgresql/postgresql_transactions index 82e01619..894a9aab 100755 --- a/plugins/postgresql/postgresql_transactions +++ b/plugins/postgresql/postgresql_transactions @@ -1,25 +1,39 @@ #!/bin/sh -# -# Plugin to monitor PostgreSQL Commits and Rollbacks in Transactions -# -# Author: -# Guilherme Augusto da Rocha Silva -# -# Created: -# 9th of november 2007 -# -# Usage: -# Place in /etc/munin/plugins/ (or link it there using ln -s) -# -# Parameters: -# config (required) -# -# General info: -# Require permission for database access and read (no writes are processed). -# Recommended user is PostgreSQL database owner (default: postgres). -# -# Log info: -# + +: <<=cut + +=head1 NAME + +postgresql_transactions - Plugin to monitor PostgreSQL Commits and Rollbacks in Transactions + + +=head1 USAGE + +Usage: + Place in /etc/munin/plugins/ (or link it there using ln -s) + +General info: + Requires permission for database read access (no writes are processed). + Recommended user is PostgreSQL database owner (default: postgres). + + +=head1 CONFIGURATION + +The following configuration directives may be placed below /etc/munin/plugin-conf.d/ (optional): + + [postgresql_transactions] + user postgres + env.dbuser postgres + env.dbhost localhost + + +=head1 AUTHOR + + Guilherme Augusto da Rocha Silva + + Copyright (C) 2007 Guilherme Augusto da Rocha Silva + +=cut dbhost=${dbhost:-localhost} dbuser=${dbuser:-postgres}