微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用prometheus+grafana监控postgresql的测试

目的

使用两台机器测试prometheus,监控机器指标和postgresql指标

server1 安装prometheus server和grafana

server2 安装 node_exporter和postgres_exporter

安装

wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz

wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz

wget https://github.com/prometheus-community/postgres_exporter/releases/download/v0.10.1/postgres_exporter-0.10.1.linux-amd64.tar.gz

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.1-1.x86_64.rpm

yum install grafana-enterprise-8.4.1-1.x86_64.rpm

server1:

下载完后解压包,修改配置文件prometheus.yml

ps. 修改配置文件后需要重启服务

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['server1:9090']


  - job_name: 'agent1'
    static_configs:
    - targets: ['server2:9100']

  - job_name: 'postgrescn1'
    static_configs:
    - targets: ['server2:9187']


9090是prometheus server端口

可以登录web页面查看配置

9100是node端口,可通过https://node2:9100/metrics 查看配置

9187是postgres_node端口

ps. 内网需打隧道

grafana配置,端口为3000

PS. 认账号密码:admin/admin

启动

server1:

[root@VM-96-39-centos prometheus-2.8.1.linux-amd64]# /data/prometheus-2.8.1.linux-amd64/prometheus --config.file="/data/prometheus-2.8.1.linux-amd64/prometheus.yml" &

grafana是用rpm装的,也可直接下tar包,启动方式不一样

server2:

nohup /data/node_exporter-1.3.1.linux-amd64/node_exporter &

export DATA_SOURCE_NAME="postgresql://dy:dy@@172.21.96.40:11345/postgres?sslmode=disable"
nohup /data/postgres_exporter-0.10.1.linux-amd64/postgres_exporter &

测试grafana监控数据库指标

配置数据源

import主机监控的模板

https://grafana.com/grafana/dashboards/8919

还有丰富的dashboards,可根据自己的需要导入,及安装对应的采集器。也可以自己定义面板,拷贝一份模板出来修改
https://grafana.com/grafana/dashboards
https://github.com/percona/grafana-dashboards/releases

使用pg_bench 搞一些数据

这里使用的模板是https://grafana.com/grafana/dashboards/455


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐