Skip to content

Commit f9d6411

Browse files
aldrickdevaldrick.castro
and
aldrick.castro
authored
[mongo] Provide a way to optionally disable collecting free storage metrics (#20135)
* Added the new configuration to the spec and example configuration * Added the configurations to the integration * Added logic to check state of the free_storage_metrics before collecting dbStats metrics * Adding a test * Formatting * validate model * Test passing but not sure why * Still don't know why it works 😅 * Added changelog * Fixed test 👍 --------- Co-authored-by: aldrick.castro <aldrick.castro@d>
1 parent cbca8e1 commit f9d6411

14 files changed

+599
-2
lines changed

mongo/assets/configuration/spec.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ files:
448448
value:
449449
type: boolean
450450
example: true
451+
- name: free_storage_metrics
452+
description: |
453+
Enabled or disable the collection of free storage metrics.
454+
By default, this option is enabled (`true`), meaning free storage metrics are collected.
455+
Set to `false` to disable collection of free storage metrics.
456+
457+
Note: If the instance has a large number of collections or indexes, obtaining free space usage data may cause
458+
processing delays and high CPU usage on the instance.
459+
https://www.mongodb.com/docs/manual/reference/command/dbStats/#std-label-dbStats-freeStorage
460+
value:
461+
type: boolean
462+
example: true
463+
display_default: true
451464
- name: add_node_tag_to_events
452465
description: |
453466
Adds the Mongo node to events as a tag rather than creating a seperate host for the event.

mongo/changelog.d/20135.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[mongo] Provide a way to optionally disable collecting free storage metrics

mongo/datadog_checks/mongo/collectors/db_stat.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, check, db_name, dbstats_tag_dbname, tags):
1818
self.db_name = db_name
1919
self.dbstats_tag_dbname = dbstats_tag_dbname
2020
self._collection_interval = check._config.metrics_collection_interval['db_stats']
21+
self.free_storage_metrics = check._config.free_storage_metrics
2122
self._collector_key = (self.__class__.__name__, db_name) # db_name is part of collector key
2223

2324
def compatible_with(self, deployment):
@@ -48,5 +49,7 @@ def collect(self, api):
4849
]
4950
else:
5051
additional_tags = None
51-
stats = {'stats': db.command({'dbStats': 1, 'freeStorage': 1})}
52+
53+
collect_free_storage_metrics = 1 if self.free_storage_metrics else 0
54+
stats = {'stats': db.command({'dbStats': 1, 'freeStorage': collect_free_storage_metrics})}
5255
return self._submit_payload(stats, additional_tags)

mongo/datadog_checks/mongo/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __init__(self, instance, log, init_config):
9797
self.custom_queries = instance.get("custom_queries", [])
9898
self._metrics_collection_interval = instance.get("metrics_collection_interval", {})
9999
self.system_database_stats = is_affirmative(instance.get('system_database_stats', True))
100+
self.free_storage_metrics = is_affirmative(instance.get('free_storage_metrics', True))
100101

101102
self._base_tags = list(set(instance.get('tags', [])))
102103

mongo/datadog_checks/mongo/config_models/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def instance_empty_default_hostname():
4040
return False
4141

4242

43+
def instance_free_storage_metrics():
44+
return True
45+
46+
4347
def instance_min_collection_interval():
4448
return 15
4549

mongo/datadog_checks/mongo/config_models/instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class InstanceConfig(BaseModel):
141141
dbstats_tag_dbname: Optional[bool] = None
142142
disable_generic_tags: Optional[bool] = None
143143
empty_default_hostname: Optional[bool] = None
144+
free_storage_metrics: Optional[bool] = None
144145
hosts: Optional[Union[str, tuple[str, ...]]] = None
145146
metric_patterns: Optional[MetricPatterns] = None
146147
metrics_collection_interval: Optional[MetricsCollectionInterval] = None

mongo/datadog_checks/mongo/data/conf.yaml.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ instances:
359359
#
360360
# system_database_stats: true
361361

362+
## @param free_storage_metrics - boolean - optional - default: true
363+
## Enabled or disable the collection of free storage metrics.
364+
## By default, this option is enabled (`true`), meaning free storage metrics are collected.
365+
## Set to `false` to disable collection of free storage metrics.
366+
##
367+
## Note: If the instance has a large number of collections or indexes, obtaining free space usage data may cause
368+
## processing delays and high CPU usage on the instance.
369+
## https://www.mongodb.com/docs/manual/reference/command/dbStats/#std-label-dbStats-freeStorage
370+
#
371+
# free_storage_metrics: true
372+
362373
## @param custom_queries - list of mappings - optional
363374
## Define custom queries to collect custom metrics on your Mongo
364375
## Note: Custom queries are ignored by default when the mongo node is a secondary of a replica set.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"raw": {
3+
"shard01/shard01a:27018,shard01b:27018": {
4+
"db": "admin",
5+
"collections": 1,
6+
"views": 0,
7+
"objects": 2,
8+
"avgObjSize": 111.0,
9+
"dataSize": 222.0,
10+
"storageSize": 32768.0,
11+
"numExtents": 0,
12+
"indexes": 1,
13+
"indexSize": 32768.0,
14+
"scaleFactor": 1.0,
15+
"ok": 1.0
16+
},
17+
"shard03/shard03a:27020,shard03b:27020": {
18+
"db": "admin",
19+
"collections": 1,
20+
"views": 0,
21+
"objects": 2,
22+
"avgObjSize": 111.0,
23+
"dataSize": 222.0,
24+
"storageSize": 32768.0,
25+
"numExtents": 0,
26+
"indexes": 1,
27+
"indexSize": 32768.0,
28+
"scaleFactor": 1.0,
29+
"ok": 1.0
30+
},
31+
"shard02/shard02a:27019,shard02b:27019": {
32+
"db": "admin",
33+
"collections": 1,
34+
"views": 0,
35+
"objects": 2,
36+
"avgObjSize": 111.0,
37+
"dataSize": 222.0,
38+
"storageSize": 32768.0,
39+
"numExtents": 0,
40+
"indexes": 1,
41+
"indexSize": 32768.0,
42+
"scaleFactor": 1.0,
43+
"ok": 1.0
44+
}
45+
},
46+
"objects": 6,
47+
"avgObjSize": 111.0,
48+
"dataSize": 666,
49+
"storageSize": 98304,
50+
"numExtents": 0,
51+
"indexes": 3,
52+
"indexSize": 98304,
53+
"scaleFactor": 1,
54+
"fileSize": 0,
55+
"ok": 1.0,
56+
"operationTime": {
57+
"$timestamp": {
58+
"t": 1600245945,
59+
"i": 21
60+
}
61+
},
62+
"$clusterTime": {
63+
"clusterTime": {
64+
"$timestamp": {
65+
"t": 1600245948,
66+
"i": 1
67+
}
68+
},
69+
"signature": {
70+
"hash": {
71+
"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
72+
"$type": "00"
73+
},
74+
"keyId": 0
75+
}
76+
}
77+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"raw": {
3+
"shard01/shard01a:27018,shard01b:27018": {
4+
"db": "config",
5+
"collections": 5,
6+
"views": 0,
7+
"objects": 124,
8+
"avgObjSize": 99.87096774193549,
9+
"dataSize": 12384.0,
10+
"storageSize": 90112.0,
11+
"numExtents": 0,
12+
"indexes": 7,
13+
"indexSize": 155648.0,
14+
"indexFreeStorageSize": 8556544.0,
15+
"scaleFactor": 1.0,
16+
"ok": 1.0
17+
},
18+
"shard03/shard03a:27020,shard03b:27020": {
19+
"db": "config",
20+
"collections": 4,
21+
"views": 0,
22+
"objects": 3,
23+
"avgObjSize": 135.0,
24+
"dataSize": 405.0,
25+
"storageSize": 53248.0,
26+
"numExtents": 0,
27+
"indexes": 5,
28+
"indexSize": 69632.0,
29+
"indexFreeStorageSize": 8556544.0,
30+
"scaleFactor": 1.0,
31+
"ok": 1.0
32+
},
33+
"shard02/shard02a:27019,shard02b:27019": {
34+
"db": "config",
35+
"collections": 4,
36+
"views": 0,
37+
"objects": 4,
38+
"avgObjSize": 128.25,
39+
"dataSize": 513.0,
40+
"storageSize": 69632.0,
41+
"numExtents": 0,
42+
"indexes": 5,
43+
"indexSize": 86016.0,
44+
"indexFreeStorageSize": 8556544.0,
45+
"scaleFactor": 1.0,
46+
"ok": 1.0
47+
}
48+
},
49+
"objects": 131,
50+
"avgObjSize": 100.70992366412214,
51+
"dataSize": 13302,
52+
"storageSize": 212992,
53+
"numExtents": 0,
54+
"indexes": 17,
55+
"indexSize": 311296,
56+
"indexFreeStorageSize": 8556544.0,
57+
"scaleFactor": 1,
58+
"fileSize": 0,
59+
"ok": 1.0,
60+
"operationTime": {
61+
"$timestamp": {
62+
"t": 1600245969,
63+
"i": 1
64+
}
65+
},
66+
"$clusterTime": {
67+
"clusterTime": {
68+
"$timestamp": {
69+
"t": 1600245969,
70+
"i": 1
71+
}
72+
},
73+
"signature": {
74+
"hash": {
75+
"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
76+
"$type": "00"
77+
},
78+
"keyId": 0
79+
}
80+
}
81+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"db": "local",
3+
"collections": 7,
4+
"views": 1,
5+
"objects": 6938,
6+
"avgObjSize": 214.15696166042088,
7+
"dataSize": 1485821.0,
8+
"storageSize": 430080.0,
9+
"numExtents": 0,
10+
"indexes": 6,
11+
"indexSize": 98304.0,
12+
"indexFreeStorageSize": 8556544.0,
13+
"scaleFactor": 1.0,
14+
"ok": 1.0,
15+
"$gleStats": {
16+
"lastOpTime": {
17+
"$timestamp": {
18+
"t": 0,
19+
"i": 0
20+
}
21+
},
22+
"electionId": {
23+
"$oid": "7fffffff0000000000000004"
24+
}
25+
},
26+
"lastCommittedOpTime": {
27+
"$timestamp": {
28+
"t": 1600249681,
29+
"i": 1
30+
}
31+
},
32+
"$configServerState": {
33+
"opTime": {
34+
"ts": {
35+
"$timestamp": {
36+
"t": 1600249677,
37+
"i": 1
38+
}
39+
},
40+
"t": 8
41+
}
42+
},
43+
"$clusterTime": {
44+
"clusterTime": {
45+
"$timestamp": {
46+
"t": 1600249681,
47+
"i": 1
48+
}
49+
},
50+
"signature": {
51+
"hash": {
52+
"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
53+
"$type": "00"
54+
},
55+
"keyId": 0
56+
}
57+
},
58+
"operationTime": {
59+
"$timestamp": {
60+
"t": 1600249681,
61+
"i": 1
62+
}
63+
}
64+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"raw": {
3+
"shard01/shard01a:27018,shard01b:27018": {
4+
"db": "test",
5+
"collections": 0,
6+
"views": 0,
7+
"objects": 0,
8+
"avgObjSize": 0,
9+
"dataSize": 0,
10+
"storageSize": 0,
11+
"numExtents": 0,
12+
"indexes": 0,
13+
"indexSize": 0,
14+
"indexFreeStorageSize": 0,
15+
"scaleFactor": 1,
16+
"fileSize": 0,
17+
"ok": 1.0
18+
},
19+
"shard03/shard03a:27020,shard03b:27020": {
20+
"db": "test",
21+
"collections": 0,
22+
"views": 0,
23+
"objects": 0,
24+
"avgObjSize": 0,
25+
"dataSize": 0,
26+
"storageSize": 0,
27+
"numExtents": 0,
28+
"indexes": 0,
29+
"indexSize": 0,
30+
"indexFreeStorageSize": 0,
31+
"scaleFactor": 1,
32+
"fileSize": 0,
33+
"ok": 1.0
34+
},
35+
"shard02/shard02a:27019,shard02b:27019": {
36+
"db": "test",
37+
"collections": 3,
38+
"views": 0,
39+
"objects": 316,
40+
"avgObjSize": 27.556962025316455,
41+
"dataSize": 8708.0,
42+
"storageSize": 49152.0,
43+
"numExtents": 0,
44+
"indexes": 3,
45+
"indexSize": 49152.0,
46+
"indexFreeStorageSize": 1.0,
47+
"scaleFactor": 1.0,
48+
"ok": 1.0
49+
}
50+
},
51+
"objects": 316,
52+
"avgObjSize": 27.0,
53+
"dataSize": 8708,
54+
"storageSize": 49152,
55+
"numExtents": 0,
56+
"indexes": 3,
57+
"indexSize": 49152,
58+
"indexFreeStorageSize": 8556544.0,
59+
"scaleFactor": 1,
60+
"fileSize": 0,
61+
"ok": 1.0,
62+
"operationTime": {
63+
"$timestamp": {
64+
"t": 1600245931,
65+
"i": 1
66+
}
67+
},
68+
"$clusterTime": {
69+
"clusterTime": {
70+
"$timestamp": {
71+
"t": 1600245931,
72+
"i": 1
73+
}
74+
},
75+
"signature": {
76+
"hash": {
77+
"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
78+
"$type": "00"
79+
},
80+
"keyId": 0
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)