PGQ Munin 插件
来自 PostgreSQL 维基
跳转到导航跳转到搜索指标
PGQ 提供延迟和 last_seen 指标。
- 延迟
- 给定消费者处理下一个事件的年龄
- last_seen
- 消费者最后一次请求工作 (next_batch()) 的时间
代码
维基媒体软件没有设置为接受文本文件上传,所以这里就是它的内容
#!/bin/bash
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#
#%# family=auto
#%# capabilities=autoconf suggest
#
prog=$(basename $0)
dbname=$(echo $prog | cut -d_ -f 2- | cut -d. -f1)
queue=$(echo $prog | cut -d_ -f 2- | cut -d. -f2)
psql="psql -At"
[ ! -z "$dbhost" ] && psql="$psql -h $dbhost"
[ ! -z "$dbport" ] && psql="$psql -p $dbport"
[ ! -z "$dbuser" ] && psql="$psql -U postgres"
case "$1" in
config)
echo "graph_category pgq"
echo "graph_title PgQ $dbname $queue consumer lag"
echo "graph_vlabel seconds"
echo "graph_args --lower-limit 1 --base 1000 --logarithmic"
echo "graph_info Shows Pgq Lag "
select="SELECT consumer_name FROM pgq.get_consumer_info('$queue');"
while read consumer
do
consumer=$(echo $consumer | tr .- __)
echo ${consumer}_lag.label $consumer lag
echo ${consumer}_lag.type GAUGE
echo ${consumer}_lag.draw LINE
echo ${consumer}_last_seen.label $consumer last seen
echo ${consumer}_last_seen.type GAUGE
echo ${consumer}_last_seen.draw LINE
done < <($psql $dbname -c "$select" 2>/dev/null)
exit 0
;;
autoconf)
sql="SELECT DISTINCT(queue_name) FROM pgq.get_consumer_info();"
working=false
for db in $($psql -Alt 2>/dev/null | cut -d\| -f1)
do
for queue in `$psql $db -c "$sql" 2>/dev/null`
do
working=true
done
done
if [ $working = 'true' ]
then
echo yes
exit 0
else
echo no
exit 1
fi
;;
suggest)
sql="SELECT DISTINCT(queue_name) FROM pgq.get_consumer_info();"
coderetour=1
for db in $($psql -Alt 2>/dev/null | cut -d\| -f1)
do
for queue in `$psql $db -c "$sql" 2>/dev/null`
do
echo $db.$queue
coderetour=0
done
done
exit $coderetour
;;
esac
sql="SELECT consumer_name, EXTRACT(epoch from lag) AS lag, \
EXTRACT(epoch FROM last_seen) AS last_seen \
FROM pgq.get_consumer_info('$queue');"
while read consumer lag last_seen
do
consumer=$(echo $consumer | tr .- __)
echo ${consumer}_lag.value $lag
echo ${consumer}_last_seen.value $last_seen
done < <($psql $dbname -F ' ' -c "$sql" 2>/dev/null)
安装
将文件放在 /usr/share/munin/plugins 或其他文档化位置,然后运行
/usr/sbin/munin-node-configure --shell
该命令将根据您的配置为您提供必要的 ln -s 命令来运行,以安装插件。您需要在托管 PostgreSQL 数据库的服务器上运行此命令,该数据库托管 PGQ 队列。