前面的文章介绍了如何通过Node Exporter提供节点监控信息,然后使用Prometheus Server进行搜集,通过Grafana进行展示的示例。示例中Prometheus Server是使用Docker方式启动,而Node Exporter是通过二进制文件直接启动的,而这篇文章介绍一下Node Exporter和Prometheus都使用Docker方式启动和配置的方法。
配置文件 Prometheus的配置文件使用如下Prometheus的配置文件,请根据需要修改自己机器的IP
liumiaocn:config liumiao$ cat prometheus-node.yml global: scrape_interval: 10s evaluation_interval: 10s scrape_configs: - job_name: 'node' static_configs: - targets: ['192.168.31.242:9100'] labels: group: 'node_exporter' liumiaocn:config liumiao$docker-compose.yml
使用Docker-compose的方式启动Prometheus和Node Exporter,最简单的方式可以使用如下内容即可
liumiaocn:config liumiao$ cat docker-compose.yml version: '2' services: prometheus: image: prom/prometheus:v2.15.1 privileged: true volumes: - ./prometheus-node.yml:/etc/prometheus/prometheus.yml command: - '--config.file=/etc/prometheus/prometheus.yml' ports: - '9090:9090' node-exporter: image: prom/node-exporter:v0.18.1 ports: - '9100:9100' liumiaocn:config liumiao$启动服务
使用如下命令启动Prometheus和Node exporter
执行命令:docker-compose up -d
liumiaocn:config liumiao$ docker-compose up -d Creating network "config_default" with the default driver Creating config_node-exporter_1 ... done Creating config_prometheus_1 ... done liumiaocn:config liumiao$服务状态确认
使用如下命令确认Prometheus和Node exporter启动状态
执行命令:docker-compose ps
liumiaocn:config liumiao$ docker-compose ps Name Command State Ports ---------------------------------------------------------------------------------------- config_node-exporter_1 /bin/node_exporter Up 0.0.0.0:9100->9100/tcp config_prometheus_1 /bin/prometheus --config.f ... Up 0.0.0.0:9090->9090/tcp liumiaocn:config liumiao$页面确认
通过Prometheus的/targets下与Node Exporter的连接信息
确认一下某个指标的变化状况
注意Node Exporter的使用上与操作系统有较强的关联,比如如下的issue:
- https://github.com/prometheus/node_exporter/issues/610