From 62a8d947a8030279863451cf05b1e8301e506d7b Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Fri, 29 Apr 2016 18:40:26 +0200 Subject: [PATCH] Metric for MongoDB jumbo chunks --- CHANGELOG.md | 1 + plugins/inputs/mongodb/README.md | 1 + plugins/inputs/mongodb/mongodb_data.go | 5 +++++ plugins/inputs/mongodb/mongodb_data_test.go | 1 + plugins/inputs/mongodb/mongodb_server.go | 7 +++++++ plugins/inputs/mongodb/mongostat.go | 12 ++++++++++++ 6 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae54ed7ca..e811dcb26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ based on _prefix_ in addition to globs. This means that a filter like - [#967](https://github.com/influxdata/telegraf/issues/967): Buffer logging improvements. - [#1107](https://github.com/influxdata/telegraf/issues/1107): Support lustre2 job stats. Thanks @hanleyja! - [#1122](https://github.com/influxdata/telegraf/pull/1122): Support setting config path through env variable and default paths. +- [#1128](https://github.com/influxdata/telegraf/pull/1128): MongoDB jumbo chunks metric for MongoDB input plugin ### Bugfixes diff --git a/plugins/inputs/mongodb/README.md b/plugins/inputs/mongodb/README.md index 0d140b395..66ff2668e 100644 --- a/plugins/inputs/mongodb/README.md +++ b/plugins/inputs/mongodb/README.md @@ -51,3 +51,4 @@ and create a single measurement containing values e.g. * ttl_deletes_per_sec * ttl_passes_per_sec * repl_lag + * jumbo_chunks (only if mongos or mongo config) diff --git a/plugins/inputs/mongodb/mongodb_data.go b/plugins/inputs/mongodb/mongodb_data.go index f9bbc1d3b..7a52d650a 100644 --- a/plugins/inputs/mongodb/mongodb_data.go +++ b/plugins/inputs/mongodb/mongodb_data.go @@ -57,6 +57,10 @@ var DefaultReplStats = map[string]string{ "repl_lag": "ReplLag", } +var DefaultClusterStats = map[string]string{ + "jumbo_chunks": "JumboChunksCount", +} + var MmapStats = map[string]string{ "mapped_megabytes": "Mapped", "non-mapped_megabytes": "NonMapped", @@ -74,6 +78,7 @@ func (d *MongodbData) AddDefaultStats() { if d.StatLine.NodeType != "" { d.addStat(statLine, DefaultReplStats) } + d.addStat(statLine, DefaultClusterStats) if d.StatLine.StorageEngine == "mmapv1" { d.addStat(statLine, MmapStats) } else if d.StatLine.StorageEngine == "wiredTiger" { diff --git a/plugins/inputs/mongodb/mongodb_data_test.go b/plugins/inputs/mongodb/mongodb_data_test.go index 5619641fc..a08549cfd 100644 --- a/plugins/inputs/mongodb/mongodb_data_test.go +++ b/plugins/inputs/mongodb/mongodb_data_test.go @@ -133,6 +133,7 @@ func TestStateTag(t *testing.T) { "vsize_megabytes": int64(0), "ttl_deletes_per_sec": int64(0), "ttl_passes_per_sec": int64(0), + "jumbo_chunks": int64(0), } acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags) } diff --git a/plugins/inputs/mongodb/mongodb_server.go b/plugins/inputs/mongodb/mongodb_server.go index 86699a4d9..173391e2f 100644 --- a/plugins/inputs/mongodb/mongodb_server.go +++ b/plugins/inputs/mongodb/mongodb_server.go @@ -36,9 +36,16 @@ func (s *Server) gatherData(acc telegraf.Accumulator) error { log.Println("Not gathering replica set status, member not in replica set") } + jumbo_chunks, _ := s.Session.DB("config").C("chunks").Find(bson.M{"jumbo": true}).Count() + + result_cluster := &ClusterStatus{ + JumboChunksCount: int64(jumbo_chunks), + } + result := &MongoStatus{ ServerStatus: result_server, ReplSetStatus: result_repl, + ClusterStatus: result_cluster, } defer func() { diff --git a/plugins/inputs/mongodb/mongostat.go b/plugins/inputs/mongodb/mongostat.go index b131bf9a0..d564931d1 100644 --- a/plugins/inputs/mongodb/mongostat.go +++ b/plugins/inputs/mongodb/mongostat.go @@ -34,6 +34,7 @@ type MongoStatus struct { SampleTime time.Time ServerStatus *ServerStatus ReplSetStatus *ReplSetStatus + ClusterStatus *ClusterStatus } type ServerStatus struct { @@ -64,6 +65,11 @@ type ServerStatus struct { Metrics *MetricsStats `bson:"metrics"` } +// ClusterStatus stores information related to the whole cluster +type ClusterStatus struct { + JumboChunksCount int64 +} + // ReplSetStatus stores information from replSetGetStatus type ReplSetStatus struct { Members []ReplSetMember `bson:"members"` @@ -387,6 +393,9 @@ type StatLine struct { NumConnections int64 ReplSetName string NodeType string + + // Cluster fields + JumboChunksCount int64 } func parseLocks(stat ServerStatus) map[string]LockUsage { @@ -665,5 +674,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec } } + newClusterStat := *newMongo.ClusterStatus + returnVal.JumboChunksCount = newClusterStat.JumboChunksCount + return returnVal }