Skip to content

Commit

Permalink
MongoDB input plugin: Improve state data (#2001)
Browse files Browse the repository at this point in the history
* MongoDB input plugin: Improve state data

Adds ARB as a "member_status" (replica set arbiter).
Uses MongoDB replica set state string for "state" value.

* MongoDB input plugin: Improve state data - changelog update
  • Loading branch information
dougreese authored and sparrc committed Dec 16, 2016
1 parent 99daa52 commit 2214ee9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in their config file.
- [#2068](https://github.com/influxdata/telegraf/issues/2068): Accept strings for StatsD sets.
- [#1893](https://github.com/influxdata/telegraf/issues/1893): Change StatsD default "reset" behavior.
- [#2079](https://github.com/influxdata/telegraf/pull/2079): Enable setting ClientID in MQTT output.
- [#2001](https://github.com/influxdata/telegraf/pull/2001): MongoDB input plugin: Improve state data.

### Bugfixes

Expand Down
4 changes: 1 addition & 3 deletions plugins/inputs/mongodb/mongodb_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ type DbData struct {
}

func NewMongodbData(statLine *StatLine, tags map[string]string) *MongodbData {
if statLine.NodeType != "" && statLine.NodeType != "UNK" {
tags["state"] = statLine.NodeType
}
return &MongodbData{
StatLine: statLine,
Tags: tags,
Expand Down Expand Up @@ -61,6 +58,7 @@ var DefaultReplStats = map[string]string{
"repl_getmores_per_sec": "GetMoreR",
"repl_commands_per_sec": "CommandR",
"member_status": "NodeType",
"state": "NodeState",
"repl_lag": "ReplLag",
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/mongodb/mongodb_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ func TestStateTag(t *testing.T) {
Insert: 0,
Query: 0,
NodeType: "PRI",
NodeState: "PRIMARY",
},
tags,
)

stateTags := make(map[string]string)
stateTags["state"] = "PRI"

var acc testutil.Accumulator

Expand All @@ -115,6 +115,7 @@ func TestStateTag(t *testing.T) {
"getmores_per_sec": int64(0),
"inserts_per_sec": int64(0),
"member_status": "PRI",
"state": "PRIMARY",
"net_in_bytes": int64(0),
"net_out_bytes": int64(0),
"open_connections": int64(0),
Expand Down
6 changes: 6 additions & 0 deletions plugins/inputs/mongodb/mongostat.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type ReplSetStatus struct {
type ReplSetMember struct {
Name string `bson:"name"`
State int64 `bson:"state"`
StateStr string `bson:"stateStr"`
OptimeDate *bson.MongoTimestamp `bson:"optimeDate"`
}

Expand Down Expand Up @@ -420,6 +421,7 @@ type StatLine struct {
NumConnections int64
ReplSetName string
NodeType string
NodeState string

// Cluster fields
JumboChunksCount int64
Expand Down Expand Up @@ -566,6 +568,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
returnVal.NodeType = "PRI"
} else if newStat.Repl.Secondary.(bool) {
returnVal.NodeType = "SEC"
} else if newStat.Repl.ArbiterOnly != nil && newStat.Repl.ArbiterOnly.(bool) {
returnVal.NodeType = "ARB"
} else {
returnVal.NodeType = "UNK"
}
Expand Down Expand Up @@ -692,6 +696,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
me := ReplSetMember{}
for _, member := range newReplStat.Members {
if member.Name == myName {
// Store my state string
returnVal.NodeState = member.StateStr
if member.State == 1 {
// I'm the master
returnVal.ReplLag = 0
Expand Down

0 comments on commit 2214ee9

Please sign in to comment.