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

Metric for MongoDB jumbo chunks #1128

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions plugins/inputs/mongodb/mongodb_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/mongodb/mongodb_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions plugins/inputs/mongodb/mongodb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions plugins/inputs/mongodb/mongostat.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type MongoStatus struct {
SampleTime time.Time
ServerStatus *ServerStatus
ReplSetStatus *ReplSetStatus
ClusterStatus *ClusterStatus
}

type ServerStatus struct {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -387,6 +393,9 @@ type StatLine struct {
NumConnections int64
ReplSetName string
NodeType string

// Cluster fields
JumboChunksCount int64
}

func parseLocks(stat ServerStatus) map[string]LockUsage {
Expand Down Expand Up @@ -665,5 +674,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
}
}

newClusterStat := *newMongo.ClusterStatus
returnVal.JumboChunksCount = newClusterStat.JumboChunksCount

return returnVal
}