Skip to content

Commit

Permalink
Add replica set tag to mongodb input (influxdata#6914)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiyaRagozina authored and idohalevi committed Sep 23, 2020
1 parent eeffd83 commit a68fb50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/inputs/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ by running Telegraf with the `--debug` argument.
- tags:
- hostname
- node_type
- rs_name
- fields:
- active_reads (integer)
- active_writes (integer)
Expand Down
4 changes: 4 additions & 0 deletions plugins/inputs/mongodb/mongodb_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ func (d *MongodbData) AddDefaultStats() {
d.addStat(statLine, DefaultLatencyStats)
}

if d.StatLine.ReplSetName != "" {
d.Tags["rs_name"] = d.StatLine.ReplSetName
}

if d.StatLine.OplogStats != nil {
d.add("repl_oplog_window_sec", d.StatLine.OplogStats.TimeDiff)
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/mongodb/mongodb_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ func TestStateTag(t *testing.T) {
Query: 0,
NodeType: "PRI",
NodeState: "PRIMARY",
ReplSetName: "rs1",
},
tags,
)

stateTags := make(map[string]string)
stateTags["node_type"] = "PRI"
stateTags["rs_name"] = "rs1"

var acc testutil.Accumulator

Expand Down

0 comments on commit a68fb50

Please sign in to comment.