Skip to content

Commit b90d83a

Browse files
authored
[DBMON-5536] collect index stats on replica set secondaries (DataDog#20819)
* collect index stats on replica set secondaries * add changelog
1 parent 625511c commit b90d83a

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

mongo/changelog.d/20819.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Collect index stats metric `mongodb.collection.indexes.accesses.opsps` on replica set secondary nodes.

mongo/datadog_checks/mongo/collectors/index_stats.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pymongo.errors import OperationFailure
66

77
from datadog_checks.mongo.collectors.base import MongoCollector, collection_interval_checker
8+
from datadog_checks.mongo.common import ReplicaSetDeployment
89
from datadog_checks.mongo.metrics import INDEX_METRICS
910

1011

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

2223
def compatible_with(self, deployment):
23-
# Can only be run once per cluster.
24+
if isinstance(deployment, ReplicaSetDeployment):
25+
# Collecting index stats on both primary and secondary nodes for replica set
26+
if deployment.is_arbiter:
27+
self.log.debug("IndexStatsCollector can not be run on arbiter nodes.")
28+
return False
29+
if deployment.use_shards:
30+
self.log.debug("IndexStatsCollector can not be run on shards on sharded clusters.")
31+
return False
32+
return True
33+
# Collecting index stats for standalone or mongos on sharding deployments
2434
return deployment.is_principal()
2535

2636
def _get_collections(self, api):

mongo/tests/test_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ def test_integration_replicaset_secondary(
782782
'dbstats-local',
783783
'fsynclock',
784784
'hostinfo',
785+
'indexes-stats',
785786
]
786787
if collect_custom_queries:
787788
metrics_categories.append('custom-queries')

0 commit comments

Comments
 (0)