Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): add threshold for MongoDB collstats metric set #31

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions metricbeat/module/mongodb/collstats/collstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@
if !ok {
return errors.New("collection 'totals' are not a map")
}

collectedCollectionDataNum := 0
for group, info := range totals {
if group == "note" {
continue
}

// 如果已采集的collection的数量大于定义的,那么不再采集数据
if collectedCollectionDataNum >= m.Config.MaxCollectionNum {
break
}
infoMap, ok := info.(map[string]interface{})
if !ok {
reporter.Error(errors.New("unexpected data returned by mongodb"))
Expand All @@ -122,11 +125,12 @@
reporter.Event(mb.Event{
MetricSetFields: event,
})
collectedCollectionDataNum += 1
}

databaseNames, err := client.ListDatabaseNames(context.Background(), bson.D{})
if err != nil {
return fmt.Errorf("ListDatabaseNames failed: %s", err)

Check failure on line 133 in metricbeat/module/mongodb/collstats/collstats.go

View workflow job for this annotation

GitHub Actions / lint (windows)

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)

Check failure on line 133 in metricbeat/module/mongodb/collstats/collstats.go

View workflow job for this annotation

GitHub Actions / lint (linux)

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)

Check failure on line 133 in metricbeat/module/mongodb/collstats/collstats.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}
collectedCollectionNum := 0
OutLoop:
Expand All @@ -138,6 +142,9 @@
continue
}
for _, collectionName := range collectionNames {
if collectedCollectionNum >= m.Config.MaxCollectionNum {
break OutLoop
}
res = db.RunCommand(context.Background(), bson.D{bson.E{Key: "collStats", Value: collectionName}})
if err = res.Err(); err != nil {
m.Logger().Errorf("'collStats %s' command returned an error: %w", collectionName, err)
Expand All @@ -159,9 +166,7 @@
MetricSetFields: event,
})
collectedCollectionNum += 1
if collectedCollectionNum >= m.Config.MaxCollectionNum {
break OutLoop
}

}
}

Expand Down
Loading