<!-- llms-explorer concept facts · https://llms-explorer.com/tree/exporting-indexstats-metrics-with-mongodb-exporter-and-pmm/ · pack 2026-10-31 · ~2031 tokens -->

# Exporting $indexStats metrics with mongodb_exporter and PMM

> Source-anchored research for Exporting $indexStats metrics with mongodb_exporter and PMM. Run status: COMPLETED.

Parent: [Unused index detection with $indexStats](https://llms-explorer.com/tree/unused-index-detection-with-indexstats/) · 5 facets · 17 facts · page: https://llms-explorer.com/tree/exporting-indexstats-metrics-with-mongodb-exporter-and-pmm/

## Structure and components

- Inspect the actual /metrics exposition when validating export: Prometheus text samples consist of a metric name, optional labels and a numeric value, with optional HELP and TYPE lines. Prometheus requires each metric-name/label combination to be unique. The exporter reference shows --web.telemetry-path="/metrics" as an example. (high confidence) — [source](https://prometheus.io/docs/instrumenting/exposition_formats/)

## How it works

- The exporter README recommends clusterMonitor on admin and read on local for its monitoring user; MongoDB documents clusterMonitor as sufficient for the $indexStats stage itself. Check permissions for the enabled collector set when diagnosing missing index-use metrics. (high confidence) — [source](https://github.com/percona/mongodb_exporter)
- The index-use metric identified by Percona support is mongodb_indexstats_accesses_ops. The collector attaches database, collection and key_name labels, plus topology labels and a shard label when applicable; preserve these dimensions when checking whether a specific index has an exported series. (high confidence) (verified as of 2026-10-30) — [source](https://forums.percona.com/t/view-index-usage/26802)
- MongoDB $indexStats accesses.ops counts user operations that used an index on the node where statistics are collected; it excludes internal uses such as TTL deletions and replication. Because the exporter reads $indexStats, its operation metric inherits that scope. A zero count on one observed node is therefore insufficient evidence that an index is unused throughout the deployment. (high confidence) — [source](https://www.mongodb.com/docs/v8.0/reference/operator/aggregation/indexstats/)
- Exporter PR #1321 documents PMM-15198: scraping $indexStats through mongos produced identical label sets for different shards, causing duplicate-metric errors and discarded shard statistics. The fix adds shard labels, and the v0.53.0 release lists that fix. This is a concrete version-specific cause of incomplete export even with indexstats enabled. (high confidence) — [source](https://github.com/percona/mongodb_exporter/pull/1321)

## Problems, failure modes and limitations

- Percona identifies mongodb_indexstats_accesses_ops as the index-usage metric. A PMM 3.6.0 scrape-error log shows database, collection, and key_name labels, plus cl_role; verify the actual exported labels before writing selectors. (medium confidence) (verified as of 2026-03-20) — [source](https://forums.percona.com/t/view-index-usage/26802)
- PMM exposes --stats-collections to scope namespaces and --max-collections-limit to control collection-count limits; zero removes that limit. The standalone exporter uses --collector.collstats-limit, which also gates indexstats. A collection limit can therefore suppress usage metrics even when the collector is enabled. (high confidence) (verified as of 2026-10-30) — [source](https://docs.percona.com/percona-monitoring-and-management/2/details/commands/pmm-admin.html)
- A March 2026 PMM 3.6.0 operator deployment reported duplicate mongodb_indexstats_accesses_ops samples from mongos, with the error "was collected before with the same name and label values". The reporter confirmed --disable-collectors=indexstats on mongos as a workaround. This is a historical report, not evidence that every later release is affected. (low confidence) (verified as of 2026-03-23) — [source](https://forums.percona.com/t/mongodb-instance-summary-dashboard-shows-no-data-for-mongos-services-on-pmm-3-6-0/40383)
- PMM 2 --stats-collections accepts comma-separated database[.collection] namespaces to scope indexstats and collstats. The documentation warns that enabling all collectors can significantly increase memory use in sharded or collection-heavy deployments. This warning concerns the enabled collector set and does not quantify indexstats-only overhead; scope the required namespaces and verify exported series before broadening collection. (medium confidence) (verified as of 2026-10-29) — [source](https://docs.percona.com/percona-monitoring-and-management/2/details/commands/pmm-admin.html)
- A March 31, 2026 AWS DocumentDB issue reports indexstats failing during collection discovery with the literal error "Field 'type' is currently not supported", including attempts with explicit collection lists and discovery disabled. Treat this as a reported compatibility limitation for that environment, not proof that MongoDB $indexStats itself is unavailable or that all DocumentDB versions fail. (low confidence) — [source](https://github.com/percona/mongodb_exporter/issues/1264)

## Comparisons and alternatives

- PMM 2 documents indexstats as an optional collector. When registering a MongoDB service, --enable-all-collectors enables it; --disable-collectors excludes named collectors. PMM registration flags differ from standalone mongodb_exporter flags, so --collector.indexstats is not the documented pmm-admin activation flag. (high confidence) (verified as of 2026-10-29) — [source](https://docs.percona.com/percona-monitoring-and-management/2/details/commands/pmm-admin.html)
- Prometheus text exposition requires each metric-name and label combination to be unique. Consequently, exporter results for different shard hosts must remain distinguishable; the PMM mongos duplicate-series report illustrates a violation rather than zero index usage. (high confidence) — [source](https://prometheus.io/docs/instrumenting/exposition_formats/)
- PMM 2 --max-collections-limit can disable indexstats and other collection-level collectors when the collection count exceeds the limit. Zero removes the limit; -1 delegates the limit to PMM. The standalone exporter exposes the corresponding limit as --collector.collstats-limit, whose inspected default is zero. Thus an absent index-use series can mean collection was suppressed rather than that index usage was zero. (high confidence) (verified as of 2026-10-29) — [source](https://docs.percona.com/percona-monitoring-and-management/2/details/commands/pmm-admin.html)

## Facts and statements

- Percona mongodb_exporter implements a collector backed by MongoDB $indexStats. Enable it explicitly with --collector.indexstats; --collect-all enables all standalone exporter collectors. Select collections with --mongodb.indexstats-colls=db1.col1,db2.col2, or use --discovering-mode for collection discovery. (high confidence) (verified as of 2026-10-30) — [source](https://github.com/percona/mongodb_exporter)
- Enabling all collectors can increase exporter CPU and memory costs, especially for numerous collections or sharding. PMM documents namespace scoping and places indexstats among its slower, low-resolution collectors. (low confidence) (verified as of 2026-10-30) — [source](https://docs.percona.com/percona-monitoring-and-management/2/details/commands/pmm-admin.html)
- An exported $indexStats accesses.ops value represents user operations using an index, excluding TTL deletion and replication/internal work. MongoDB resets these statistics after restart, index recreation, or index modification; exporting them does not change those source semantics. (medium confidence) — [source](https://www.mongodb.com/docs/v8.0/reference/operator/aggregation/indexstats/)
- In the inspected collector, sanitizeMetrics retains accesses.ops and optional building, and omits accesses.since from the exported document. MongoDB itself supplies accesses.since, so this exporter output does not by itself expose the full $indexStats result or its statistics-start timestamp. (high confidence) (verified as of 2026-10-30) — [source](https://github.com/percona/mongodb_exporter/blob/main/exporter/indexstats_collector.go)
