node_exporter 收集器监控linux系统;
[root@Prometheus tools]# tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /opt/ #解压tar包
[root@Prometheus opt]# mv node_exporter-0.18.1.linux-amd64/ /usr/local/node_exporter #修改文件夹名称
[root@Prometheus ]# cd /usr/local/node_exporter/
[root@Prometheus /]# /usr/local/node_exporter/node_exporter & #启动node_exporter,默认端口9100;
[root@Prometheus /]# ps -ef|grep node
root 17404 2918 0 13:58 pts/2 00:00:00 /usr/local/node_exporter/node_exporter
root 17423 2918 0 13:58 pts/2 00:00:00 grep --color=auto node
node_exporter常用启动参数:
# 收集文件系统,忽略哪些不搜集
--collector.filesystem.ignored-mount-points="^/(dev|proc|sys|var/lib/docker/.+)($|/)"
# 管理的系统服务
--collector.systemd.unit-whitelist=".+"
# 指定监听端口 默认9100
--web.listen-address=":9100"
注册node_exporter服务
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter --conllector.systemd --conllector.systemd.unit-whitelist=(docker|kubelet|kube-proxy|flanneld).service
[Install]
WantedBy=multi-user.target
启动node_exporter服务
systemctl daemon-reload
systemctl restart node_exporter
修改Prometheus.yml配置文件,添加Job
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
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: ['localhost:9090']
############## 添加Job #############
- job_name: 'node'
file_sd_configs:
- files: ['/opt/prometheus/sd_config/node.yml']
refresh_interval: 5s
############## 添加job #############
重载配置文件
[root@prometheus]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 0 rule files found
重启 prometheus
[root@prometheus ]# service prometheus restart
Grafana可视化Prometheus 数据
安装Grafana
官网地址:https://grafana.com/grafana/download
[root@Prometheus tools]# wget https://dl.grafana.com/oss/release/grafana-8.0.6-1.x86_64.rpm
[root@Prometheus tools]# sudo yum install grafana-8.0.6-1.x86_64.rpm
[root@Prometheus tools]# systemctl daemon-reload
[root@Prometheus tools]# systemctl start grafana-server
Granfana默认的端口3000 ; 默认的账户密码 admin admin
访问 http://192.168.11.3:3000
添加数据源 > add data source
添加Prometheus 数据源
添加视图
官网视图地址:https://grafana.com/grafana/dashboards