使用两台机器测试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 &
https://grafana.com/grafana/dashboards/8919
还有丰富的dashboards,可根据自己的需要导入,及安装对应的采集器。也可以自己定义面板,拷贝一份模板出来修改。
https://grafana.com/grafana/dashboards
https://github.com/percona/grafana-dashboards/releases
这里使用的模板是https://grafana.com/grafana/dashboards/455