安装采集组件
node_exporter
安装
tar zxf node_exporter-1.2.2.linux-amd64.tar.gz -C /opt
mv /opt/node_exporter-1.2.2.linux-amd64 /opt/node_exporter
配置服务:
vim /usr/lib/systemd/system/node_exporter.service
# 配置node exporter自启动服务
[Unit]
Description=node_exporter service
[Service]
User=root
ExecStart=/opt/node_exporter/node_exporter
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
配置开机自启动
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter
查看服务状态
[test_001@centos-7 ~]$ systemctl status node_exporter
● node_exporter.service - node_exporter service
Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-12-14 23:50:51 CST; 2 days ago
Main PID: 581 (node_exporter)
CGroup: /system.slice/node_exporter.service
└─581 /opt/node_exporter/node_exporter
Prometheus配置文件添加监控项
vi /opt/prometheus/prometheus.yml --添加需要监控的主机
- job_name: 'node_exporter_vm2'
static_configs:
- targets: ['**.**.1**.**:9100']
labels:
instance: vm2
重启Prometheus:
systemctl restart prometheus
验证
查看Prometheus自带监控页面中Targets,可以看到我们新增的vm2
postgres_exporter
安装
tar zxf postgres_exporter-0.10.0.linux-amd64.tar.gz -C /opt
mv /opt/postgres_exporter-0.10.0.linux-amd64 /opt/postgres_exporter
编辑配置文件,配置postgresql源
--创建 postgres_exporter.env 文件
cd /opt/postgres_exporter
touch postgres_exporter.env
vi postgres_exporter.env
DATA_SOURCE_NAME="postgresql://postgres:vFWJTJpUoXXcS1zS8hEq7EmBtOLC7M5T@**.**.**.**:5432/?sslmode=disable"
配置服务
vim /etc/systemd/system/postgres_exporter.service
[Unit]
Description=Prometheus exporter for Postgresql
Wants=network-online.target
After=network-online.target
[Service]
User=postgres
Group=postgres
WorkingDirectory=/opt/postgres_exporter
EnvironmentFile=/opt/postgres_exporter/postgres_exporter.env
ExecStart=/opt/postgres_exporter/postgres_exporter
Restart=always
[Install]
WantedBy=multi-user.target
配置开机自启动
systemctl daemon-reload
systemctl enable postgres_exporter
systemctl start postgres_exporter
systemctl status postgres_exporter
Prometheus配置文件添加监控项
vim /opt/prometheus/prometheus.yml --添加需要监控数据库信息
- job_name: 'postgres'
static_configs:
- targets: ['**.**.**.**:9187']
labels:
instance: postgresql
重启Prometheus:
systemctl restart promtheus
后续用的新的组件再更新…