Mongodb Exporter不使用Docker和Prometheus显示指标

时间:2019-08-10 10:24:43

标签: mongodb docker dockerfile monitoring prometheus

我正在尝试从this page中看到的教程中对mongodb监控进行docker化。

这是我的Dockerfile配置:

FROM alpine
RUN apk update && apk add wget && rm -rf /var/cache/apk/*
RUN wget https://github.com/dcu/mongodb_exporter/releases/download/v1.0.0/mongodb_exporter-linux-amd64
RUN chmod 777 mongodb_exporter-linux-amd64
EXPOSE 9001

Prometheus.yml:

global:
    scrape_interval: 15s
    external_labels:
        monitor: 'my-monitor'
scrape_configs:
    - job_name: 'mongodb-exporter'
      static_configs:
          - targets: ['mongodb-exporter:9001']

docker-compose.yml:

version: '3'

services: 
  mongo:
    image: mongo
    container_name: mongo
    restart: always
    environment: 
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

  prometheus:
    image: prom/prometheus
    restart: always
    ports:
      - 9090:9090
    volumes:
      - /home/mostafa/Desktop/docker_lab/mongo/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command: 
      - '--config.file=/etc/prometheus/prometheus.yml'

  mongodb-exporter:
    build: .
    command: ./mongodb_exporter-linux-amd64 -logtostderr -mongodb.uri mongodb://root:example@mongo:27017 -groups.enabled 'asserts,durability,background_flusshing,connections,extra_info,global_lock,index_counters,network,op_counters,op_counters_repl,memory,locks,metrics'
    restart: always
    ports: 
      - 9001:9001
  

1 mongodb_collector.go:70]收集Oplog状态

     

1 oplog_status.go:127]无法获取local.oplog_rs集合统计信息。

我应该看到的指标是this,但现在我只看到以下指标。

My Metrics

1 个答案:

答案 0 :(得分:3)

运行mongodb_exporter时使用的IP /主机名错误。

尝试使用docker-compose.yml文件中的Mongo DB容器名称代替127.0.0.1。在您的情况下,使用mongo

完整的URI应该是:mongodb://root:example@mongo:27017

关于Failed to get local.oplog_rs collection stats.错误,您需要为用于刮取数据库的用户帐户授予适当的权限,请参见详细信息in this blog post