dcu / mongodb_exporter

MongoDB exporter for prometheus.io
MIT License
356 stars 216 forks source link

Mongodb Exporter doesn't Show the Metrics Using Docker and Prometheus #117

Closed mostafaghadimi closed 5 years ago

mostafaghadimi commented 5 years ago

I'm trying to dockerize mongodb monitoring from the tutorial I have seen in this page.

Here is my Dockerfile configuration:

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] Collecting Oplog Status

1 oplog_status.go:127] Failed to get local.oplog_rs collection stats.

The metrics I should see is this but now I just see the following metrics.

My Metrics

avishefi commented 5 years ago

Try using: -mongodb.uri mongodb://root:example@mongo:27017

pauldintel commented 7 months ago

@mostafaghadimi - have you been able to make this work . ! I still have issue not getting full spectrum of mongo metrics through exporter .

mostafaghadimi commented 7 months ago

@pauldintel Yes, I did. Please share the details about how you deploy your applications. In case of using Docker, there might be network related issues.

pauldintel commented 7 months ago

hi @mostafaghadimi thanks for offering the help . I am using mongo7.0.5, prometheus , nodeexporter , grafana and mongodb exporter in docker container (all inside same network bridge) . Below is the docker specification :

mongodb-exporter: hostname: mongodb-exporter container_name: mongodb-exporter image: mongoexport:prom command: ./mongodb_exporter-linux-amd64 -logtostderr -mongodb.uri mongodb://admin1:password@mongo1:27017/mydb -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:

Please note above mongo1 is the container name and mydb is the db name . the exporter linux utility is used in command line. the issue with the above is I am getting Authentication failed error : the prometheus portal shows mongo exporter is up and running on 9001 port and no issue . But just shows couple of http# metrics and nothing on mongo metrics shown . So my gut feeling is this is because mongo authentication failure.

image

Generally at this moment my thought is those user/password needs to be preexisting on the database. Once I create them in database with admin roles I started getting Panic error plus mongo exporter shows down in prometheus ..

image

So at this moment it is being very strange ! I want to use Grafana dashboard comes pre-shipped with mongo metrics that works on exporter and stuck on implementing that solution.

mostafaghadimi commented 7 months ago

@pauldintel you're welcome. I think you can create user with environment variables and would you please also share your mongodb service in docker-compose file details?

avishefi commented 7 months ago

@pauldintel take a look if this is relevant: https://github.com/dcu/mongodb_exporter/issues/110

I had the same message: panic: runtime error: invalid memory address or nil pointer dereference

I patched according to this comment and it worked.