A Prometheus exporter for MongoDB metrics
Pull the latest version of this image from the Ghost registry. Pulling requires authentication — generate a token and run docker login first (see Authentication below).
The Ghost catalog is public to browse, but pulling images requires an account. Generate a pull token below (or from your Account → Tokens page) — you'll get a ready-to-paste docker login command, then docker pull works.
The username is generated automatically (it looks like robot$<project>+<auto-id>, not the name you typed) and is included in the docker login command above. The secret is shown only once when you create the token.
All Ghost images are signed with cosign. Verifying the signature before deployment ensures the image has not been tampered with.
Install cosign via brew install cosign or download from the Sigstore releases page.
Reference this image in your Dockerfile as a base layer:
All examples in this guide use the public image. If you’ve mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored image instead of the public one.
For example:
registry.ghost-prod.alphabravo.io/ghost-base/<repository>:<tag><your-namespace>/dhi-<repository>:<tag>For the examples, you must first use docker login registry.ghost-prod.alphabravo.io to authenticate to the registry to pull the images.
Note: MongoDB Ghost hardened images are AMD64-tagged images. When running on ARM-based systems using the
--platform linux/amd64 flag, the images will run under emulation, which can significantly impact performance.
Before you run a MongoDB Exporter instance, ensure that you have MongoDB database instance up and running on your system.
# 1. Create network
docker network create mongo-monitoring
# 2. Start MongoDB DHI
docker run -d \
--name mongodb \
--platform linux/amd64 \
--network mongo-monitoring \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb:<tag>-dev \
--bind_ip_all
# Wait for MongoDB to be ready
echo "Waiting for MongoDB to start..."
sleep 15
# Verify MongoDB is running
docker exec mongodb mongosh --eval "db.version()"
# 3. Start MongoDB Exporter DHI
docker run -d \
--name mongodb-exporter \
--network mongo-monitoring \
-p 9216:9216 \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag> \
--mongodb.uri=mongodb://mongodb:27017
# Wait for exporter to connect
sleep 5
# 4. Verify it's working
curl -s http://localhost:9216/metrics | grep mongodb_up
# Expected output: mongodb_up{cluster_role="mongod"} 1
Note: This assumes that you have already mirrored the MongoDB DHI image repository from the catalog to your
organization. MongoDB DHI requires the --bind_ip_all flag to accept connections from other containers. The
--bind_ip_all flag makes MongoDB DHI container listen on 0.0.0.0 (all network interfaces).
If your MongoDB instance requires authentication, provide credentials in the connection URI:
docker run -d \
--name mongodb-exporter \
-p 9216:9216 \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag> \
--mongodb.uri=mongodb://admin:secure_password@mongodb:27017/admin
You can also configure MongoDB Exporter using environment variables:
docker run -d \
--name mongodb-exporter \
-p 9216:9216 \
-e MONGODB_URI=mongodb://admin:secure_password@mongodb:27017/admin \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag>
Available environment variables:
This example shows how to set up MongoDB with authentication and MongoDB Exporter for monitoring:
# 1. Create network and volume
docker network create mongo-monitoring
docker volume create mongodb_data
# 2. Start MongoDB without authentication
docker run -d \
--name mongodb \
--platform linux/amd64 \
--network mongo-monitoring \
-v mongodb_data:/data/db \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb:<tag>-dev \
--bind_ip_all
# Wait for MongoDB to be ready
echo "Waiting for MongoDB to start..."
sleep 15
# Verify MongoDB is running
docker exec mongodb mongosh --eval "db.version()"
# 3. Create admin user
docker exec mongodb mongosh --eval "
db.getSiblingDB('admin').createUser({
user: 'admin',
pwd: 'secure_password',
roles: [{role: 'root', db: 'admin'}]
})
"
# 4. Enable authentication - Restart MongoDB
docker stop mongodb && docker rm mongodb
docker run -d \
--name mongodb \
--network mongo-monitoring \
-p 27017:27017 \
-v mongodb_data:/data/db \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb:<tag>-dev \
--bind_ip_all \
--auth
# Wait for MongoDB with authentication
echo "Waiting for MongoDB with authentication..."
sleep 15
# Verify authentication works
docker exec mongodb mongosh -u admin -p secure_password \
--authenticationDatabase admin --eval "db.version()"
# 5. Start MongoDB Exporter
docker run -d \
--name mongodb-exporter \
--network mongo-monitoring \
-p 9216:9216 \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag> \
--mongodb.uri=mongodb://admin:secure_password@mongodb:27017/admin \
--collector.dbstats \
--collector.collstats
# Wait for exporter to connect
sleep 5
# 6. Verify metrics are being exported
curl -s http://localhost:9216/metrics | grep mongodb_up
# Expected output: mongodb_up{cluster_role="mongod"} 1
--platform linux/amd64--bind_ip_all flag is required for MongoDB to accept connections from other containers. Without
it, MongoDB only binds to 127.0.0.1--auth flag for simple auth setup, or config files for advanced scenariosThe MongoDB Exporter supports various command-line flags to customize its behavior:
docker run -d \
--name mongodb-exporter \
-p 9216:9216 \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag> \
--mongodb.uri=mongodb://admin:secure_password@mongodb:27017/admin \
--collector.dbstats \
--collector.collstats \
--collector.topmetrics \
--collector.indexstats \
--collector.replicasetstatus
Common collectors:
--collector.dbstats - Database statistics--collector.collstats - Collection statistics--collector.topmetrics - Top command metrics--collector.indexstats - Index statistics--collector.replicasetstatus - Replica set status metricsComplete monitoring stack with MongoDB, MongoDB Exporter, and Prometheus:
services:
mongodb:
image: registry.ghost-prod.alphabravo.io/ghost-base/mongodb:<tag>-dev
container_name: mongodb
command: --bind_ip_all --auth
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password
volumes:
- mongodb_data:/data/db
networks:
- monitoring
healthcheck:
test: ["CMD", "mongosh", "-u", "admin", "-p", "password", "--authenticationDatabase", "admin", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
mongodb-exporter:
image: registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag>
container_name: mongodb-exporter
ports:
- "9216:9216"
command:
- --mongodb.uri=mongodb://admin:password@mongodb:27017/admin
- --collector.dbstats
- --collector.collstats
- --collector.topmetrics
depends_on:
mongodb:
condition: service_healthy
networks:
- monitoring
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:9216/metrics"]
interval: 10s
timeout: 5s
retries: 3
prometheus:
image: dockerdevrel/dhi-prometheus:<tag>
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
depends_on:
mongodb-exporter:
condition: service_healthy
networks:
- monitoring
volumes:
mongodb_data:
prometheus_data:
networks:
monitoring:
driver: bridge
prometheus.yml configuration:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'mongodb-exporter'
static_configs:
- targets: ['mongodb-exporter:9216']
scrape_interval: 30s
Once the MongoDB Exporter is running, you can access the metrics:
# View all metrics
curl http://localhost:9216/metrics
# Check MongoDB connectivity
curl -s http://localhost:9216/metrics | grep mongodb_up
# Should return: mongodb_up{cluster_role="mongod"} 1
# Check exporter health
curl http://localhost:9216/metrics | grep mongodb_exporter_build_info
# View database statistics
curl -s http://localhost:9216/metrics | grep mongodb_db
| Feature | MongoDB Exporter (Official) | Docker Hardened MongoDB Exporter |
|---|---|---|
| Security | Standard base with common utilities | Minimal, hardened base with security patches |
| Shell access | Full shell (bash/sh) available | No shell in runtime variants |
| Package manager | package manager available | No package manager in runtime variants |
| User | Runs as specific user | Runs as nonroot user |
| Attack surface | Larger due to additional utilities | Minimal, only essential components |
| Debugging | Traditional shell debugging | Use Docker Debug or Image Mount for troubleshooting |
| Vulnerabilities | Varies by base image | None found (as per current scans) |
Ghost hardened images prioritize security through minimalism:
The hardened images intended for runtime don't contain a shell nor any tools for debugging. Common debugging methods for applications built with Ghost hardened images include:
Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
Using Docker Debug:
docker debug mongodb-exporter
Using Image Mount feature:
docker run --rm -it --pid container:mongodb-exporter \
--mount=type=image,source=registry.ghost-prod.alphabravo.io/ghost-base/busybox,destination=/dbg,ro \
registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:<tag> /dbg/bin/sh
Ghost hardened images come in different variants depending on their intended use.
Runtime variants are designed to run your application in production. These images are intended to be used either directly or as the FROM image in the final stage of a multi-stage build. These images typically:
Build-time variants typically include dev in the variant name and are intended for use in the first stage of a
multi-stage Dockerfile. These images typically:
Note: The MongoDB Exporter DHI currently only provides runtime variants as the exporter is distributed as a pre-built binary.
To migrate your application to a Ghost hardened image, you must update your Dockerfile. At minimum, you must update the base image in your existing Dockerfile to a Ghost hardened image.
| Item | Migration note |
|---|---|
| Base image | Replace your base images in your Dockerfile with a Ghost hardened image. |
| Package management | Non-dev images, intended for runtime, don't contain package managers. Use package managers only in images with a dev tag. |
| Non-root user | By default, non-dev images, intended for runtime, run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. |
| Multi-stage build | Utilize images with a dev tag for build stages and non-dev images for runtime. For binary executables, use a static image for runtime. |
| TLS certificates | Ghost hardened images contain standard TLS certificates by default. There is no need to install TLS certificates. |
| Ports | Non-dev hardened images run as a nonroot user by default. MongoDB Exporter's default port 9216 works without issues as it's above 1024. |
| Entry point | Ghost hardened images may have different entry points than images such as Docker Official Images. Inspect entry points for Ghost hardened images and update your Dockerfile if necessary. |
| No shell | By default, non-dev images, intended for runtime, don't contain a shell. Use dev images in build stages to run shell commands and then copy artifacts to the runtime stage. |
Find hardened images for your app
A hardened image may have several variants. Inspect the image tags and find the image variant that meets your needs.
Update deployment configuration
For MongoDB Exporter, you typically don't need a custom Dockerfile. Update your Docker Compose files, Kubernetes manifests, or Docker run commands to use the hardened image:
# Before
docker run -d -p 9216:9216 percona/mongodb_exporter:0.40 \
--mongodb.uri=mongodb://localhost:27017
# After
docker run -d -p 9216:9216 registry.ghost-prod.alphabravo.io/ghost-base/mongodb-exporter:0.47.1-debian13 \
--mongodb.uri=mongodb://localhost:27017
Verify functionality
After migration, verify that:
# Test metrics endpoint
curl http://localhost:9216/metrics | grep mongodb_up
# Should return: mongodb_up 1
The hardened images intended for runtime don't contain a shell nor any tools for debugging. The recommended method for debugging applications built with Ghost hardened images is to use Docker Debug to attach to these containers. Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
docker debug mongodb-exporter
By default image variants intended for runtime, run as the nonroot user. This typically doesn't cause issues for MongoDB Exporter as it only needs network access and doesn't require file system writes.
MongoDB Exporter uses port 9216 by default, which is above 1024, so there are no privileged port issues. If you need to customize the port, ensure you use a port above 1024:
By default, image variants intended for runtime don't contain a shell. For MongoDB Exporter, all configuration is done via command-line flags or environment variables, so shell access is rarely needed. Use Docker Debug to troubleshoot containers with no shell.
Ghost hardened images may have different entry points than images such as Docker Official Images. Use docker inspect
to inspect entry points for Ghost hardened images and update your configuration if necessary.