天天看点

PG的Prometheus监控

到github上,下载已编译好的exporter文件

地址: https://github.com/wrouesnel/postgres_exporter/releases

tar xf postgres_exporter_v0.4.1_linux-amd64.tar.gz -C /opt/

cd /opt/postgres_exporter_v0.4.1_linux-amd64

vim start.sh 启动脚本内容如下

#!/bin/bash

cd /opt/postgres_exporter_v0.4.1_linux-amd64
export PATH=/usr/local/pgsql/bin:$PATH

# 下面的password替换为你自己的postgres用户的密码
export  DATA_SOURCE_NAME="user=postgres host=localhost password=123456 port=5432 dbname=postgres sslmode=disable"

nohup ./postgres_exporter --web.listen-address=":9187" >/dev/null 2>&1 &      

然后,到Prometheus里面去加上对应的target

采集到数据后,就可以在 grafana里面画图了,类似这样:

PG的Prometheus监控

通常,我们还会同时部署个node_exporter 采集下主机级别的监控信息。类似这样:

PG的Prometheus监控

因为blog不方便上传文件,这里我就不贴 grafana模板文件了。