PostgreSQL 集群性能审计工具pgCluu
1. 简介
pgCluu 是一个对 PostgreSQL 集群性能进行完整审计的工具,该工具分为两部分:
- collector 用于从 PostgreSQL 集群中获取统计数据,使用 psql 和 sar 工具。
grapher 用于生成 HTML 报表和图表。
语法:
PostgreSQL数据库和系统指标收集器 pgcluu_collectd [options] output_dir 报表生成器 pgcluu [options] -o report_dir input_dir
2. 安装
好,下面我们介绍如何安装和使用它。
我们可以从pgCluu的github上下载。目前gpCluu版本更新到了2.4,下载后解压
tar -xzvf pgcluu-2.4.tar.gz
检查并编译,可执行文件默认会安装至 /usr/local/bin/
目录下。
[root@anzhy pgcluu-2.4]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for pgCluu
[root@anzhy pgcluu-2.4]# make
cp pgcluu_collectd blib/script/pgcluu_collectd
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/pgcluu_collectd
cp pgcluu blib/script/pgcluu
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/pgcluu
Manifying blib/man1/pgcluu.1
[root@anzhy pgcluu-2.4]# sudo make install
Installing /usr/local/share/man/man1/pgcluu.1
Installing /usr/local/bin/pgcluu_collectd
Installing /usr/local/bin/pgcluu
Appending installation info to /usr/lib64/perl5/perllocal.pod
3. 配置
3.1 启动postgres
如果还没有启动postgres,我们先启动它,我们使用postgres用户
su - postgres
pg_ctl -D /usr/local/pgsql/data start
3.2 执行收集器
我们先建立临时目录,然后执行收集器
mkdir /tmp/stat_db1/
pgcluu_collectd -D -i 60 /tmp/stat_db1/
过几分钟我们停止收集
pgcluu_collectd -k
以下就是收集过程
1 | [postgres@anzhy ~]$ mkdir /tmp/stat_db1/ |
收集的数据保存在csv及txt文件中。
3.3 执行报表生成器
接下来我们通过报表生成器生成我们可以看的html网页
mkdir /tmp/report_db1/
pgcluu -o /tmp/report_db1/ /tmp/stat_db1/
结果1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33[postgres@anzhy ~]$ mkdir /tmp/report_db1/
[postgres@anzhy ~]$ pgcluu -o /tmp/report_db1/ /tmp/stat_db1/
[postgres@anzhy ~]$ ll /tmp/report_db1
total 1760
-rw-rw-r--. 1 postgres postgres 102595 Mar 4 09:21 bootstrap.min.css
-rw-rw-r--. 1 postgres postgres 27834 Mar 4 09:21 bootstrap.min.js
-rw-rw-r--. 1 postgres postgres 128934 Mar 4 09:21 cluster.html
-rw-rw-r--. 1 postgres postgres 41925 Mar 4 09:21 database-all.html
-rw-rw-r--. 1 postgres postgres 71078 Mar 4 09:21 database-pgbench.html
-rw-rw-r--. 1 postgres postgres 71186 Mar 4 09:21 database-plpython_testdb.html
-rw-rw-r--. 1 postgres postgres 74045 Mar 4 09:21 database-postgres.html
-rw-rw-r--. 1 postgres postgres 70967 Mar 4 09:21 database-test.html
-rw-rw-r--. 1 postgres postgres 71153 Mar 4 09:21 database-trigger_testdb.html
-rw-rw-r--. 1 postgres postgres 125286 Mar 4 09:21 font-awesome.min.css
-rw-rw-r--. 1 postgres postgres 80174 Mar 4 09:21 index.html
-rw-rw-r--. 1 postgres postgres 104684 Mar 4 09:21 jquery.min.js
-rw-rw-r--. 1 postgres postgres 43879 Mar 4 09:21 network-device0.html
-rw-rw-r--. 1 postgres postgres 43873 Mar 4 09:21 network-device1.html
-rw-rw-r--. 1 postgres postgres 43120 Mar 4 09:21 pgbench-index-size.html
-rw-rw-r--. 1 postgres postgres 41934 Mar 4 09:21 pgbench-table-size.html
-rw-rw-r--. 1 postgres postgres 3782 Mar 4 09:21 pgcluu.css
-rw-rw-r--. 1 postgres postgres 104288 Mar 4 09:21 pgcluu.js
-rw-rw-r--. 1 postgres postgres 42871 Mar 4 09:21 plpython_testdb-index-size.html
-rw-rw-r--. 1 postgres postgres 41609 Mar 4 09:21 plpython_testdb-table-size.html
-rw-rw-r--. 1 postgres postgres 42850 Mar 4 09:21 postgres-index-size.html
-rw-rw-r--. 1 postgres postgres 41588 Mar 4 09:21 postgres-table-size.html
-rw-rw-r--. 1 postgres postgres 17899 Mar 4 09:21 sorttable.js
-rw-rw-r--. 1 postgres postgres 53244 Mar 4 09:21 system-device0.html
-rw-rw-r--. 1 postgres postgres 75758 Mar 4 09:21 system.html
-rw-rw-r--. 1 postgres postgres 42838 Mar 4 09:21 test-index-size.html
-rw-rw-r--. 1 postgres postgres 41654 Mar 4 09:21 test-table-size.html
-rw-rw-r--. 1 postgres postgres 42868 Mar 4 09:21 trigger_testdb-index-size.html
-rw-rw-r--. 1 postgres postgres 41673 Mar 4 09:21 trigger_testdb-table-size.html
4. 结果展示
4.1 index 网页
4.2 系统信息
4.3 数据库信息
更多结果参见pgCluu官网Example
本文参考pgCluu官网