Add option to disable mongodb cluster status (#7515)

It can be expensive to compute these metrics. In particular, when
retrieveing the amount of jumbo chunks, an index is not being used and
consequently the query triggers an expensive COLLSCAN. For big
databases, this query has negative impact on the cluster performance.
This commit is contained in:
raul-te 2020-05-22 00:11:00 -07:00 committed by GitHub
parent 130403c0c9
commit 4d071bed24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 13 deletions

View File

@ -11,6 +11,11 @@
## mongodb://10.10.3.33:18832, ## mongodb://10.10.3.33:18832,
servers = ["mongodb://127.0.0.1:27017"] servers = ["mongodb://127.0.0.1:27017"]
## When true, collect cluster status.
## Note that the query that counts jumbo chunks triggers a COLLSCAN, which
## may have an impact on performance.
# gather_cluster_status = true
## When true, collect per database stats ## When true, collect per database stats
# gather_perdb_stats = false # gather_perdb_stats = false

View File

@ -17,12 +17,13 @@ import (
) )
type MongoDB struct { type MongoDB struct {
Servers []string Servers []string
Ssl Ssl Ssl Ssl
mongos map[string]*Server mongos map[string]*Server
GatherPerdbStats bool GatherClusterStatus bool
GatherColStats bool GatherPerdbStats bool
ColStatsDbs []string GatherColStats bool
ColStatsDbs []string
tlsint.ClientConfig tlsint.ClientConfig
Log telegraf.Logger Log telegraf.Logger
@ -41,6 +42,11 @@ var sampleConfig = `
## mongodb://10.10.3.33:18832, ## mongodb://10.10.3.33:18832,
servers = ["mongodb://127.0.0.1:27017"] servers = ["mongodb://127.0.0.1:27017"]
## When true, collect cluster status
## Note that the query that counts jumbo chunks triggers a COLLSCAN, which
## may have an impact on performance.
# gather_cluster_status = true
## When true, collect per database stats ## When true, collect per database stats
# gather_perdb_stats = false # gather_perdb_stats = false
@ -177,14 +183,17 @@ func (m *MongoDB) gatherServer(server *Server, acc telegraf.Accumulator) error {
} }
server.Session = sess server.Session = sess
} }
return server.gatherData(acc, m.GatherPerdbStats, m.GatherColStats, m.ColStatsDbs) return server.gatherData(acc, m.GatherClusterStatus, m.GatherPerdbStats, m.GatherColStats, m.ColStatsDbs)
} }
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), GatherClusterStatus: true,
GatherPerdbStats: false,
GatherColStats: false,
ColStatsDbs: []string{"local"},
} }
}) })
} }

View File

@ -192,7 +192,7 @@ func (s *Server) gatherCollectionStats(colStatsDbs []string) (*ColStats, error)
return results, nil return results, nil
} }
func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool, gatherColStats bool, colStatsDbs []string) error { func (s *Server) gatherData(acc telegraf.Accumulator, gatherClusterStatus bool, gatherDbStats bool, gatherColStats bool, colStatsDbs []string) error {
s.Session.SetMode(mgo.Eventual, true) s.Session.SetMode(mgo.Eventual, true)
s.Session.SetSocketTimeout(0) s.Session.SetSocketTimeout(0)
@ -218,9 +218,13 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool, gather
} }
} }
clusterStatus, err := s.gatherClusterStatus() var clusterStatus *ClusterStatus
if err != nil { if gatherClusterStatus {
s.Log.Debugf("Unable to gather cluster status: %s", err.Error()) status, err := s.gatherClusterStatus()
if err != nil {
s.Log.Debugf("Unable to gather cluster status: %s", err.Error())
}
clusterStatus = status
} }
shardStats, err := s.gatherShardConnPoolStats() shardStats, err := s.gatherShardConnPoolStats()