diff --git a/mongo/changelog.d/18405.added b/mongo/changelog.d/18405.added new file mode 100644 index 0000000000000..8b86ac94ea25e --- /dev/null +++ b/mongo/changelog.d/18405.added @@ -0,0 +1 @@ +Add metric `mongodb.collection.indexes.accesses.opsps` to measure number of times the index was used per second. diff --git a/mongo/datadog_checks/mongo/collectors/base.py b/mongo/datadog_checks/mongo/collectors/base.py index 4bf49f201b1c8..27f3b92407f87 100644 --- a/mongo/datadog_checks/mongo/collectors/base.py +++ b/mongo/datadog_checks/mongo/collectors/base.py @@ -124,6 +124,6 @@ def _submit_payload(self, payload, additional_tags=None, metrics_to_collect=None metric_name_alias = self._normalize(metric_name_alias, submit_method, prefix) submit_method(self.check, metric_name_alias, value, tags=tags) - if metric_name_alias.endswith("countps"): - # Keep old incorrect metric name (only 'top' metrics are affected) + if metric_name_alias.endswith("countps") or metric_name_alias.endswith("accesses.opsps"): + # Keep old incorrect metric name (only 'top' and 'index' metrics are affected) self.gauge(metric_name_alias[:-2], value, tags=tags) diff --git a/mongo/datadog_checks/mongo/collectors/index_stats.py b/mongo/datadog_checks/mongo/collectors/index_stats.py index b0d0f4976e35f..912530138a026 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 +from datadog_checks.mongo.metrics import INDEX_METRICS class IndexStatsCollector(MongoCollector): @@ -29,13 +30,14 @@ def collect(self, api): for coll_name in coll_names: try: for stats in api.index_stats(self.db_name, coll_name): - idx_tags = self.base_tags + [ + additional_tags = [ "name:{0}".format(stats.get('name', 'unknown')), "collection:{0}".format(coll_name), "db:{0}".format(self.db_name), ] - val = int(stats.get('accesses', {}).get('ops', 0)) - self.gauge('mongodb.collection.indexes.accesses.ops', val, idx_tags) + if stats.get('shard'): + additional_tags.append("shard:{0}".format(stats['shard'])) + self._submit_payload({"indexes": stats}, additional_tags, INDEX_METRICS, "collection") except OperationFailure as e: # Atlas restricts $indexStats on system collections self.log.warning("Could not collect index stats for collection %s: %s", coll_name, e) diff --git a/mongo/datadog_checks/mongo/metrics.py b/mongo/datadog_checks/mongo/metrics.py index d735677b4dd35..b1e731afe9349 100644 --- a/mongo/datadog_checks/mongo/metrics.py +++ b/mongo/datadog_checks/mongo/metrics.py @@ -357,6 +357,10 @@ 'collection.collectionScans.nonTailable': GAUGE, } +INDEX_METRICS = { + 'indexes.accesses.ops': RATE, +} + """ Mapping for case-sensitive metric name suffixes. diff --git a/mongo/metadata.csv b/mongo/metadata.csv index 862d461b62089..66e00ae0cba9b 100644 --- a/mongo/metadata.csv +++ b/mongo/metadata.csv @@ -19,6 +19,7 @@ mongodb.collection.commands.latency.avg,gauge,,microsecond,,Average latency for mongodb.collection.commands.opsps,gauge,,operation,second,Number of command operations per second on the collection.,0,mongodb,command operations per second,, mongodb.collection.count,gauge,,item,,Total number of objects in the collection.,0,mongodb,number of objects in the collection,, mongodb.collection.indexes.accesses.ops,gauge,,event,,Number of time the index was used.,0,mongodb,index usage,, +mongodb.collection.indexes.accesses.opsps,gauge,,event,,Number of time the index was used per second.,0,mongodb,index usage per second,, mongodb.collection.indexsizes,gauge,,byte,,Size of index in bytes.,0,mongodb,index size,, mongodb.collection.max,gauge,,document,,Maximum number of documents in a capped collection.,0,mongodb,max documents in capped collection,, mongodb.collection.maxsize,gauge,,byte,,Maximum size of a capped collection in bytes.,0,mongodb,max size of capped collection,, diff --git a/mongo/tests/results/metrics-indexes-stats-autodiscover.json b/mongo/tests/results/metrics-indexes-stats-autodiscover.json index e1f64ace03346..0b004e45eca58 100644 --- a/mongo/tests/results/metrics-indexes-stats-autodiscover.json +++ b/mongo/tests/results/metrics-indexes-stats-autodiscover.json @@ -86,5 +86,93 @@ "collection:bar", "db:integration" ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 1243.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:foo", + "db:test" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 12.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:bar", + "db:test" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 1243.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:foo", + "db:admin" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 12.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:bar", + "db:admin" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 1243.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:foo", + "db:config" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 12.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:bar", + "db:config" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 1243.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:foo", + "db:integration" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 12.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:bar", + "db:integration" + ] } ] \ No newline at end of file diff --git a/mongo/tests/results/metrics-indexes-stats.json b/mongo/tests/results/metrics-indexes-stats.json index 4977ad2f1d274..37f040d4310e3 100644 --- a/mongo/tests/results/metrics-indexes-stats.json +++ b/mongo/tests/results/metrics-indexes-stats.json @@ -20,5 +20,27 @@ "collection:bar", "db:test" ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 1243.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:foo", + "db:test" + ] + }, + { + "name": "mongodb.collection.indexes.accesses.opsps", + "type": 1, + "value": 12.0, + "tags": [ + "server:mongodb://testUser2:*****@localhost:27017/test", + "name:_id_", + "collection:bar", + "db:test" + ] } ] \ No newline at end of file