Mongodb Exporter 不显示使用 Docker 和 Prometheus 的指标
Mongodb Exporter doesn't Show the Metrics Using Docker and Prometheus
我正在尝试 docker 调整 mongodb 我在 this page 中看到的教程中的监控。
这是我的 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] Collecting Oplog Status
1 oplog_status.go:127] Failed to get local.oplog_rs collection stats.
我应该看到的指标是 this 但现在我只看到以下指标。
您在 运行 和 mongodb_exporter 时使用了错误的 IP/hostname。
而不是 127.0.0.1
,尝试使用 Mongo 数据库的容器名称,就像在 docker-compose.yml 文件中一样,在您的情况下是mongo
.
完整的 URI 应该是:mongodb://root:example@mongo:27017
关于 Failed to get local.oplog_rs collection stats.
错误,您需要为用于抓取数据库的用户帐户授予适当的权限,请参阅详细信息 in this blog post。
我正在尝试 docker 调整 mongodb 我在 this page 中看到的教程中的监控。
这是我的 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] Collecting Oplog Status
1 oplog_status.go:127] Failed to get local.oplog_rs collection stats.
我应该看到的指标是 this 但现在我只看到以下指标。
您在 运行 和 mongodb_exporter 时使用了错误的 IP/hostname。
而不是 127.0.0.1
,尝试使用 Mongo 数据库的容器名称,就像在 docker-compose.yml 文件中一样,在您的情况下是mongo
.
完整的 URI 应该是:mongodb://root:example@mongo:27017
关于 Failed to get local.oplog_rs collection stats.
错误,您需要为用于抓取数据库的用户帐户授予适当的权限,请参阅详细信息 in this blog post。