{"id":13601001,"url":"https://github.com/percona/mongodb_exporter","last_synced_at":"2026-01-12T07:44:23.434Z","repository":{"id":37686469,"uuid":"55603028","full_name":"percona/mongodb_exporter","owner":"percona","description":"A Prometheus exporter for MongoDB including sharding, replication and storage engines","archived":false,"fork":false,"pushed_at":"2025-05-07T08:26:04.000Z","size":8434,"stargazers_count":1253,"open_issues_count":47,"forks_count":439,"subscribers_count":54,"default_branch":"main","last_synced_at":"2025-05-08T01:48:38.963Z","etag":null,"topics":["go","golang","hacktoberfest","metrics","mongodb","pmm","prometheus","prometheus-exporter"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/percona.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-04-06T12:14:59.000Z","updated_at":"2025-05-06T06:58:02.000Z","dependencies_parsed_at":"2024-03-05T14:25:06.673Z","dependency_job_id":"9f4b5006-0270-4ebd-850d-91ab93db2e3b","html_url":"https://github.com/percona/mongodb_exporter","commit_stats":{"total_commits":397,"total_committers":70,"mean_commits":5.671428571428572,"dds":0.6801007556675063,"last_synced_commit":"e065c155ccc1a9802048d475ee58f3475761173c"},"previous_names":["percona-lab/prometheus_mongodb_exporter"],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/percona%2Fmongodb_exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/percona%2Fmongodb_exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/percona%2Fmongodb_exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/percona%2Fmongodb_exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/percona","download_url":"https://codeload.github.com/percona/mongodb_exporter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259363,"owners_count":22040815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","hacktoberfest","metrics","mongodb","pmm","prometheus","prometheus-exporter"],"created_at":"2024-08-01T18:00:52.216Z","updated_at":"2026-01-12T07:44:23.428Z","avatar_url":"https://github.com/percona.png","language":"Go","funding_links":[],"categories":["Go","Exporters","Repositories"],"sub_categories":["Percona"],"readme":"# MongoDB exporter\n[![Release](https://img.shields.io/github/release/percona/mongodb_exporter.svg?style=flat)](https://github.com/percona/mongodb_exporter/releases/latest)\n[![Build Status](https://github.com/percona/mongodb_exporter/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/percona/mongodb_exporter/actions/workflows/go.yml?query=branch%3Amain)\n[![codecov.io Code Coverage](https://img.shields.io/codecov/c/github/percona/mongodb_exporter.svg?maxAge=2592000)](https://codecov.io/github/percona/mongodb_exporter?branch=main)\n[![Go Report Card](https://goreportcard.com/badge/github.com/percona/mongodb_exporter)](https://goreportcard.com/report/github.com/percona/mongodb_exporter)\n[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/percona/mongodb_exporter/badge)](https://scorecard.dev/viewer/?uri=github.com/percona/mongodb_exporter)\n[![CLA assistant](https://cla-assistant.percona.com/readme/badge/percona/mongodb_exporter)](https://cla-assistant.percona.com/percona/mongodb_exporter)\n[![Forum](https://img.shields.io/badge/Forum-join-brightgreen)](https://forums.percona.com/)\n\n\nThis is the new MongoDB exporter implementation that handles ALL metrics exposed by MongoDB monitoring commands.\nThis new implementation loops over all the fields exposed in diagnostic commands and tries to get data from them.\n\nCurrently, these metric sources are implemented:\n- $collStats\n- $indexStats\n- getDiagnosticData\n- replSetGetStatus\n- replSetGetConfig\n- serverStatus\n\n## Supported MongoDB versions\n\nThe exporter works with Percona Server for MongoDB and MongoDB Community or Enterprise Edition versions 6.0 and newer. Older versions might also work but are not tested anymore.\n\n## Info on Percona MongoDB exporter versions\n\nThe old 0.1x.y version (ex `master` branch) has been moved to the `release-0.1x` branch.\n\nA flag, `--compatible-mode`, which exposes metrics with 0.1x compatible metric\nnames has been implemented which simplifies migration from the old version to\nthe current version.\n\n### Build the exporter\nThe build process uses the dockerized version of goreleaser so you don't need to install Go.\nJust run `make release` and the new binaries will be generated under the build directory.\n```\n├── build\n│ ├── config.yaml\n│ ├── mongodb_exporter_7c73946_checksums.txt\n│ ├── mongodb_exporter-7c73946.darwin-amd64.tar.gz\n│ ├── mongodb_exporter-7c73946.linux-amd64.tar.gz\n│ ├── mongodb_exporter_darwin_amd64\n│ │ └── mongodb_exporter \u003c--- MacOS binary\n│ └── mongodb_exporter_linux_amd64\n│ └── mongodb_exporter \u003c--- Linux binary\n```\n### Running the exporter\nIf you built the exporter using the method mentioned in the previous section, the generated binaries are in `mongodb_exporter_linux_amd64/mongodb_exporter` or `mongodb_exporter_darwin_amd64/mongodb_exporter`\n\n#### Docker\nA docker image is available on the [official percona repository](https://hub.docker.com/r/percona/mongodb_exporter).\n\n##### Examples\n\n```sh\n# with podman\npodman run -d -p 9216:9216 percona/mongodb_exporter:0.40 --mongodb.uri=mongodb://127.0.0.1:17001\n\n# with docker\ndocker run -d -p 9216:9216 percona/mongodb_exporter:0.40 --mongodb.uri=mongodb://127.0.0.1:17001\n```\n\n### Permissions\nConnecting user should have sufficient rights to query needed stats:\n\n```\n      {\n         \"role\":\"clusterMonitor\",\n         \"db\":\"admin\"\n      },\n      {\n         \"role\":\"read\",\n         \"db\":\"local\"\n      }\n```\nWhen using the PBM collector to get metrics from Percona Backup for MongoDB, the user should also have sufficient privileges\nto query the PBM internal collections (in the `admin` database). One option is to grant `find` privileges on the `admin` collection:\n```\nprivileges: [\n        { resource: { db: \"admin\", collection: \"\" }, actions: [ \"find\" ] },\n],\n```\n\nAlternatively, you can grant the `find` privilege for each PBM internal collection (see: https://docs.percona.com/percona-backup-mongodb/details/control-collections.html):\n```\nprivileges: [\n       { resource: { db: \"admin\", collection: \"pbmBackups\" }, actions: [ \"find\" ] },\n       { resource: { db: \"admin\", collection: \"pbmAgents\" }, actions: [ \"find\" ] },\n       { resource: { db: \"admin\", collection: \"pbmConfig\" }, actions: [ \"find\" ] },\n       ...\n],\n```\nHowever, this is not recommended as the list of internal collections may change in future releases.\n\nMore info about roles in MongoDB [documentation](https://docs.mongodb.com/manual/reference/built-in-roles/#mongodb-authrole-clusterMonitor).\n\n#### Example\n```sh\nmongodb_exporter_linux_amd64/mongodb_exporter --mongodb.uri=mongodb://127.0.0.1:17001\n```\n\n#### MongoDB Authentication\nYou can supply the mongodb user/password direct in the `--mongodb.uri=` like `--mongodb.uri=mongodb://user:pass@127.0.0.1:17001`, you can also supply the mongodb user/password with `--mongodb.user=`, `--mongodb.password=`\nbut the user and password info will be leaked via `ps` or `top` command, for security issue, you can use `MONGODB_USER` and `MONGODB_PASSWORD` env variable to set user/password for given uri\n```sh\nMONGODB_USER=XXX MONGODB_PASSWORD=YYY mongodb_exporter_linux_amd64/mongodb_exporter --mongodb.uri=mongodb://127.0.0.1:17001 --mongodb.collstats-colls=db1.c1,db2.c2\n# or\nexport MONGODB_USER=XXX\nexport MONGODB_PASSWORD=YYY\nmongodb_exporter_linux_amd64/mongodb_exporter --mongodb.uri=mongodb://127.0.0.1:17001 --mongodb.collstats-colls=db1.c1,db2.c2\n```\n\n#### Multi-target support\nYou can run the exporter specifying multiple URIs, devided by a comma in --mongodb.uri option or MONGODB_URI environment variable in order to monitor multiple mongodb instances with the a single mongodb_exporter instance.\n```sh\n--mongodb.uri=mongodb://user:pass@127.0.0.1:27017/admin,mongodb://user2:pass2@127.0.0.1:27018/admin\n```\nIn this case you can use the **/scrape** endpoint with the **target** parameter to retreive the specified tartget's metrics.  When querying the data you can use just mongodb://host:port in the target parameter without other parameters and, of course without host credentials\n```sh\nGET /scrape?target=mongodb://127.0.0.1:27018\n```\nIf your URI is prefixed by mongodb:// or mongodb+srv:// schema, any host not prefixed by it after comma is being treated as part of a cluster rather then as a standalone host. Thus clusters and standalone hosts can be combined like this:\n```\n--mongodb.uri=mongodb+srv://user:pass@host1:27017,host2:27017,host3:27017/admin,mongodb://user2:pass2@host4:27018/admin\n```\n\nYou can use the --split-cluster option to split all cluster nodes into separate targets. This mode is useful when cluster nodes are defined as SRV records and the mongodb_exporter is running with mongodb+srv domain specified. In this case SRV records will be queried upon mongodb_exporter start and each cluster node can be queried using the **target** parameter of multitarget endpoint. \n\n#### Overall targets request endpoint\n\nThere is an overall targets endpoint **/scrapeall** that queries all the targets in one request. It can be used to store multiple node metrics without separate target requests. In this case, each node metric will have a **instance** label containing the node name as a host:port pair (or just host if no port was not specified). For example, for mongodb_exporter running with the options:\n```\n--mongodb.uri=\"mongodb://host1:27015,host2:27016\" --split-cluster=true\n``` \nwe get metrics like this:\n```\nmongodb_up{instance=\"host1:27015\"} 1\nmongodb_up{instance=\"host2:27016\"} 1\n```\n\n#### Enabling collstats metrics gathering\n`--mongodb.collstats-colls` receives a list of databases and collections to monitor using collstats.\nUsage example: `--mongodb.collstats-colls=database1.collection1,database2.collection2`\n```sh\nmongodb_exporter_linux_amd64/mongodb_exporter --mongodb.uri=mongodb://127.0.0.1:17001 --mongodb.collstats-colls=db1.c1,db2.c2\n```\n#### Enabling compatibility mode.\nWhen compatibility mode is enabled by the `--compatible-mode`, the exporter will expose all new metrics with the new naming and labeling schema and at the same time will expose metrics in the version 1 compatible way.\nFor example, if compatibility mode is enabled, the metric `mongodb_ss_wt_log_log_bytes_written` (new format)\n```\n# HELP mongodb_ss_wt_log_log_bytes_written serverStatus.wiredTiger.log.\n# TYPE mongodb_ss_wt_log_log_bytes_written untyped\nmongodb_ss_wt_log_log_bytes_written 2.6208e+06\n```\nwill be also exposed as `mongodb_mongod_wiredtiger_log_bytes_total`  with the `unwritten` label.\n```\nHELP mongodb_mongod_wiredtiger_log_bytes_total mongodb_mongod_wiredtiger_log_bytes_total\n# TYPE mongodb_mongod_wiredtiger_log_bytes_total untyped\nmongodb_mongod_wiredtiger_log_bytes_total{type=\"unwritten\"} 2.6208e+06\n```\n#### Enabling profile metrics gathering\n`--collector.profile` \nTo collect metrics, you need to enable the profiler in [MongoDB](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler/):\nUsage example: `db.setProfilingLevel(2)`\n\n|Level|Description|\n|-----|-----------|\n|0| The profiler is off and does not collect any data. This is the default profiler level.|\n|1| The profiler collects data for operations that take longer than the value of `slowms` or that match a filter.\u003cbr\u003e When a filter is set: \u003cul\u003e\u003cli\u003e The `slowms` and `sampleRate` options are not used for profiling.\u003c/li\u003e\u003cli\u003eThe profiler only captures operations that match the filter.\u003c/li\u003e\u003c/ul\u003e\n|2|The profiler collects data for all operations.|\n\n#### Enabling shards metrics gathering\nWhen shard metrics collection is enabled by `--collector.shards`, the exporter will expose metrics related to sharded Mongo. \nExample, if shards collector is enabled:\n```\n# HELP mongodb_shards_collection_chunks_count sharded collection chunks.\n# TYPE mongodb_shards_collection_chunks_count counter\nmongodb_shards_collection_chunks_count{collection=\"system.sessions\",database=\"config\",shard=\"rs1\"} 250\nmongodb_shards_collection_chunks_count{collection=\"system.sessions\",database=\"config\",shard=\"rs2\"} 250\n```\nYou can see shard name, it's collection, database and count.\n\n#### Cluster role labels\nThe exporter sets some topology labels in all metrics.\nThe labels are:\n\n- cl_role: Cluster role according to this table:\n\n|Server type|Label|\n|-----|-----|\n|mongos|mongos|\n|regular instance (primary or secondary)|shardsvr|\n|arbiter|shardsvr|\n|standalone|(empty string)|\n\n- cl_id: Cluster ID\n- rs_nm: Replicaset name\n- rs_state: Replicaset state is an integer from `getDiagnosticData()` -\u003e `replSetGetStatus.myState`. \nCheck [the official documentation](https://docs.mongodb.com/manual/reference/replica-states/) for details on replicaset status values.\n\n## Usage Reference\n\nSee the [Reference Guide](REFERENCE.md) for details on using the exporter.\n## Bug Reports / Feature PR\n\nRefer to the [Contribution Guide](CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpercona%2Fmongodb_exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpercona%2Fmongodb_exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpercona%2Fmongodb_exporter/lists"}