if newStat.Repl != nil {
returnVal.ReplSetName = newStat.Repl.SetName
// BEGIN code modification
if newStat.Repl.IsMaster.(bool) {
returnVal.NodeType = "PRI"
} else if newStat.Repl.Secondary != nil && newStat.Repl.Secondary.(bool) {
returnVal.NodeType = "SEC"
} else if newStat.Repl.ArbiterOnly != nil && newStat.Repl.ArbiterOnly.(bool) {
returnVal.NodeType = "ARB"
} else {
returnVal.NodeType = "UNK"
} // END code modification
}
when using telegraf collects mongodb metrics with 5.x replicaset, newStat.Repl.IsMaster.(bool) will cause a crash, the reason is that the 'repl' of serverStatus in 5.x use 'isWritablePrimary' instead of 'ismaster'
when using telegraf collects mongodb metrics with 5.x replicaset, newStat.Repl.IsMaster.(bool) will cause a crash, the reason is that the 'repl' of serverStatus in 5.x use 'isWritablePrimary' instead of 'ismaster'