MongoDB collstats metricset
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
This is the collstats metricset of the module mongodb.
The collstats metricset collects collection-level operational and storage statistics from MongoDB. It transparently uses either the deprecated collStats database command (legacy) or the $collStats aggregation stage (MongoDB 6.2+) depending on server version and feature availability.
Notes:
- For sharded clusters, stats from multiple shards are merged. The metricset reports an aggregate view and exposes a
shardCountsummary. It does not emit a per-shard breakdown (noshards.*). - Index size details (the
indexSizes.*map) are intentionally not collected at this time.
The collstats metricset uses the top administrative command to return usage statistics for each collection. It provides the amount of time, in microseconds, used and a count of operations for the following types:
- total
- readLock
- writeLock
- queries
- getmore
- insert
- update
- remove
- commands
It requires the following privileges, which is covered by the clusterMonitor role:
topaction onclusterresourcecollStatsaction on collection resourcesaggregateaction on collection resources (for MongoDB 6.2+)
On mongos routers, the top command is not available. In such cases, only storage statistics are populated. Operation counters (for example: total, read, write, and query) may be absent.
Optional settings for this metricset:
scale(integer, default: 1): Server-side scale factor for size values reported bycollStats/$collStats(for example, set to1024to receive sizes in KiB). Values are not rescaled client-side.
This is a default metricset. If the host module is unconfigured, this metricset is enabled by default.
For a description of each field in the metricset, see the exported fields section.
Here is an example document generated by this metricset:
{
"@timestamp": "2025-09-22T08:38:56.429Z",
"event": {
"dataset": "mongodb.collstats",
"duration": 31226375,
"module": "mongodb"
},
"metricset": {
"name": "collstats",
"period": 60000
},
"mongodb": {
"collstats": {
"collection": "users",
"commands": {
"count": 6,
"time": {
"us": 67484
}
},
"db": "testdb",
"getmore": {
"count": 0,
"time": {
"us": 0
}
},
"insert": {
"count": 1,
"time": {
"us": 4080
}
},
"lock": {
"read": {
"count": 3,
"time": {
"us": 2167
}
},
"write": {
"count": 4,
"time": {
"us": 69397
}
}
},
"name": "testdb.users",
"queries": {
"count": 0,
"time": {
"us": 0
}
},
"remove": {
"count": 0,
"time": {
"us": 0
}
},
"stats": {
"avgObjSize": 67,
"capped": false,
"count": 5,
"freeStorageSize": 0,
"nindexes": 4,
"numOrphanDocs": 0,
"scaleFactor": 1,
"size": 336,
"storageSize": 4096,
"totalIndexSize": 65536,
"totalSize": 69632
},
"total": {
"count": 7,
"time": {
"us": 71564
}
},
"update": {
"count": 0,
"time": {
"us": 0
}
}
}
},
"service": {
"address": "mongodb://localhost:27017",
"type": "mongodb"
}
}