合 PG监控工具之pgcenter
简介
GitHub:https://github.com/lesovsky/pgcenter
pgCenter is a command-line admin tool for observing and troubleshooting Postgres.
pgCenter's main goal is to help Postgres DBA working with statistics and provide a convenient way to observe Postgres in runtime.
安装
普通安装使用
可以tar.gz也可以rpm包:
1 2 3 4 5 6 7 8 9 10 11 12 13 | wget https://github.com/lesovsky/pgcenter/releases/download/v0.9.2/pgcenter_0.9.2_linux_amd64.tar.gz tar zxvf pgcenter_0.9.2_linux_amd64.tar.gz chmod 755 pgcenter ./pgcenter --version wget https://github.com/lesovsky/pgcenter/releases/download/v0.9.2/pgcenter_0.9.2_linux_amd64.rpm [root@docker35 soft]# rpm -ivh pgcenter_0.9.2_linux_amd64.rpm Preparing... ################################# [100%] Updating / installing... 1:pgcenter-0:0.9.2-1 ################################# [100%] [root@docker35 soft]# rpm -ql pgcenter-0:0.9.2-1 /usr/bin/pgcenter |
Docker使用
地址:https://hub.docker.com/r/lesovsky/pgcenter
1 2 | docker pull lesovsky/pgcenter:latest docker run -it --rm lesovsky/pgcenter:latest pgcenter top -h 1.2.3.4 -U user -d dbname -p 5432 |
使用过程:
1 2 3 4 5 6 7 8 9 | [root@docker35 ~]# docker pull lesovsky/pgcenter:latest latest: Pulling from lesovsky/pgcenter 540db60ca938: Pull complete 21f2e7685a5c: Pull complete Digest: sha256:5fb7a26a146d10e31a641e474d01ebea5319668962310c7fbf2a6ef8c47f3b3a Status: Downloaded newer image for lesovsky/pgcenter:latest docker.io/lesovsky/pgcenter:latest [root@docker35 ~]# docker run -it --rm lesovsky/pgcenter:latest pgcenter top -h 172.17.0.4 -U postgres -d postgres -p 5432 Password for user postgres: |
输入密码后就可以返回如下结果:
帮助命令
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 34 35 36 37 38 | [root@docker35 soft]# pgcenter --help pgCenter is a command line admin tool for PostgreSQL. Usage: pgcenter [flags] pgcenter [command] [command-flags] [args] Available commands: config installs or uninstalls pgcenter stats schema to Postgres profile wait events profiler record record stats to file report make report based on previously saved statistics top top-like stats viewer Flags: -?, --help show this help and exit --version show version information and exit Use "pgcenter [command] --help" for more information about a command. Report bugs to <https://github.com/lesovsky/pgcenter/issues>. [root@docker35 soft]# pgcenter top --help 'pgcenter top' is the top-like stats viewer. Usage: pgcenter top [OPTIONS]... [DBNAME [USERNAME]] Options: -d, --dbname DBNAME database name to connect to -h, --host HOSTNAME database server host or socket directory -p, --port PORT database server port (default 5432) -U, --username USERNAME database user name General options: -?, --help show this help and exit Report bugs to <https://github.com/lesovsky/pgcenter/issues>. |
pgcenter top命令常用的指令选项
使用pgcenter top命令进行监控,默认是一秒刷新一次
- h,F1 查看帮助
- q,‘ESC’,‘Ctrl+Q’ 退出
- z 设置刷新间隔,默认是1秒,可调范围是1到300
- Q 重置数据库统计信息
- ‘-’ 中划线符号,输入pid,取消查询,相当于调用pg_cancel_backend函数
- ‘_’ 下划线符号,输入pid,取消查询,相当于调用pg_terminate_backend函数
- B 同时查看磁盘信息,交替按会取消。
- N 同时查看网络接口信息,交替按会取消。
- L 查看数据库日志尾部行
- l 查看数据库的日志信息,翻页形式
- ‘~’ 打开psql会话,\q退出到pgcenter界面
- C、E、R 显示、编辑、重载PG配置参数
- a、d、f、r 活动连接信息, 数据库信息, 函数信息, 流复制信息
- s、t、i 分别显示表大小、表统计信息、索引统计信息
- x、X 小写x交替显示不同维度pg_stat_statements信息,大写X下拉选取pg_stat_statements 菜单
- p、P 小写p交替显示pg_statprogress信息,大写P下拉选取pg_statprogress菜单
- Up、Down 上下键调整列的宽度
- Left,Right,<,/ 左右键选择列, 左方括号交替排序, '/'过滤
pgcenter top示例
先使用pgbench压测,准备环境
1 2 3 | $ pgbench -i -s8 --unlogged-tables postgres $ pgbench -r -c8 -T120 postgres |
使用pgcenter top命令进行监控,默认是一秒刷新一次
1 2 | [root@docker35 ~]# pgcenter top -h 172.17.0.4 -U postgres -d postgres -p 5433 Password for user postgres: |
按下“ctrl+c”结束监控。