node-exporte-节点指标收集
方法一
添加步骤
1. 在对应的服务器启动一个服务: node-exporter:
1
172.17.3.15:9100
2. 在普罗米修斯的配置文件中加入新加服务器的ip:port
1
2
3
4
5
# vim prometheus.yml
scrape_configs:
- job_name: bin-k8s-node02
static_configs:
- targets: ['172.17.3.15:9100']
3. 重启prometheus
方法二
1. 与方法一第1步一致
2. 修改配置文件: prometheus.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 使用加载json文件的格式,只要文件发生变化,Prometheus 就会自动加载
# vim prometheus.yml
scrape_configs:
- job_name: 'node-exporter'
file_sd_configs:
- files: ['/usr/local/prometheus/groups/nodegroups/*.json']
#json文件
# vim /usr/local/prometheus/groups/nodegroups/localhost.json
[
{
"targets": [
"172.17.3.7:9100"
],
"labels": {
"instance": "172.17.3.7",
"service": "localhost-node"
}
}
]
3. 如果是容器启动的话,挂载目录
**注意: 如果想要自动加载需要在启动的时候加载参数: --web.enable-lifecycle**1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#docker-compose.yml
services:
prometheus:
image: prom/prometheus
container_name: prometheus
hostname: prometheus
restart: always
environment:
TZ: Asia/Shanghai
volumes:
- /opt/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml:rw
- /opt/prometheus/config/rule/node_down.yml:/etc/prometheus/node_down.yml:rw
- /opt/prometheus/data:/prometheus:rw
- /opt/prometheus/config/groups/:/usr/local/prometheus/groups/:rw
ports:
- "9090:9090"
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.enable-admin-api' # 开启可以调用API删除时序数据库的内容
- '--web.enable-lifecycle' # 开启热更新,自动加载配置文件
本文由作者按照
CC BY 4.0
进行授权