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.
You're using the wrong IP/hostname when running the mongodb_exporter.
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
.
The full URI should be: mongodb://root:example@mongo:27017
Regarding the 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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.