root / plugins / postgresql / slony_lag_time @ 17f78427
Historique | Voir | Annoter | Télécharger (2,62 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
# plugin to monitor difference between st_last_event_ts and st_last_received_ts |
| 4 |
# in sl_status table (based on slony_ and slony_lag_) |
| 5 |
# |
| 6 |
# http://blog.endpoint.com/2009/07/slony-slstatus-and-diagnosing.html |
| 7 |
# |
| 8 |
# st_origin: the local slony system |
| 9 |
# st_received: the slony instance that sent an event |
| 10 |
# st_last_event: the sequence number of the last event received from that origin/received pair |
| 11 |
# st_last_event_ts: the timestamp on the last event received |
| 12 |
# st_last_received: the sequence number of the last sl_event + sl_confirm pair received |
| 13 |
# st_last_received_ts: the timestamp on the sl_confirm in that pair |
| 14 |
# st_last_received_event_ts: the timestamp on the sl_event in that pair |
| 15 |
# st_lag_num_events: difference between st_last_event and st_last_received |
| 16 |
# st_lag_time: difference between st_last_event_ts and st_last_received_ts |
| 17 |
# |
| 18 |
# |
| 19 |
# Configuration variables: |
| 20 |
# |
| 21 |
# PGHOST - Database server to use. |
| 22 |
# PGUSER - User to connect as. |
| 23 |
# PGPASSWORD - Password to use. |
| 24 |
# PGSCHEMA - Replication schema. |
| 25 |
# |
| 26 |
# Configuration example: |
| 27 |
# |
| 28 |
# munin-node: |
| 29 |
# |
| 30 |
# [slony*] |
| 31 |
# user slony |
| 32 |
# env.PGHOST localhost |
| 33 |
# env.PGUSER slony |
| 34 |
# env.PGPASSWORD password |
| 35 |
# env.PGSCHEMA _slony |
| 36 |
# |
| 37 |
# postgresql.conf: |
| 38 |
# |
| 39 |
# standard_conforming_strings = on |
| 40 |
# |
| 41 |
# ln -s /usr/share/munin/plugins/slony_lag_time_/etc/munin/plugins/slony_lag_time_PGDATABASE |
| 42 |
# |
| 43 |
# |
| 44 |
# Magic markers (optional - only used by munin-config and some installation scripts): |
| 45 |
#%# family=contrib |
| 46 |
|
| 47 |
|
| 48 |
PGDATABASE=$(basename $0 | sed 's/^slony_lag_time_//g') |
| 49 |
|
| 50 |
if [ "$1" = "config" ]; then |
| 51 |
echo "graph_args --base 1000 -l 0" |
| 52 |
echo "graph_category db" |
| 53 |
echo "graph_info Slony st_lag_time for ${PGDATABASE}"
|
| 54 |
echo "graph_title Slony lag time for ${PGDATABASE}"
|
| 55 |
echo "graph_vlabel \${graph_period}"
|
| 56 |
|
| 57 |
psql -h ${PGHOST} -d ${PGDATABASE} -U ${PGUSER} -tc "SELECT no_id,regexp_replace(pa_conninfo, '.*host=(.*?) .*$', '\\\\1') FROM ${PGSCHEMA}.sl_node JOIN ${PGSCHEMA}.sl_path ON (pa_server=no_id) WHERE pa_client=${PGSCHEMA}.getlocalnodeid('${PGSCHEMA}'::name);" | while read node_id sep host
|
| 58 |
do |
| 59 |
test -z "${node_id}" && continue
|
| 60 |
echo "${node_id}.label ${host}"
|
| 61 |
echo "${node_id}.type GAUGE"
|
| 62 |
echo "${node_id}.draw LINE2"
|
| 63 |
echo "${node_id}.info difference between st_last_event_ts and st_last_received_ts"
|
| 64 |
echo "${node_id}.warning 300"
|
| 65 |
echo "${node_id}.critical 600"
|
| 66 |
done |
| 67 |
exit 0 |
| 68 |
fi |
| 69 |
|
| 70 |
psql -h ${PGHOST} -d ${PGDATABASE} -U ${PGUSER} -tc "SELECT st_received, extract(epoch FROM st_lag_time)::integer FROM ${PGSCHEMA}.sl_status ORDER BY 1;" | while read node_id sep time
|
| 71 |
do |
| 72 |
test -z "${node_id}" && continue
|
| 73 |
echo "${node_id}.value ${time}"
|
| 74 |
done |
