Search code examples
linuxmongodbsslexporter

Mongodb Exporter as a Service in linux


I'm trying to install mongodb exporter using this github link: https://github.com/percona/mongodb_exporter

I follow this link for instruction https://www.percona.com/blog/2020/04/17/how-to-configure-mongodb-exporter-with-ssl-tls/

So far no problem, I can use the "mongodb_exporter" binary file alone to execute and successfully connected to mongo by executing

mongodb_exporter --mongodb.uri=mongodb://user:password@localhost:27017?ssl=true&sslclientcertificatekeyfile=/etc/ssl/mongo.pem&sslinsecure=true&sslcertificateauthorityfile=/etc/ssl/mongo.pem

But to run this binary file as a service, I create a mongodb_exporter.service in /etc/systemd/system folder.

Here is the content of the service's file:

[Unit]
Description=Mongodb Exporter
After=network-online.target

[Service]
User=mongodb_exporter
Group=mongodb_exporter
Type=simple
EnvironmentFile=/etc/.mongodb_exporterconf
ExecStart=/usr/local/bin/mongodb_exporter $ARG1

[Install]
WantedBy=multi-user.target

As you notice, there is .mongodb_exporterconf file that I created earlier and then assign the ARG1 variable the flag "--mongodb.uri" above

When I check the status of this service, it throws this error error msg="Can't create mongo session to mongodb://****:password@localhost:27017?&sslclientcertificatekeyfile=/etc/ssl/mongo.pem&sslinsecure=true&sslcertificateauthorityfile=/etc/ssl/mongo.pem" source="mongodb_collector.go:188"

For the moment I have no idea what I missed, but there's only 1 clue I found but I'm not so sure, is that the error message didn't show or skipped the "ssl=true" option. Or I just missed some configuration. Any idea or help is appreciated!


Solution

  • Turns out that I just need --mongodb.uri=mongodb://user:password@localhost:27017?ssl=true, the other options are optional.