Module Munin pg_read_hits
Ce module Munin permet de suivre le nombre de blocs lus en cache et sur disque, sur l'ensemble des bases d'un serveur PostgreSQL.
Pour utiliser ce fichier, sauvegardez le sous le nom « pg_read_hits » dans le répertoire de vos modules Munin (« /etc/munin/plugins »).
# pg_read_hits: Munin plugin used to monitor the number of
# blocks read on disk and in cache of a PostgreSQL server
#
# pg_read_hits : module Munin de suivi du nombre de blocs
# lus sur disque et en cache d'un serveur PostgreSQL
#
# (c) 2007 Jean-Philippe Guérard
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Ce programme est un logiciel libre. Vous pouvez le redistribuer
# et le modifier selon les termes de la Licence publique générale
# GNU (GPL) version 2 ou supérieure, telle que publiée par la Free
# Software Foundation.
#
# Ce programme est distribué dans l'espoir qu'il se révélera
# utile, mais sans aucune garantie, ni explicite ni implicite,
# y compris les garanties de commercialisation ou d'adaptation
# à un but spécifique. Reportez-vous à la Licence Publique
# Générale GNU pour plus d'informations.
# Installation
# To use this plugin, you need to add the following
# 2 lines to the plugin configuration file:
#
# Pour utiliser ce module, ajoutez les deux lignes
# ci-dessous à votre fichier de paramétrage des
# modules Munin :
#
# [pg_read_hits]
# user postgres
#
PATH=/usr/bin:/bin
# Display plugin config if requested
if [ "${1}" = "config" ] ; then
cat <<'FDT'
graph_title PostgreSQL cache hits and disk read
graph_args --base 1000 -l 0
graph_category PostgreSQL
graph_vlabel blocks
graph_info PostgreSQL nomber of blocks read on disk and cache hits
disk_read.info Number of blocks read on disk
disk_read.label disk_read
disk_read.type DERIVE
cache_hits.info Number of blocks read in cache
cache_hits.label cache_hits
cache_hits.type DERIVE
FDT
exit 0
fi
# Database request
READ_HIT=$(psql -A -t \
-c "select sum(blks_read),sum(blks_hit) \
from pg_stat_database where datname \
not in ('postgres','template0','template1') ;" postgres)
# Display total blocks read count
READ=$(echo "${READ_HIT}" | gawk -F "|" '{print $1}')
echo "disk_read.value ${READ}"
# Display total cache hits count
HIT=$(echo "${READ_HIT}" | gawk -F "|" '{print $2}')
echo "cache_hits.value ${HIT}"
exit 0