Classic MongoDB Exporter
This is a fork of version 0.11.2 of the Percona MongoDB Exporter, which just got some dependency updates.
Percona MongoDB Exporter is based on MongoDB exporter by David Cuadrado (@dcu), but forked for full sharded support and structure changes.
Features
- MongoDB Server Status metrics (cursors, operations, indexes, storage, etc)
- MongoDB Replica Set metrics (members, ping, replication lag, etc)
- MongoDB Replication Oplog metrics (size, length in time, etc)
- MongoDB Sharding metrics (shards, chunks, db/collections, balancer operations)
- MongoDB RocksDB storage-engine metrics (levels, compactions, cache usage, i/o rates, etc)
- MongoDB WiredTiger storage-engine metrics (cache, blockmanger, tickets, etc)
- MongoDB Top Metrics per collection (writeLock, readLock, query, etc*)
Important Note
Metrics mongodb_mongod_replset_oplog_*
doesn't work in Master/Slave replication mode, because it was DEPRECATED in MongoDB 3.2
and removed in 4.0
.
Building and running
Prerequisites:
- Go compiler
- Docker and Docker Compose
Building
-
Get the code from the Percona repository:
go get -u github.com/monotek/mongodb-exporter
-
Switch to the buld directory and just run
make
to install all needed tools, format code withgo fmt
, build a binary for your OS and run tests.:cd ${GOPATH-$HOME/go}/src/github.com/monotek/mongodb-exporter make
Note: Running tests requires
docker
(as it uses MongoDB) anddocker-compose
, and you will also need free27017
port, asdocker-compose
maps 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_exporter
binary:make docker
-
Running
To define your own MongoDB URL, use environment variable MONGODB_URI
. If set this variable takes precedence over --mongodb.uri
flag.
To enable HTTP basic authentication, set environment variable HTTP_AUTH
to user:password pair. Alternatively, you can
use YAML file with server_user
and server_password
fields.
export MONGODB_URI='mongodb://localhost:27017'
export HTTP_AUTH='user:password'
./bin/mongodb_exporter [<flags>]
If you are using hidden nodes, connect to them using the connect=direct
option. Example:
./mongodb_exporter --mongodb.uri=admin:admin123456@127.0.0.3:17003/admin/?connect=direct
Kubernetes
You can use the chart prometheus-mongodb-exporter from helm stable repository.
Flags
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_URI
before starting the exporter:export MONGODB_URI=mongodb://mongodb_exporter:s3cr3tpassw0rd@localhost:27017
If you use x.509 Certificates to Authenticate Clients, pass in username and authMechanism
via connection options to the MongoDB uri. Eg:
mongodb://CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry@localhost:27017/?authMechanism=MONGODB-X509
Note about how this works
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.
Roadmap
- just maintenance