Skip to content

Commit

Permalink
added mongodb.flowcontrol.lag.time metric
Browse files Browse the repository at this point in the history
  • Loading branch information
RutvikS-crest committed Nov 19, 2024
1 parent c06be6d commit 3b390c6
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 0 deletions.
8 changes: 8 additions & 0 deletions receiver/mongodbreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ The number of extents.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {extents} | Sum | Int | Cumulative | false |
### mongodb.flowcontrol.lag.time
the amount of time flow control has spent being engaged since the last restart.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| ms | Gauge | Int |
### mongodb.global_lock.time
The time the global lock has been held.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions receiver/mongodbreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ all_set:
enabled: true
mongodb.extent.count:
enabled: true
mongodb.flowcontrol.lag.time:
enabled: true
mongodb.global_lock.time:
enabled: true
mongodb.health:
Expand Down Expand Up @@ -88,6 +90,8 @@ none_set:
enabled: false
mongodb.extent.count:
enabled: false
mongodb.flowcontrol.lag.time:
enabled: false
mongodb.global_lock.time:
enabled: false
mongodb.health:
Expand Down
7 changes: 7 additions & 0 deletions receiver/mongodbreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ metrics:
value_type: int
monotonic: false
attributes: []
mongodb.flowcontrol.lag.time:
description: the amount of time flow control has spent being engaged since the last restart.
unit: "ms"
enabled: true
gauge:
value_type: int
attributes: []
mongodb.global_lock.time:
description: The time the global lock has been held.
unit: ms
Expand Down
12 changes: 12 additions & 0 deletions receiver/mongodbreceiver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ func (s *mongodbScraper) recordConnections(now pcommon.Timestamp, doc bson.M, db
}
}

func (s *mongodbScraper) recordFlowControlLagTime(now pcommon.Timestamp, doc bson.M, dbName string, errs *scrapererror.ScrapeErrors) {
metricPath := []string{"flowControl", "isLaggedTimeMicros"}
metricName := "mongodb.flowcontrol.lag.time"
// metricAttributes := fmt.Sprintf("%s", dbName)
val, err := collectMetric(doc, metricPath)
if err != nil {
errs.AddPartial(1, fmt.Errorf(collectMetricWithAttributes, metricName, dbName, err))
return
}
s.mb.RecordMongodbFlowcontrolLagTimeDataPoint(now, val/1000)
}

func (s *mongodbScraper) recordMemoryUsage(now pcommon.Timestamp, doc bson.M, dbName string, errs *scrapererror.ScrapeErrors) {
for mtVal, mt := range metadata.MapAttributeMemoryType {
metricPath := []string{"mem", mtVal}
Expand Down
1 change: 1 addition & 0 deletions receiver/mongodbreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (s *mongodbScraper) recordDBStats(now pcommon.Timestamp, doc bson.M, dbName

func (s *mongodbScraper) recordNormalServerStats(now pcommon.Timestamp, doc bson.M, dbName string, errs *scrapererror.ScrapeErrors) {
s.recordConnections(now, doc, dbName, errs)
s.recordFlowControlLagTime(now, doc, dbName, errs)
s.recordDocumentOperations(now, doc, dbName, errs)
s.recordMemoryUsage(now, doc, dbName, errs)
s.recordLockAcquireCounts(now, doc, dbName, errs)
Expand Down
1 change: 1 addition & 0 deletions receiver/mongodbreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
"failed to collect metric mongodb.collection.count with attribute(s) fakedatabase: could not find key for metric",
"failed to collect metric mongodb.data.size with attribute(s) fakedatabase: could not find key for metric",
"failed to collect metric mongodb.extent.count with attribute(s) fakedatabase: could not find key for metric",
"failed to collect metric mongodb.flowcontrol.lag.time with attribute(s) fakedatabase: could not find key for metric",
"failed to collect metric mongodb.index.size with attribute(s) fakedatabase: could not find key for metric",
"failed to collect metric mongodb.index.count with attribute(s) fakedatabase: could not find key for metric",
"failed to collect metric mongodb.object.count with attribute(s) fakedatabase: could not find key for metric",
Expand Down
8 changes: 8 additions & 0 deletions receiver/mongodbreceiver/testdata/scraper/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
unit: '{extents}'
- description: the amount of time flow control has spent being engaged since the last restart.
name: mongodb.flowcontrol.lag.time
gauge:
dataPoints:
- asInt: "10"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
unit: ms
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
Expand Down
22 changes: 22 additions & 0 deletions receiver/mongodbreceiver/testdata/serverStatus.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@
"$numberInt": "3"
}
},
"flowControl": {
"enabled": true,
"targetRateLimit": {
"$numberInt": "3"
},
"timeAcquiringMicros": {
"$numberLong": "10000"
},
"locksPerKiloOp": {
"$numberInt": "3"
},
"sustainerRate": {
"$numberInt": "3"
},
"isLagged": true,
"isLaggedCount": {
"$numberInt": "3"
},
"isLaggedTimeMicros": {
"$numberLong": "10000"
}
},
"globalLock": {
"activeClients": {
"readers": {
Expand Down

0 comments on commit 3b390c6

Please sign in to comment.