使用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



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM