安装node-exporter
脚本地址,点击下载。
下载安装
1
2
3
4
|
cd /usr/local/src
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz
tar xf node_exporter-0.18.0.linux-amd64.tar.gz -C /opt/
ln -s /opt/node_exporter-0.18.0.linux-amd64/ /opt/node_exporter
|
以ops
用户启动,需要先创建用户并授权。
1
2
|
useradd ops
chown -R ops. /opt/node_exporter*
|
服务启动
system
配置文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
cat > /etc/systemd/system/node_exporter.service << EOF
[Unit]
Description=Node_exporter daemon
After=network.target
[Service]
ExecStart=/opt/node_exporter/node_exporter
User=ops
Group=ops
PrivateTmp=True
[Install]
WantedBy=multi-user.target
EOF
|
启动
1
2
3
4
|
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter
|
Prometheus
注册到consul
。
1
|
pip=$(ip a|grep eth0|grep inet|awk '{print $2}'|cut -d "/" -f 1);hn=$(hostname);curl -s -X PUT -d '{"id":"'"${hn}"'","name":"'"${hn}"'","address":"'"${pip}"'","port":9100,"tags":["hosts-node"],"checks":[{"http":"http://'"${pip}"':9100/metrics","interval":"15s"}]}' http://10.66.2.152:8500/v1/agent/service/register
|
若使用Ansible
批量注册,可参考play-book。
Prometheus
基于consul
自动发现。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
- job_name: consul-node
consul_sd_configs:
- server: "10.66.2.152:8500"
relabel_configs:
- source_labels: [__meta_consul_tags]
# 从consul中过滤hosts-xxxxxx相关主机
regex: .*hosts-node.*
action: keep
- source_labels:
- __meta_consul_service
- __meta_consul_service_address
separator: "::"
target_label: "sd_instance_name"
- source_labels: [__meta_consul_dc]
target_label: "dc"
- source_labels: [__meta_consul_tags]
target_label: "sd_tag"
|
Grafana
最终效果如图: