Skip collection stats when disabled in mongodb input (#6364)
This commit is contained in:
parent
23cddef30a
commit
a4078da648
|
@ -13,8 +13,10 @@
|
||||||
|
|
||||||
## When true, collect per database stats
|
## When true, collect per database stats
|
||||||
# gather_perdb_stats = false
|
# gather_perdb_stats = false
|
||||||
|
|
||||||
## When true, collect per collection stats
|
## When true, collect per collection stats
|
||||||
# gather_col_stats = false
|
# gather_col_stats = false
|
||||||
|
|
||||||
## List of db where collections stats are collected
|
## List of db where collections stats are collected
|
||||||
## If empty, all db are concerned
|
## If empty, all db are concerned
|
||||||
# col_stats_dbs = ["local"]
|
# col_stats_dbs = ["local"]
|
||||||
|
|
|
@ -42,8 +42,10 @@ var sampleConfig = `
|
||||||
|
|
||||||
## When true, collect per database stats
|
## When true, collect per database stats
|
||||||
# gather_perdb_stats = false
|
# gather_perdb_stats = false
|
||||||
|
|
||||||
## When true, collect per collection stats
|
## When true, collect per collection stats
|
||||||
# gather_col_stats = false
|
# gather_col_stats = false
|
||||||
|
|
||||||
## List of db where collections stats are collected
|
## List of db where collections stats are collected
|
||||||
## If empty, all db are concerned
|
## If empty, all db are concerned
|
||||||
# col_stats_dbs = ["local"]
|
# col_stats_dbs = ["local"]
|
||||||
|
@ -177,6 +179,7 @@ func (m *MongoDB) gatherServer(server *Server, acc telegraf.Accumulator) error {
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("mongodb", func() telegraf.Input {
|
inputs.Add("mongodb", func() telegraf.Input {
|
||||||
return &MongoDB{
|
return &MongoDB{
|
||||||
|
ColStatsDbs: []string{"local"},
|
||||||
mongos: make(map[string]*Server),
|
mongos: make(map[string]*Server),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -227,10 +227,14 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool, gather
|
||||||
authLogLevel(err), err)
|
authLogLevel(err), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
collectionStats, err := s.gatherCollectionStats(colStatsDbs)
|
var collectionStats *ColStats
|
||||||
|
if gatherColStats {
|
||||||
|
stats, err := s.gatherCollectionStats(colStatsDbs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
collectionStats = stats
|
||||||
|
}
|
||||||
|
|
||||||
dbStats := &DbStats{}
|
dbStats := &DbStats{}
|
||||||
if gatherDbStats {
|
if gatherDbStats {
|
||||||
|
|
|
@ -961,8 +961,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newColStats := *newMongo.ColStats
|
if newMongo.ColStats != nil {
|
||||||
for _, col := range newColStats.Collections {
|
for _, col := range newMongo.ColStats.Collections {
|
||||||
colStatsData := col.ColStatsData
|
colStatsData := col.ColStatsData
|
||||||
// mongos doesn't have the db key, so setting the db name
|
// mongos doesn't have the db key, so setting the db name
|
||||||
if colStatsData.Collection == "" {
|
if colStatsData.Collection == "" {
|
||||||
|
@ -980,6 +980,7 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
|
||||||
}
|
}
|
||||||
returnVal.ColStatsLines = append(returnVal.ColStatsLines, *colStatLine)
|
returnVal.ColStatsLines = append(returnVal.ColStatsLines, *colStatLine)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set shard stats
|
// Set shard stats
|
||||||
newShardStats := *newMongo.ShardStats
|
newShardStats := *newMongo.ShardStats
|
||||||
|
|
Loading…
Reference in New Issue