prometheus & node_exporter

  • Category: 電腦相關
  • Last Updated: Tuesday, 11 June 2019 13:26
  • Published: Monday, 03 June 2019 11:40
  • Written by sam

Prometheus 安裝非常簡單,許久前已用過,這次就記錄一下node_exporter的過程

[root@ip-172-31-26-97 ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz
[root@ip-172-31-26-97 ~]# tar -zxf node_exporter-0.18.0.linux-amd64.tar.gz
[root@ip-172-31-26-97 ~]# mv ./node_exporter-0.18.0.linux-amd64/node_exporter /usr/bin/

[root@ip-172-31-26-97 ~]# vi /etc/systemd/system/samexporter.service
[Unit]
Description=Prometheus Time Series Collection and Processing Server
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/bin/node_exporter 

[Install]
WantedBy=multi-user.target

[root@ip-172-31-26-97 ~]# systemctl daemon-reload
[root@ip-172-31-26-97 ~]# systemctl start samexporter.service
[root@ip-172-31-26-97 ~]# systemctl enable samexporter.service
Created symlink from /etc/systemd/system/multi-user.target.wants/samexporter.service to /etc/systemd/system/samexporter.service.
[root@ip-172-31-26-97 ~]# systemctl status samexporter.service
[root@ip-172-31-26-97 ~]# netstat -ntulp |grep 9100 #check port up
[root@ip-172-31-26-97 ~]# curl http://localhost:9100/metrics #test curl data
[root@ip-172-31-26-97 ~]# systemctl status firewalld #check firewall status
[root@ip-172-31-26-97 ~]# firewall-cmd --add-port=9100/tcp --permanent #if firewall up add allow
[root@ip-172-31-26-97 ~]# systemctl restart firewalld 

#Go to prometheus and add node


[root@ip-172-31-26-97 ~]# vi /etc/prometheus/prometheus.yml
- job_name: 'api1'
  static_configs:
  - targets: ['172.31.26.97:9100']
- job_name: 'api6'
  static_configs:
  - targets: ['172.31.25.73:9100']
- job_name: 'api7'
  static_configs:
  - targets: ['172.31.28.35:9100']
[root@ip-172-31-26-97 ~]# systemctl restart prometheus.service

Delete Time Series Metrics

root@ip-172-31-37-37:~# curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={job="node_exporter"}'
root@ip-172-31-37-37:~# curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={instance="172.31.24.209:9100"}'
root@ip-172-31-37-37:~# curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={instance="172.31.25.117:9100"}'
root@ip-172-31-37-37:~# curl -X DELETE -g 'localhost:9090/prometheus/api/v1/series?match[]={instance="192.31.28.35:9100"}'

do it first

root@ip-172-31-37-37:~# prometheus --web.enable-admin-api --config.file=/etc/prometheus/prometheus.yml
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={__name__=~".+"}'
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/clean_tombstones'