简体   繁体   English

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

[英]Mongodb Exporter doesn't Show the Metrics Using Docker and Prometheus

I'm trying to dockerize mongodb monitoring from the tutorial I have seen in this page . 我正在尝试从本页面中看到的教程中对mongodb监控进行docker化。

Here is my Dockerfile configuration: 这是我的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: 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: 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] Collecting Oplog Status 1 mongodb_collector.go:70]收集操作日志状态

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

The metrics I should see is this but now I just see the following metrics. 我应该看到的指标是这个,但现在我只看到以下指标。

我的指标

You're using the wrong IP/hostname when running the mongodb_exporter. 运行mongodb_exporter时使用的IP /主机名错误。

Instead of 127.0.0.1 , try using the name of the container of your Mongo DB as you have in the docker-compose.yml file, in your case it's mongo . 尝试使用docker-compose.yml文件中的Mongo数据库容器名称代替127.0.0.1 ,在本例中为mongo

The full URI should be: mongodb://root:example@mongo:27017 完整的URI应该是: mongodb://root:example@mongo:27017

Regarding the Failed to get local.oplog_rs collection stats. 关于Failed to get local.oplog_rs collection stats. error, you need to give proper permissions to the user account that you use to scrape the DB, see details in this blog post . 错误,您需要为用于刮取数据库的用户帐户授予适当的权限,请参阅此博客文章中的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM