PostgreSQL Monitor pg_view

时间:2022-07-31 02:57:58

PostgreSQL Monitor pg_view

https://github.com/zalando/pg_view

Requirements

Linux 2.6, python 2.6, psycopg2, curses

查看系统是否有curses

[root@node3 /]# ls /usr/include/ncurses*

/usr/include/ncurses_dll.h  /usr/include/ncurses.h

系统已经安装了curses,如果没有下载安装curses

下载安装 curses

curses 的GNU实现 ncurses,官网下载地址:http://ftp.gnu.org/gnu/ncurses/

下载 ncurses 的最新版本;

[root@node3 soft_bak]tar zxvf ncurses-6.0.tar.gz

[root@node3 soft_bak] cd ncurses-6.0

[root@node3 soft_bak] ./configure

[root@node3 soft_bak] make

[root@node3 soft_bak] make install

默认的安装,头文件在 /usr/include 下,库在 /usr/lib 下。

也可以使用yum安装

搜索 : yum search ncurses

安装 : yum install ncurses

软件包

Python-2.7.tar.bz2   psycopg2-2.6.1.tar.gz   psutil-3.2.2.tar.gz

安装 python2.7

[root@node3 soft_bak]# tar jxvf Python-2.7.tar.bz2

[root@node3 soft_bak]# cd Python-2.7

[root@node3 Python-2.7]# ./configure --prefix=/usr/local/python2.7/

[root@node3 Python-2.7]# make

[root@node3 Python-2.7]# make install

添加/usr/local/python2.7/bin/到Linux的环境变量中

[root@node3 bin]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@node3 bin]# PATH="$PATH":/usr/local/python2.7/bin/

[root@node3 bin]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/python2.7/bin/

删除/usr/bin中的python文件,为python2.7创建连接

[root@node3 bin]# cd /usr/bin/

[root@node3 bin]# rm -rf python

[root@node3 bin]# ln -s /usr/local/python2.7/bin/python ./python

[root@node3 bin]# python

Python 2.7 (r27:82500, Jan 14 2016, 16:13:36)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

解决Python升级后yum不能用的问题

#修改yum文件

vi /usr/bin/yum

将文件头部的

#!/usr/bin/python

改为如下内容

#!/usr/bin/python2.6

安装psutil

[root@node3 soft_bak]# tar zxvf psutil-3.2.2.tar.gz

[root@node3 PGMonitor]# cd psutil-3.2.2

[root@node3 psutil-3.2.2]# python setup.py install

安装psycopg2

[root@node3 soft_bak]# tar zxvf psycopg2-2.6.1.tar.gz

[root@node3 PGMonitor]# cd psycopg2-2.6.1

[root@node3 psycopg2-2.6.1]# python setup.py build_ext --pg-config /usr/local/pg945/bin/pg_config  build

[root@node3 psycopg2-2.6.1]# python setup.py build_ext --pg-config /usr/local/pg945/bin/pg_config  install

安装setuptools

[root@node3 soft_bak]# tar zxvf setuptools-19.2.tar.gz

[root@node3 setuptools-19.2]# cd setuptools-19.2

[root@node3 setuptools-19.2]# python setup.py install

[root@node3 soft_bak]# unzip pg_view-master.zip

[root@node3 soft_bak]# cd pg_view-master

将opt/soft_bak/pg_view-master目录下setup.py 中的

第112行  long_description=read('README.md'),改为如下

long_description=read('README.rst'),

[root@node3 pg_view-master]# python setup.py install

[root@node3 soft_bak]# cd /usr/local/python2.7/bin/

[root@node3 bin]# ls

2to3  easy_install  easy_install-2.7  idle   pg_view  pydoc  python  python2.7  python2.7-config  python-config  smtpd.py

启动PostgreSQL

[postgres@node3 bin]$ ./pg_ctl -D ../data/ start

server starting

postgres 用户执行 pg_view

[postgres@node3 ~]$ cd /usr/local/python2.7/bin/

[postgres@node3 bin]$ ./pg_view

生成少量数据

[postgres@node3 bin]$ ./pgbench -i -F 100 -s 142 -h localhost -p 5432 -U postgres postgres

进程pgbench测试

[postgres@node3 bin]$ ./pgbench -h localhost -p 5432 -d postgres -U postgres -c 50 -j 10 -T 600

PostgreSQL Monitor pg_view