PostgreSQL的监控二(pgwatch & pg_statsinfo)
2.3 pgwatch
http://www.cybertec.at/postgresql_produkte/pgwatch-cybertec-enterprise-postgresql-monitor/
主要特性:
- 配置简单
- 大量的监控图表
-
快速系统检查面板
-
自动收集
统计信息
- 交互式的 Flash 图表
- 集成
sql worksheet
pgwatch的监控画面
pgwatch是个
PHP做的web管理控制台,
后台存储使用Postgre
sql数据库,其工作的原理是利用cron定期经由dblink采集远程
数据库性能数据,并以图形的形式
显示。使用
方法也很简单,只要把pgwatch配到Apache上,第一次访问的时候进入setup.
PHP,引导设置pgwatch使用的
后台数据库。然后再配置定期
调用采集数据脚本的daemon,再在配置
页面里填上监控目标机器的连接信息就可以了。
- Requirements:
-------------
You will need a handful of components to make this work:
- Apache (webserver)
- PHP 5 (scripting language)
- pgsql extension for PHP (see http://www.PHP.net/manual/en/book.pgsql.PHP)
- Postgresql 9 (to store the data we collect)
- dblink (contribution module for Postgresql 9)
- For now we only support Postgresql >= 9.0 databases.
Older systems cannot be monitored,however,we will
add support for future database releases.
How to set it up:
-----------------
- Extract your package to your Apache directory
- Adjust ownership of your application if www-data is improper
- Open in browser the setup.PHP. It will lead you through the setup process.
- You can choose setup.sh in linux and setup.bat in windows as alternatives.
- Start the data collection daemon by adding the proper row to cron,something like:
0 * * * * cd /var/www/pgwatch/util && /usr/bin/PHP5 getraw_d.PHP
(But setup.sh will also remind you of it)
- Log into the website and click "configure" to add new database servers
/ databases to make sure that your daemon will pick up the statistics.
然而实际配置时发现,收集数据的地方出错。
[root@zabbix util]#/usr/bin/PHP getraw_d.PHP
256:pgwatch_xml:given parameter isnota valid xml.in/var/www/html/pgwatch/classes/pgwatch_xml.PHP(18)<br/>
重试了2次,还是一样的
错误,也懒得再折腾了。不过下面这位兄弟配成功了。
http://www.linuxidc.com/Linux/2012-11/74515.htm
pgwatch的优点是可以监控多个
数据库,并且不需要在被监控
数据库上作任何设置。但pgwatch的界面有点丑,监控项目不多,更新也慢(pgwatch最新一次更新是2011年)。
2.4 pg_statsinfo
http://pgstatsinfo.projects.pgfoundry.org/
pg_statsinfo的
功能比较全面。pg_statsinfo在被监控DB上以代理的形式存在,pg_statsinfo定期采集snaoshot信息并存入仓库。仓库可以在相同的
数据库也可以在远程,在远程的话可以使用同一个仓库存放多个被监控
数据库的信息。pg_statsinfo不仅采集
数据库中系统表,还采集OS(
cpu,MEM,IO)信息.甚至还可以从Postgre
sql日志中抽取
性能数据。pg_statsinfo还可以报警,当某个监控项超出预定义的阈值时,pg_statsinfo会在日志中产生ALERT消息,配合其它可以监视日志的监控软件(比如zabbix)就可以实现告警。
http://pgstatsinfo.projects.pgfoundry.org/pg_statsinfo.html
------------------------------------------------------------------------------------------------------
pic1: Example of system installed with pg_statsinfo
pic2: Image of Functionary in pg_statsinfo
Statistics Snapshot
pg_statsinfo gathers statistics periodically and stores them as snapshots into a repository database. The repository can be in the same database with the monitored instance or in another instance. Also,one repository can store snapshots from multiple monitored instances.
- Snapshots are gathered periodically (default: every 10 minutes) or by manual.
- An event handler function is called after every snapshots taken. The function can be defined by users. A new snapshot can be compared with prevIoUs snapshots and raise alert messages in the function.
Snapshot holds the following statistics information:
- All of the information collected bythe statistics collector. For example,numbers of INSERT/UPDATE/DELETE and buffer access counters.
- Disk usages of each tablespace,pg_xlog,and archive log directory.
- Long transactions and their query strings.
- Process status in running,waiting for locks,idles in transaction,and idle.
- Amount of WAL output size.
- Number of CHECKPOINT,VACUUM execution time and access of buffers.
- sqls and functions that take long time.
- Postgresql configuration parameters.
- OS resource information(Usage of cpu,Memory,Disk I/O,Load Average)
- Lock information
- Number of canceled queries which conflicts recovery
- State fo replication
Size of a snapshot depends on the numbers of objects in DB. There are about 600 - 800kB per snapshot. In case of pg_statsinfo default settings,snapshots for each monitored DB requires 90 - 120MB per day.
Note that pg_statsinfo doesn't delete old snapshots. Please delete them manually.
@H_
404_181@ Server Log Filter
- Split server log lines according to the message levels. You can set different message threshold for csvlog,textlog,and syslog.
- Fix filename of the textlog. The default is $PGDATA/pg_log/pg_statsinfo.log. You can always read the latest log in the same filename and setup of log monitoring tools would be easier.
- Set arbitrary access permission for each textlog files. You can control the default permission not only 600.
- Can change log level which was outputted Text log or syslog freely. For example,it can change log message ERROR level to INFO level. It is useful in missed operations.
- We can set not to output log message which is specified user which is like database admin.
Alert Function
If database statistics is over threshold which was set by user,pg_statsinfo detect and write alert log in postgresql-log(message level is 'ALERT').
Alert function can set following alert parameter:
- rollback / seconds
- commit / seconds
- garbage data size (MB)
- garbage data size ratio(%)
- garbage data size ratio in each tables (%)
- average response time of queries (sec)
- longest response time of queries (sec)
- correlations of each tables (%)
- maximum number of backends
- empty disk space in table space (%)
- load average
- usage of disk swap (KB)
- amount of replication delay (MB)
(*1) Correlation of table is judged by only clustered table which is in cluster index.
------------------------------------------------------------------------------------------------------
pg_statsinfo展现数据方式有两种。
简易的文本报告:
http://pgstatsinfo.projects.pgfoundry.org/files/report_sample.txt
或者pg_stats_reporter产生的HTML报告:
http://pgstatsinfo.projects.pgfoundry.org/files/report_sample.html
使用例
1)安装
- [root@zabbix ~#rpm-ihv http://pgfoundryorg/frs/download.PHP/3545/pg_statsinfo-2.5.0-1.pg93.rhel6.x86_64.rpm
- Retrieving http.rpm
- Preparing.###########################################[100%]
- 1:pg_statsinfo ###########################################]
2)配置
这里只做最简单的配置
修改postgre
sql.conf
shared_preload_libraries
='pg_statsinfo'#
(change requires restart
)
log_filename'postgresql-%Y-%m-%d_%H%M%S.log'# log filenamepattern,
安装pg_stat_statements
#p
sql-U postgres
-c
"CREATE EXTENSION pg_stat_statements"