Postgresql监控pgwatch的搭建
一,需要环境:
You will need a handful of components to make this work:
- Apache (webserver) #apache搭建web页面
- PHP (scripting language) #php5
- pgsql extension for PHP (see http://www.php.net/manual/en/book.pgsql.php) #php的pgsql的扩展支持
- PostgreSQL (to store the data we collect) #postgresql9
- dblink (contribution module for PostgreSQL ) #dblink 数据库连接常用软件
- For now we only support PostgreSQL >= 9.0 databases.
Older systems cannot be monitored, however, we will
add support for future database releases.
我的pgsql是yum安装的,就是为了省事,但是在安装pgwatch环境的时候费了不少劲,主要原因也是我对pgsql不太了解,才接触,所以主要讲一下yum的安装方法,编译的pgsql搭建以上环境很轻松,百度。
1,首先apache的安装一般centos都自带,没有的话yum安装就可以,讲一下遇到的一些问题。
[root@wds00 pgwatch-1.0]# vim /etc/httpd/conf/httpd.conf
# Deny from all
# </LimitExcept>
#</Directory> #
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents. The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.php index.html index.html.var #添加index.php索引 #
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess #
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
########################################
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so
97 LoadModule php5_module modules/libphp5.so #添加php模块
########################################
AddType application/x-httpd-php .php
10 AddType application/x-httpd-php-source .phps #添加php文件
2.安装php支持的postgresql扩展
[root@localhost config]# yum list |grep pgsql
php-pgsql.x86_64 5.3.3-27.el6_5.1 @updates
apr-util-pgsql.x86_64 1.3.-.el6_0. base
dovecot-pgsql.x86_64 :2.0.-.el6_5. updates
dspam-pgsql.x86_64 3.10.-.el6 epel
erlang-pgsql.x86_64 -.20101203svn.el6 epel
exim-pgsql.x86_64 4.72-.el6 epel
gnokii-smsd-pgsql.x86_64 0.6.-.el6 epel
libdbi-dbd-pgsql.x86_64 0.8.-5.1.el6 base
libodb-pgsql.i686 2.3.-.el6 epel
libodb-pgsql.x86_64 2.3.-.el6 epel
libodb-pgsql-devel.i686 2.3.-.el6 epel
libodb-pgsql-devel.x86_64 2.3.-.el6 epel
mod_auth_pgsql.x86_64 2.0.-10.1.el6 base
mydns-pgsql.x86_64 1.2.8.31-.el6 epel
nagios-plugins-pgsql.x86_64 1.4.-.el6 epel
php-pear-MDB2-Driver-pgsql.noarch 1.5.-0.8.b4.el6 epel
plpgsql_check_93.x86_64 0.9.-.rhel6 pgdg93
plpgsql_check_93-debuginfo.x86_64 0.9.-.rhel6 pgdg93
root-sql-pgsql.x86_64 5.34.-.el6 epel
rsyslog-pgsql.x86_64 5.8.-.el6 base
trytond-pgsql.noarch 1.8.-.el6 epel
uuid-pgsql.x86_64 1.6.-.el6 base
zabbix-proxy-pgsql.x86_64 1.8.-.el6 epel
zabbix-server-pgsql.x86_64 1.8.-.el6 epel
zabbix-web-pgsql.noarch 1.8.-.el6 epel
zabbix20-proxy-pgsql.x86_64 2.0.-.el6 epel
zabbix20-server-pgsql.x86_64 2.0.-.el6 epel
zabbix20-web-pgsql.noarch 2.0.-.el6 epel
zabbix22-dbfiles-pgsql.noarch 2.2.-.el6 epel
zabbix22-proxy-pgsql.x86_64 2.2.-.el6 epel
zabbix22-server-pgsql.x86_64 2.2.-.el6 epel
zabbix22-web-pgsql.noarch 2.2.-.el6 epel
[root@localhost config]# yum -y install php-pgsql.x86_64
3.安装dblink
在网上找了很久关于yum安装dblink的资料,几乎没有,最后找到debian安装的办法,主要就是一个dblink.sql的文件。
方法如下:
[root@wds00 /]# rpm -qa |grep post
postgresql92-contrib-9.2.9-1PGDG.rhel6.x86_64
postfix-2.6.6-2.2.el6_1.x86_64
postgresql92-libs-9.2.9-1PGDG.rhel6.x86_64
postgresql92-jdbc-9.2.1002-1PGDG.rhel6.x86_64
postgresql92-9.2.9-1PGDG.rhel6.x86_64
postgresql92-server-9.2.9-1PGDG.rhel6.x86_64
[root@wds00 /]# [root@localhost config]# find / -name dblink*
/usr/pgsql-9.2/lib/dblink.so #重要
/usr/pgsql-9.2/share/man/man3/dblink_get_result.
/usr/pgsql-9.2/share/man/man3/dblink_is_busy.
/usr/pgsql-9.2/share/man/man3/dblink_exec.
/usr/pgsql-9.2/share/man/man3/dblink.
/usr/pgsql-9.2/share/man/man3/dblink_close.
/usr/pgsql-9.2/share/man/man3/dblink_fetch.
/usr/pgsql-9.2/share/man/man3/dblink_error_message.
/usr/pgsql-9.2/share/man/man3/dblink_connect.
/usr/pgsql-9.2/share/man/man3/dblink_get_notify.
/usr/pgsql-9.2/share/man/man3/dblink_cancel_query.
/usr/pgsql-9.2/share/man/man3/dblink_build_sql_update.
/usr/pgsql-9.2/share/man/man3/dblink_build_sql_delete.
/usr/pgsql-9.2/share/man/man3/dblink_disconnect.
/usr/pgsql-9.2/share/man/man3/dblink_get_connections.
/usr/pgsql-9.2/share/man/man3/dblink_get_pkey.
/usr/pgsql-9.2/share/man/man3/dblink_build_sql_insert.
/usr/pgsql-9.2/share/man/man3/dblink_send_query.
/usr/pgsql-9.2/share/man/man3/dblink_open.
/usr/pgsql-9.2/share/man/man3/dblink_connect_u.
/usr/pgsql-9.2/share/extension/dblink.control
/usr/pgsql-9.2/share/extension/dblink--unpackaged--1.0.sql
/usr/pgsql-9.2/share/extension/dblink--1.0.sql #重要
[root@localhost config]# [root@wds00 pgwatch-1.0]# cat /usr/pgsql-9.2/share/extension/dblink--1.0.sql |psql -U postgres -h 192.168.102.43
Use "CREATE EXTENSION dblink" to load this file. 登陆数据库 执行CREATE EXTENSION dblink;成功
postgres=# CREATE EXTENSION dblink;
CREATE EXTENSION
postgres=# select extname,extversion from pg_extension;
extname | extversion
---------+------------
plpgsql | 1.0
dblink | 1.0
(2 行记录)
二,下载pgwatch安装包1.0版本。
wget http://www.cybertec.at/download/pgwatch/pgwatch-1.0.tar.gz -O /usr/loca/src/pgwatch-1.0.tar.gz cd /usr/local/src/ tar zxvf /usr/loca/src/pgwatch-1.0.tar.gz #解压 [root@wds00 src]# ls
pgwatch-1.0 pgwatch-1.0.tar.gz
三,修改配置文件
由于之前网上一哥们(玩命写博客)的文章给了我们很大帮助,但是他搭建的时候pgsql的版本还比较低,所以有些问题没有遇到,现在pgsql大家都用version2.0 或者version3.0版本的,所以在安装上都会遇到不出图的问题,我也一样,下面仔细说说原因与解决办法。
1,配置文件
[root@wds00 config]# pwd
/var/www/html/config
[root@wds00 config]# ls
config.ini config.ini.template fetch_8_4.xml fetch_9_0.xml fetch_9_1.xml fetch_9_2.xml #模板文件用来生成config.ini 的,里面版本就没有9.1以上的,所以生成出来的配置文件也不能有9.1以上版本的xml文件了,里面的所有xml文件都是一个软连接,指向fetch_8_4.xml。
[root@wds00 config]# ll
总用量 32
-rw-r--r-- 1 apache apache 2289 9月 15 19:14 config.ini
-rw-r--r-- 1 apache apache 2313 9月 15 19:03 config.ini.template
-rw-r--r-- 1 apache apache 23351 9月 15 16:59 fetch_8_4.xml
lrwxrwxrwx 1 apache apache 13 9月 15 17:42 fetch_9_0.xml -> fetch_8_4.xml
lrwxrwxrwx 1 apache apache 13 9月 15 17:42 fetch_9_1.xml -> fetch_8_4.xml
lrwxrwxrwx 1 apache apache 13 9月 15 19:16 fetch_9_2.xml -> fetch_8_4.xml
[root@wds00 config]#cat config.ini.template
; When during synchronization a daily aggregation also happens for tables and indexes info.
; This variable tells the system what length of interval to reprocess.
; Must be at least 1 hour, but to avoid "holes" in data due to any syytem halts
; it's better to choose a bigger interval.
sync_agg_reprocess_interval = "2 days" ; allowed pg versions (dropdown in configure menu)
allowed_pg_versions[] = "8.4"
allowed_pg_versions[] = "9.0"
allowed_pg_versions[] = "9.1"
allowed_pg_versions[] = "9.2" #我自己后加的 ; Allow caching dbrow objects for acceleration purposes, but needs more memory
allow_cache = true
###########################################################################
修改 fetch_8_4.xml,重中之重,不然你可能会sql查询报错,原因就是由于pgsql8.4与9.2 9.3这类版本不一样导致的,里面的一个 pg_stat_activity数据列名称不一样。我的是pgsql9.2
pgwatch主要就是查这个表然后统计数据在显示的,如果你连查表都出问题,更别说显示了。
feeb=# \d pg_stat_activity
View "pg_catalog.pg_stat_activity"
Column | Type | Modifiers
------------------+--------------------------+-----------
datid | oid |
datname | name |
pid | integer |
usesysid | oid |
usename | name |
application_name | text |
client_addr | inet |
client_hostname | text |
client_port | integer |
backend_start | timestamp with time zone |
xact_start | timestamp with time zone |
query_start | timestamp with time zone |
state_change | timestamp with time zone |
waiting | boolean |
state | text |
query | text |
##########################################
看一下fetch_8_4.xml文件里面怎么写的
<query debug="true" log="Retrieving t_stat_activity">
INSERT INTO raw_data.t_stat_activity
(tstamp, node_id, database_id, datid, datname, procpid, usesysid, usename, current_query,
waiting, xact_start, query_start, backend_start, client_addr, client_port)
SELECT '{{input:now}}', '{{input:node_id}}', '{{input:db_id}}', *
FROM dblink('{{input:link}}', 'SELECT datid, datname, procpid, usesysid, usename, current_query,
waiting, xact_start, query_start, backend_start, client_addr, client_port
FROM pg_catalog.pg_stat_activity WHERE datname=''{{input:dbname}}''
AND current_query!=''<IDLE>'' AND procpid!=pg_backend_pid()')
AS (datid oid, datname name, procpid integer, usesysid oid, usename name,
current_query text, waiting boolean, xact_start timestamp, query_start timestamp,
backend_start timestamp, client_addr inet, client_port integer)
我简单标红了几个地方,具体的我也不找了,我直接把正确的复制过来,如下:
<?xml version='1.0' standalone='yes'?>
<queries>
<query debug="true" log="Retrieving t_stat_activity">
INSERT INTO raw_data.t_stat_activity
(tstamp, node_id, database_id, datid, datname, procpid, usesysid, usename, current_query,
waiting, xact_start, query_start, backend_start, client_addr, client_port)
SELECT '{{input:now}}', '{{input:node_id}}', '{{input:db_id}}', *
FROM dblink('{{input:link}}', 'SELECT datid, datname, pid, usesysid, usename, query,
waiting, xact_start, query_start, backend_start, client_addr, client_port
FROM pg_catalog.pg_stat_activity WHERE datname=''{{input:dbname}}''
AND query!=''<IDLE>'' AND pid!=pg_backend_pid()')
AS (datid oid, datname name, pid integer, usesysid oid, usename name,
query text, waiting boolean, xact_start timestamp, query_start timestamp,
backend_start timestamp, client_addr inet, client_port integer)
</query>
###########################################################################
2,php文件
[root@wds00 classes]# pwd
/var/www/html/classes
[root@wds00 classes]# ls
auth.php config_node.php database.php env.php logging.php pgwatch_smarty.php validator.php yui_datatable.php
chart.php configure.php dates.php FusionCharts_Gen.php log.php pgwatch_xml.php xmlpage.php
config_database.php dashboard.php dbrow.php FusionCharts.php pgwatch_database.php sql_worksheet.php xmlpageset.php ###################################
[root@wds00 classes]# cat config_database.php
// collect raw data from remote database
public function sync($now){
$node = $this->get_node();
new log("NOTICE", "Synchronizing database " . $this->database_name);
$version = preg_replace('/^(\d+\.\d+).*/', '\1', $node->version);
switch ($version){
case "8.4":
$xml_file = "config/fetch_8_4.xml";
break;
case "9.0":
$xml_file = "config/fetch_9_0.xml";
break;
case "9.1":
$xml_file = "config/fetch_9_1.xml";
break;
case "9.2": #此处自行添加。
$xml_file = "config/fetch_9_2.xml";
break;
三,完成以上修改之后就可以运行setup.php了,生成配置文件,配置数据库链接,添加计划任务定时收集数据。
0 * * * * cd/var/www/html/util && /usr/bin/php getraw_d.php
感谢QQ好友-等等路人(370508695),欢迎交流,如有错误希望能留言指出,我会及时修改,谢谢支持。
请珍惜别人的劳动转载请指明出处谢谢
官网监控推荐:http://wiki.postgresql.org/wiki/Monitoring
参考博客:http://blog.csdn.net/lengzijian/article/details/8127207
Postgresql监控pgwatch的搭建的更多相关文章
- 企业级监控软件zabbix搭建部署之zabbix server的安装
企业级监控软件zabbix搭建部署之zabbix server的安装 zabbix线上已经应用半年多了,关于zabbix在生产环境中的使用心得,以及一些经验写下来,希望让大家少走弯路,共同学习! 环境 ...
- 企业级监控软件Zabbix搭建部署之zabbix在WEB页面中的配置
企业级监控软件zabbix搭建部署之zabbix在WEB页面中的配置 企业级监控软件zabbix搭建部署之zabbix在WEB页面中的配置 关于安装请看 http://www.linuxidc.com ...
- PostgreSQL Hot Standby的搭建
一. 简介: PG在9.*版本后热备提供了新的一个功能,那就是Stream Replication的读写分离,是PG高可用性的一个典型应用.这个功能在oracle中叫active d ...
- PostgreSQL 监控数据库活动
监控数据库活动 1. 标准Unix 工具 [root@mysqlhq ~]# ps auxww | grep ^postgrespostgres 12106 0.0 0.0 340060 15064 ...
- 基于Prometheus和Grafana的监控平台 - 环境搭建
相关概念 微服务中的监控分根据作用领域分为三大类,Logging,Tracing,Metrics. Logging - 用于记录离散的事件.例如,应用程序的调试信息或错误信息.它是我们诊断问题的依据. ...
- Security基础(四):OpenSSL及证书服务常用系统监控命令、搭建nagios监控服务器、配置文件及插件使用、监控远程主机的公有数据、监控远程主机的私有数据
一.OpenSSL及证书服务常用系统监控命令 目标: 本案例要求练习常用的系统监控命令完成以下任务: 使用vmstat命令监控内存及磁盘I/O信息 使用iostat命令监控CPU处理器及磁盘的I/O信 ...
- Prometheus 监控平台的搭建
1. 环境准备 两台ubuntu 16.04 服务器内网IP 作用 安装软件 172.16.4.11 监控的服务端 Prometheus( ...
- Prometheus+Grafana监控-基于docker-compose搭建
前言 Prometheus Prometheus 是有 SoundCloud 开发的开源监控系统和时序数据库,基于 Go 语言开发.通过基于 HTTP 的 pull 方式采集时序数据,通过服务发现或静 ...
- zabbix监控超详细搭建过程
监控及zabbix 目录: 1 监控分类... 1 1.1 硬件监控... 1 1.2 系统监控... 2 1.3 网络监控... 3 1.4 ...
随机推荐
- [BJOI2010]次小生成树
OJ题号: BZOJ1977.COGS2453 题目大意: 给你一个无向连通图,求严格次小生成树. 思路: 对于一般次小生成树,我们有一个结论:一般次小生成树一定可以通过替换掉最小生成树某一条边得到. ...
- 浙江省队选拔 ZJOI2015 (Round 1) 解题报告
最近莫名其妙地喜欢上了用这种格式写各省省选的全套题解= = 今年浙江省选的出题人是算法竞赛界传说级人物陈立杰,看样子他的出题风格很有特点……ABC三题难度是严格递减的,感觉如果在做第一题的时候被卡住的 ...
- 移动端适配之雪碧图(sprite)背景图片定位
为了减少网络请求个数量,提高网站的访问速度,我们一般都会把一些小的图片合并成一张sprite图,然后根据background-position来进行定位.在web端由于是固定的大小与left .top ...
- mysql数据库cup飙升处理思路
1.先top查看是那一个进程,哪个端口占用CPU多. 2.show processeslist查看是否由于大量并发,锁引起的负载问题. 3.否则,查看慢查询,找出执行时间长的sql:explain分析 ...
- hadoop 2.7.1 高可用安装部署
hadoop集群规划 目标:创建2个NameNode,做高可用,一个NameNode挂掉,另一个能够启动:一个运行Yarn,3台DataNode,3台Zookeeper集群,做高可用. 在hadoop ...
- Android File Hierarchy : System Structure Architecture Layout
Most of the Android user are using their Android phone just for calls, SMS, browsing and basic apps, ...
- 改变 Windows 用户文件夹默认位置
https://social.microsoft.com/Forums/zh-CN/b6602d50-1a75-42d2-90bd-3dc6c2c82147/programdata?forum=win ...
- MySQL:按前缀批量删除表格
想要实现mysql>drop table like "prefix_%" 没有直接可用的命令,不过可以通过mysql语法来组装, SELECT CONCAT( 'DROP T ...
- IOS中为tableViewCell增加右侧标记(选中或者更多)
if ([self.selectWys containsObject:[self.initCitys objectAtIndex:indexPath.row]]) { tvCell.accessory ...
- 【笨木头Lua专栏】基础补充05:迭代器番外篇
关于迭代器的内容, 另一点点,只是已经无关紧要了.应该算是一种扩展吧.就一起来开开眼界好了~ 笨木头花心贡献.哈?花心?不.是用心~ 转载请注明,原文地址: http://www.benmutou.c ...