MongoDB input plugin: Improve state data (#2001)

* 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
This commit is contained in:
Doug Reese 2016-12-16 05:46:32 -08:00 committed by Cameron Sparr
parent e6fc32bdf0
commit bc13d32d53
4 changed files with 10 additions and 4 deletions

View File

@ -25,6 +25,7 @@ in their config file.
- [#2068](https://github.com/influxdata/telegraf/issues/2068): Accept strings for StatsD sets. - [#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. - [#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. - [#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 ### Bugfixes

View File

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

View File

@ -95,12 +95,12 @@ func TestStateTag(t *testing.T) {
Insert: 0, Insert: 0,
Query: 0, Query: 0,
NodeType: "PRI", NodeType: "PRI",
NodeState: "PRIMARY",
}, },
tags, tags,
) )
stateTags := make(map[string]string) stateTags := make(map[string]string)
stateTags["state"] = "PRI"
var acc testutil.Accumulator var acc testutil.Accumulator
@ -115,6 +115,7 @@ func TestStateTag(t *testing.T) {
"getmores_per_sec": int64(0), "getmores_per_sec": int64(0),
"inserts_per_sec": int64(0), "inserts_per_sec": int64(0),
"member_status": "PRI", "member_status": "PRI",
"state": "PRIMARY",
"net_in_bytes": int64(0), "net_in_bytes": int64(0),
"net_out_bytes": int64(0), "net_out_bytes": int64(0),
"open_connections": int64(0), "open_connections": int64(0),

View File

@ -107,6 +107,7 @@ type ReplSetStatus struct {
type ReplSetMember struct { type ReplSetMember struct {
Name string `bson:"name"` Name string `bson:"name"`
State int64 `bson:"state"` State int64 `bson:"state"`
StateStr string `bson:"stateStr"`
OptimeDate *bson.MongoTimestamp `bson:"optimeDate"` OptimeDate *bson.MongoTimestamp `bson:"optimeDate"`
} }
@ -420,6 +421,7 @@ type StatLine struct {
NumConnections int64 NumConnections int64
ReplSetName string ReplSetName string
NodeType string NodeType string
NodeState string
// Cluster fields // Cluster fields
JumboChunksCount int64 JumboChunksCount int64
@ -566,6 +568,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
returnVal.NodeType = "PRI" returnVal.NodeType = "PRI"
} else if newStat.Repl.Secondary.(bool) { } else if newStat.Repl.Secondary.(bool) {
returnVal.NodeType = "SEC" returnVal.NodeType = "SEC"
} else if newStat.Repl.ArbiterOnly != nil && newStat.Repl.ArbiterOnly.(bool) {
returnVal.NodeType = "ARB"
} else { } else {
returnVal.NodeType = "UNK" returnVal.NodeType = "UNK"
} }
@ -692,6 +696,8 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
me := ReplSetMember{} me := ReplSetMember{}
for _, member := range newReplStat.Members { for _, member := range newReplStat.Members {
if member.Name == myName { if member.Name == myName {
// Store my state string
returnVal.NodeState = member.StateStr
if member.State == 1 { if member.State == 1 {
// I'm the master // I'm the master
returnVal.ReplLag = 0 returnVal.ReplLag = 0