2018-09-04-docker 安装配置Prometheus+node_exporter+cadvisor

这是搜索普遍得到的安装命令,需要自定义映射端口的话自行修改。
执行这两个命令很不理想,会导致node_exporter端口没有映射,很郁闷


image.png

而且prometheus 添加node_exporter 会报出无法连接

docker 启动prometheus

docker run -d -p 9090:9090 --name prometheus -v ~/prometheus.yml:/etc/prometheus/prometheus.yml quay.io/prometheus/prometheus -config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000

docker 启动node_exporter

docker run -d -p 9100:9100 -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --net="host" --name=node quay.io/prometheus/node-exporter:v0.13.0   -collector.procfs /host/proc   -collector.sysfs /host/sys   -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

解决办法

我试着创建一个docker 网络,然后将prometheus和node_exporter 加入到这个网络中
docker network create -d bridge my-net

docker run -d -p 9090:9090 --name prometheus --network my-net -v ~/prom/prometheus.yml:/etc/prometheus/prometheus.yml quay.io/prometheus/prometheus
docker run -d -p 9100:9100 -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --net="host" --name=node --network my-net quay.io/prometheus/node-exporter:v0.13.0   -collector.procfs /host/proc   -collector.sysfs /host/sys   -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

端口映射不成功问题解决,算是误打误撞吧
通过修改prometheus.yml

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # By default, scrape targets every 15 seconds.

rule_files:
  - "rules/rule.yml"

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['127.0.0.1:9090']
  - job_name: 'node'
    scrape_interval: 8s
    static_configs:
      - targets: ['127.0.0.1:9100']

job_name为node 服务发现的targets应该是机器的外部ip + hostPort

安装 cadvisor

docker run \
  -p=8080:8080 \
  -d \
  --name=cadvisor \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:rw \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  google/cadvisor:latest

修改prometheus.yml,添加cadvisor 数据源

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # By default, scrape targets every 15 seconds.

rule_files:
  - "rules/rule.yml"

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['127.0.0.1:9090']
  - job_name: 'node'
    scrape_interval: 8s
    static_configs:
      - targets: ['127.0.0.1:9100']
  - job_name: 'cadvisor'
    static_configs:
      - targets: ['127.0.0.1:8080']

targets 的值应该是机器的外部ip + cadvisor服务的hostport

你可能感兴趣的:(2018-09-04-docker 安装配置Prometheus+node_exporter+cadvisor)