Loading

MongoDB collstats metricset

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 shardCount summary. It does not emit a per-shard breakdown (no shards.*).
  • 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:

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 by collStats/$collStats (for example, set to 1024 to 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"
    }
}