diff --git a/mongo/changelog.d/20819.added b/mongo/changelog.d/20819.added new file mode 100644 index 0000000000000..c11487872f2f8 --- /dev/null +++ b/mongo/changelog.d/20819.added @@ -0,0 +1 @@ +Collect index stats metric `mongodb.collection.indexes.accesses.opsps` on replica set secondary nodes. diff --git a/mongo/datadog_checks/mongo/collectors/index_stats.py b/mongo/datadog_checks/mongo/collectors/index_stats.py index 397467328f7ad..993ac4095fbe8 100644 --- a/mongo/datadog_checks/mongo/collectors/index_stats.py +++ b/mongo/datadog_checks/mongo/collectors/index_stats.py @@ -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 @@ -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): diff --git a/mongo/tests/test_integration.py b/mongo/tests/test_integration.py index ee553834c64c1..732c6fd9e6804 100644 --- a/mongo/tests/test_integration.py +++ b/mongo/tests/test_integration.py @@ -782,6 +782,7 @@ def test_integration_replicaset_secondary( 'dbstats-local', 'fsynclock', 'hostinfo', + 'indexes-stats', ] if collect_custom_queries: metrics_categories.append('custom-queries')