Skip to content

[DBMON-5536] collect index stats on replica set secondaries #20819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mongo/changelog.d/20819.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Collect index stats metric `mongodb.collection.indexes.accesses.opsps` on replica set secondary nodes.
12 changes: 11 additions & 1 deletion mongo/datadog_checks/mongo/collectors/index_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pymongo.errors import OperationFailure

from datadog_checks.mongo.collectors.base import MongoCollector, collection_interval_checker
from datadog_checks.mongo.common import ReplicaSetDeployment
from datadog_checks.mongo.metrics import INDEX_METRICS


Expand All @@ -20,7 +21,16 @@ def __init__(self, check, db_name, tags, coll_names=None):
self._collector_key = (self.__class__.__name__, db_name) # db_name is part of collector key

def compatible_with(self, deployment):
# Can only be run once per cluster.
if isinstance(deployment, ReplicaSetDeployment):
# Collecting index stats on both primary and secondary nodes for replica set
if deployment.is_arbiter:
self.log.debug("IndexStatsCollector can not be run on arbiter nodes.")
return False
if deployment.use_shards:
self.log.debug("IndexStatsCollector can not be run on shards on sharded clusters.")
return False
return True
# Collecting index stats for standalone or mongos on sharding deployments
return deployment.is_principal()

def _get_collections(self, api):
Expand Down
1 change: 1 addition & 0 deletions mongo/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ def test_integration_replicaset_secondary(
'dbstats-local',
'fsynclock',
'hostinfo',
'indexes-stats',
]
if collect_custom_queries:
metrics_categories.append('custom-queries')
Expand Down
Loading