-
Notifications
You must be signed in to change notification settings - Fork 450
Description
Description
When running mongodb_exporter directly via the command line, it connects to MongoDB successfully and exposes metrics (verifiable via curl). However, when starting the exporter as a systemd service with the same connection URI, it fails with a "no such host" error (the exporter incorrectly parses the host as mongodb instead of 127.0.0.1:27018).
Version Information
- MongoDB version: 3.6.12
- mongodb_exporter version: v0.44.0 (linux-amd64)
- OS: Linux (RHEL/CentOS 7, systemd-based)
Steps to Reproduce
1. Command line execution (WORKS):
Execute the exporter directly in the terminal – it runs successfully and metrics are accessible via curl http://localhost:9216/metrics:
[root@mongos1 mongodb_exporter-0.44.0.linux-amd64]# ./mongodb_exporter --mongodb.uri=mongodb://dbs_admin:mypwd@127.0.0.1:27018/admin?authSource=admin --collector.dbstats
2. Systemd service configuration (FAIL):
Create /etc/systemd/system/mongodb_exporter.service:
[Unit]
Description=Prometheus MongoDB Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=mongodb_exporter
Group=mongodb_exporter
Type=simple
Restart=on-failure
ExecStart=/usr/local/bin/mongodb_exporter--collector.dbstats
--mongodb.uri="mongodb://dbs_admin:mypwd@127.0.0.1:27018/admin?authSource=admin"
--collector.dbstats
--web.listen-address=:9216
CPUQuota=20%
MemoryLimit=300M
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
[Install]
WantedBy=multi-user.target
3. Start systemd service:
systemctl daemon-reload
systemctl start mongodb_exporter.service
Logs
Full error log from journalctl -u mongodb_exporter.service:
mongodb exporter: time="2025-12-03T16:47:30+08:00" level=error msg="Cannot connect to MongoDB: cannot connect to MongoDB: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: "mongodb, Type: Unknown, Last error: dial tcp: lookup "mongodb: no such host }, ] }"