PostgreSQL 监控脚本[from zabbix.org]
2012-05-31 18:53
417 查看
zabbix是一个非常好的监控平台软件,通过编写被监控目标的脚步实现对目标的监控。
下面是PostgreSQL的一个监控脚步:(可以在此基础之上进行修改)
原文地址
http://www.zabbix.com/forum/showthread.php?t=8009
#! /bin/bash
#
# Name: zapost
#
# Checks PostgreSQL activity.
#
# Author: bashman
#
# Version: 1.0
#
zapostver="1.0"
rval=0
sql=""
case $1 in
#'summary')
# sql="select a.datname, pg_size_pretty(pg_database_size(a.datid)) as size, cast(blks_hit/(blks_read+blks_hit+0.000001)*100.0 as numeric(5,2)) as cache, cast(xact_commit/(xact_rollback+xact_commit+0.000001)*100.0 as numeric(5,2)) as success from pg_stat_database
a order by a.datname"
# ;;
#'size')
#comprobar aqui los parametros
# shift
# sql="select pg_database_size('$1') as size"
# ;;
#'version')
# sql='select version()'
# ;;
'totalsize')
sql="select sum(pg_database_size(datid)) as total_size from pg_stat_database"
;;
'db_cache')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select cast(blks_hit/(blks_read+blks_hit+0.000001)*100.0 as numeric(5,2)) as cache from pg_stat_database where datname = '$1'"
fi
;;
'db_success')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select cast(xact_commit/(xact_rollback+xact_commit+0.000001)*100.0 as numeric(5,2)) as success from pg_stat_database where datname = '$1'"
fi
;;
'server_processes')
sql="select sum(numbackends) from pg_stat_database"
;;
'tx_commited')
sql="select sum(xact_commit) from pg_stat_database"
;;
'tx_rolledback')
sql="select sum(xact_rollback) from pg_stat_database"
;;
'db_size')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select pg_database_size('$1')" #as size"
fi
;;
'db_connections')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select numbackends from pg_stat_database where datname = '$1'"
fi
;;
'db_returned')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_returned from pg_stat_database where datname = '$1'"
fi
;;
'db_fetched')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_fetched from pg_stat_database where datname = '$1'"
fi
;;
'db_inserted')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_inserted from pg_stat_database where datname = '$1'"
fi
;;
'db_updated')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_updated from pg_stat_database where datname = '$1'"
fi
;;
'db_deleted')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_deleted from pg_stat_database where datname = '$1'"
fi
;;
'db_commited')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select xact_commit from pg_stat_database where datname = '$1'"
fi
;;
'db_rolled')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select xact_rollback from pg_stat_database where datname = '$1'"
fi
;;
'version')
sql="version"
;;
'zapostver')
echo "$zapostver"
exit $rval
;;
*)
echo "zapost version: $zapostver"
echo "usage:"
echo " $0 total size -- Check the total databases size."
echo " $0 db_cache <dbname> -- Check the database cache hit ratio (percentage)."
echo " $0 db_success <dbname> -- Check the database success rate (percentage)."
echo " $0 server_processes -- Check the total number of Server Processes that are active."
echo " $0 tx_commited -- Check the total number of commited transactions."
echo " $0 tx_rolledback -- Check the total number of rolled back transactions."
echo " $0 db_size <dbname> -- Check the size of a Database (in bytes)."
echo " $0 db_connections <dbname> -- Check the number of active connections for a specified database."
echo " $0 db_returned <dbname> -- Check the number of tuples returned for a specified database."
echo " $0 db_fetched <dbname> -- Check the number of tuples fetched for a specified database."
echo " $0 db_inserted <dbname> -- Check the number of tuples inserted for a specified database."
echo " $0 db_updated <dbname> -- Check the number of tuples updated for a specified database."
echo " $0 db_deleted <dbname> -- Check the number of tuples deleted for a specified database."
echo " $0 db_commited <dbname> -- Check the number of commited back transactions for a specified database."
echo " $0 db_rolled <dbname> -- Check the number of rolled back transactions for a specified database."
echo " $0 version -- The PostgreSQL version."
echo " $0 zapostver -- Version of this script."
exit $rval
;;
esac
if [ "$sql" != "" ]; then
if [ "$sql" == "version" ]; then
psql --version|head -n1
rval=$?
else
psql -t -c "$sql"
rval=$?
fi
fi
if [ "$rval" -ne 0 ]; then
echo "ZBX_NOTSUPPORTED"
fi
exit $rval
#
# end zapost
下面是PostgreSQL的一个监控脚步:(可以在此基础之上进行修改)
原文地址
http://www.zabbix.com/forum/showthread.php?t=8009
#! /bin/bash
#
# Name: zapost
#
# Checks PostgreSQL activity.
#
# Author: bashman
#
# Version: 1.0
#
zapostver="1.0"
rval=0
sql=""
case $1 in
#'summary')
# sql="select a.datname, pg_size_pretty(pg_database_size(a.datid)) as size, cast(blks_hit/(blks_read+blks_hit+0.000001)*100.0 as numeric(5,2)) as cache, cast(xact_commit/(xact_rollback+xact_commit+0.000001)*100.0 as numeric(5,2)) as success from pg_stat_database
a order by a.datname"
# ;;
#'size')
#comprobar aqui los parametros
# shift
# sql="select pg_database_size('$1') as size"
# ;;
#'version')
# sql='select version()'
# ;;
'totalsize')
sql="select sum(pg_database_size(datid)) as total_size from pg_stat_database"
;;
'db_cache')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select cast(blks_hit/(blks_read+blks_hit+0.000001)*100.0 as numeric(5,2)) as cache from pg_stat_database where datname = '$1'"
fi
;;
'db_success')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select cast(xact_commit/(xact_rollback+xact_commit+0.000001)*100.0 as numeric(5,2)) as success from pg_stat_database where datname = '$1'"
fi
;;
'server_processes')
sql="select sum(numbackends) from pg_stat_database"
;;
'tx_commited')
sql="select sum(xact_commit) from pg_stat_database"
;;
'tx_rolledback')
sql="select sum(xact_rollback) from pg_stat_database"
;;
'db_size')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select pg_database_size('$1')" #as size"
fi
;;
'db_connections')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select numbackends from pg_stat_database where datname = '$1'"
fi
;;
'db_returned')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_returned from pg_stat_database where datname = '$1'"
fi
;;
'db_fetched')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_fetched from pg_stat_database where datname = '$1'"
fi
;;
'db_inserted')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_inserted from pg_stat_database where datname = '$1'"
fi
;;
'db_updated')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_updated from pg_stat_database where datname = '$1'"
fi
;;
'db_deleted')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select tup_deleted from pg_stat_database where datname = '$1'"
fi
;;
'db_commited')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select xact_commit from pg_stat_database where datname = '$1'"
fi
;;
'db_rolled')
# comprueba los parametros
if [ ! -z $2 ]; then
shift
sql="select xact_rollback from pg_stat_database where datname = '$1'"
fi
;;
'version')
sql="version"
;;
'zapostver')
echo "$zapostver"
exit $rval
;;
*)
echo "zapost version: $zapostver"
echo "usage:"
echo " $0 total size -- Check the total databases size."
echo " $0 db_cache <dbname> -- Check the database cache hit ratio (percentage)."
echo " $0 db_success <dbname> -- Check the database success rate (percentage)."
echo " $0 server_processes -- Check the total number of Server Processes that are active."
echo " $0 tx_commited -- Check the total number of commited transactions."
echo " $0 tx_rolledback -- Check the total number of rolled back transactions."
echo " $0 db_size <dbname> -- Check the size of a Database (in bytes)."
echo " $0 db_connections <dbname> -- Check the number of active connections for a specified database."
echo " $0 db_returned <dbname> -- Check the number of tuples returned for a specified database."
echo " $0 db_fetched <dbname> -- Check the number of tuples fetched for a specified database."
echo " $0 db_inserted <dbname> -- Check the number of tuples inserted for a specified database."
echo " $0 db_updated <dbname> -- Check the number of tuples updated for a specified database."
echo " $0 db_deleted <dbname> -- Check the number of tuples deleted for a specified database."
echo " $0 db_commited <dbname> -- Check the number of commited back transactions for a specified database."
echo " $0 db_rolled <dbname> -- Check the number of rolled back transactions for a specified database."
echo " $0 version -- The PostgreSQL version."
echo " $0 zapostver -- Version of this script."
exit $rval
;;
esac
if [ "$sql" != "" ]; then
if [ "$sql" == "version" ]; then
psql --version|head -n1
rval=$?
else
psql -t -c "$sql"
rval=$?
fi
fi
if [ "$rval" -ne 0 ]; then
echo "ZBX_NOTSUPPORTED"
fi
exit $rval
#
# end zapost
相关文章推荐
- zabbix客户端一键安装脚本(主动模式监控)
- zabbix调用脚本监控 或者调用程序
- zabbix自定义监控脚本,显示权限不足
- zabbix通过自定义脚本监控nginx,php-fpm和mysql占用内存数和进程的个数
- zabbix增加手机短信、邮件监控的注意要点,SSL邮件发送python脚本
- Zabbix 监控Nginx_status 自动发现脚本
- 编写脚本实现Zabbix监控Nginx状态
- Python一键添加Zabbix监控脚本
- 使用Zabbix监控Mysql(FromDual)
- Zabbix Linux http 监控脚本
- 微信接收zabbix监控信息脚本
- zabbix trap 监控windows 服务器raid中个磁盘状态脚本
- python脚本监控redis制作zabbix模板
- zabbix通过orabbix和自定义脚本监控oracle数据库
- zabbix3.2监控Oracle11G数据脚本
- Zabbix监控Mysql数据库性能--脚本方式
- zabbix中通过shell脚本进行微信监控告警
- Zabbix监控PostgreSQL
- zabbix自定义监控脚本——获取tcp状态之不同命令的响应时间
- zabbix统一脚本监控方式