Skip to content

Commit a4078da

Browse files
authored
Skip collection stats when disabled in mongodb input (influxdata#6364)
1 parent 23cddef commit a4078da

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

plugins/inputs/mongodb/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
## When true, collect per database stats
1515
# gather_perdb_stats = false
16+
1617
## When true, collect per collection stats
1718
# gather_col_stats = false
19+
1820
## List of db where collections stats are collected
1921
## If empty, all db are concerned
2022
# col_stats_dbs = ["local"]

plugins/inputs/mongodb/mongodb.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ var sampleConfig = `
4242
4343
## When true, collect per database stats
4444
# gather_perdb_stats = false
45+
4546
## When true, collect per collection stats
4647
# gather_col_stats = false
48+
4749
## List of db where collections stats are collected
4850
## If empty, all db are concerned
4951
# col_stats_dbs = ["local"]
@@ -177,7 +179,8 @@ func (m *MongoDB) gatherServer(server *Server, acc telegraf.Accumulator) error {
177179
func init() {
178180
inputs.Add("mongodb", func() telegraf.Input {
179181
return &MongoDB{
180-
mongos: make(map[string]*Server),
182+
ColStatsDbs: []string{"local"},
183+
mongos: make(map[string]*Server),
181184
}
182185
})
183186
}

plugins/inputs/mongodb/mongodb_server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool, gather
227227
authLogLevel(err), err)
228228
}
229229

230-
collectionStats, err := s.gatherCollectionStats(colStatsDbs)
231-
if err != nil {
232-
return err
230+
var collectionStats *ColStats
231+
if gatherColStats {
232+
stats, err := s.gatherCollectionStats(colStatsDbs)
233+
if err != nil {
234+
return err
235+
}
236+
collectionStats = stats
233237
}
234238

235239
dbStats := &DbStats{}

plugins/inputs/mongodb/mongostat.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -961,24 +961,25 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
961961
}
962962
}
963963

964-
newColStats := *newMongo.ColStats
965-
for _, col := range newColStats.Collections {
966-
colStatsData := col.ColStatsData
967-
// mongos doesn't have the db key, so setting the db name
968-
if colStatsData.Collection == "" {
969-
colStatsData.Collection = col.Name
970-
}
971-
colStatLine := &ColStatLine{
972-
Name: colStatsData.Collection,
973-
DbName: col.DbName,
974-
Count: colStatsData.Count,
975-
Size: colStatsData.Size,
976-
AvgObjSize: colStatsData.AvgObjSize,
977-
StorageSize: colStatsData.StorageSize,
978-
TotalIndexSize: colStatsData.TotalIndexSize,
979-
Ok: colStatsData.Ok,
964+
if newMongo.ColStats != nil {
965+
for _, col := range newMongo.ColStats.Collections {
966+
colStatsData := col.ColStatsData
967+
// mongos doesn't have the db key, so setting the db name
968+
if colStatsData.Collection == "" {
969+
colStatsData.Collection = col.Name
970+
}
971+
colStatLine := &ColStatLine{
972+
Name: colStatsData.Collection,
973+
DbName: col.DbName,
974+
Count: colStatsData.Count,
975+
Size: colStatsData.Size,
976+
AvgObjSize: colStatsData.AvgObjSize,
977+
StorageSize: colStatsData.StorageSize,
978+
TotalIndexSize: colStatsData.TotalIndexSize,
979+
Ok: colStatsData.Ok,
980+
}
981+
returnVal.ColStatsLines = append(returnVal.ColStatsLines, *colStatLine)
980982
}
981-
returnVal.ColStatsLines = append(returnVal.ColStatsLines, *colStatLine)
982983
}
983984

984985
// Set shard stats

0 commit comments

Comments
 (0)