A Prometheus exporter for MongoDB including sharding, replication and storage engines
| :warning: WARNING | |:-------------------------------------------------------------------------------------------------------------------------------------------------| | We switching to the new branch. Please use https://github.com/percona/mongodbexporter/tree/exporterv2 and read more about the new version of the mongodb_exporter at https://www.percona.com/blog/2020/09/22/new-mongodb-exporter-released-with-percona-monitoring-and-management-2-10-0/ |
Based on MongoDB exporter by David Cuadrado (@dcu), but forked for full sharded support and structure changes.
Metrics
mongodb_mongod_replset_oplog_*doesn't work in Master/Slave replication mode, because it was DEPRECATED in MongoDB
3.2and removed in
4.0.
Get the code from the Percona repository:
go get -u github.com/percona/mongodb_exporter
Switch to the buld directory and just run
maketo install all needed tools, format code with
go fmt, build a binary for your OS and run tests.:
cd ${GOPATH-$HOME/go}/src/github.com/percona/mongodb_exporter make
Note: Running tests requires
docker(as it uses MongoDB) and
docker-compose, and you will also need free
27017port, as
docker-composemaps this port into your host OS while testing.
If you want just build a binary for your OS without codestyle checks and tests you can run command below:
make build
If you don't have or don't want to install the whole GO stuff, use this docker build that creates a container with a freshly built
mongodb_exporterbinary:
make docker
To define your own MongoDB URL, use environment variable
MONGODB_URI. If set this variable takes precedence over
--mongodb.uriflag.
To enable HTTP basic authentication, set environment variable
HTTP_AUTHto user:password pair. Alternatively, you can use YAML file with
server_userand
server_passwordfields.
export MONGODB_URI='mongodb://localhost:27017' export HTTP_AUTH='user:password' ./bin/mongodb_exporter []
If you are using hidden nodes, connect to them using the
connect=directoption. Example:
./mongodb_exporter --mongodb.uri=admin:[email protected]:17003/admin/?connect=direct
You can use the chart prometheus-mongodb-exporter from helm stable repository.
See the help page with
-h.
If you use MongoDB Authorization, you must:
Create a user with 'clusterMonitor' role and 'read' on the 'local' database, like the following (replace username/password!):
db.getSiblingDB("admin").createUser({ user: "mongodb_exporter", pwd: "s3cr3tpassw0rd", roles: [ { role: "clusterMonitor", db: "admin" }, { role: "read", db: "local" } ] })
Set environment variable
MONGODB_URIbefore starting the exporter:
export MONGODB_URI=mongodb://mongodb_exporter:[email protected]:27017
If you use x.509 Certificates to Authenticate Clients, pass in username and
authMechanismvia connection options to the MongoDB uri. Eg:
mongodb://CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,[email protected]:27017/?authMechanism=MONGODB-X509
Point the process to any mongo port and it will detect if it is a mongos, replicaset member, or stand alone mongod and return the appropriate metrics for that type of node. This was done to prevent the need to an exporter per type of process.
If you find a bug in Percona MongoDB Exporter or one of the related projects, you should submit a report to that project's JIRA issue tracker.
Your first step should be to search the existing set of open tickets for a similar report. If you find that someone else has already reported your problem, then you can upvote that report to increase its visibility.
If there is no existing report, submit a report following these steps:
An excellent resource is Elika Etemad's article on filing good bug reports..
As a general rule of thumb, please try to create bug reports that are: