-
Notifications
You must be signed in to change notification settings - Fork 439
PMM-9403 Add extra label for replicaset metrics #804
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -999,8 +999,8 @@ func oplogStatus(ctx context.Context, client *mongo.Client) ([]prometheus.Metric | |
return []prometheus.Metric{headMetric, tailMetric}, nil | ||
} | ||
|
||
func replSetMetrics(m bson.M) []prometheus.Metric { | ||
replSetGetStatus, ok := m["replSetGetStatus"].(bson.M) | ||
func replSetMetrics(d bson.M) []prometheus.Metric { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity. Why "d"? Since it is bson.M not bson.D. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thanks |
||
replSetGetStatus, ok := d["replSetGetStatus"].(bson.M) | ||
if !ok { | ||
return nil | ||
} | ||
|
@@ -1021,7 +1021,7 @@ func replSetMetrics(m bson.M) []prometheus.Metric { | |
for _, m := range repl.Members { | ||
if m.StateStr == "PRIMARY" { | ||
primaryOpTime = m.OptimeDate.Time() | ||
gotPrimary = !primaryOpTime.IsZero() | ||
gotPrimary = primaryOpTime.Unix() != 0 | ||
|
||
break | ||
} | ||
|
@@ -1044,20 +1044,19 @@ func replSetMetrics(m bson.M) []prometheus.Metric { | |
"name": m.Name, | ||
"state": m.StateStr, | ||
"set": repl.Set, | ||
"self": "0", | ||
} | ||
if m.Self { | ||
createMetric("my_name", "The replica state name of the current member.", 1, map[string]string{ | ||
"name": m.Name, | ||
"set": repl.Set, | ||
}) | ||
labels["self"] = "1" | ||
createMetric("my_name", "The replica state name of the current member.", 1, labels) | ||
} | ||
|
||
if !m.ElectionTime.IsZero() { | ||
createMetric("member_election_date", | ||
"The timestamp the node was elected as replica leader", | ||
float64(m.ElectionTime.T), labels) | ||
} | ||
if t := m.OptimeDate.Time(); gotPrimary && !t.IsZero() && m.StateStr != "PRIMARY" { | ||
if t := m.OptimeDate.Time(); gotPrimary && t.Unix() != 0 && m.StateStr != "PRIMARY" { | ||
val := math.Abs(float64(t.Unix() - primaryOpTime.Unix())) | ||
createMetric("member_replication_lag", | ||
"The replication lag that this member has with the primary.", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
Function 'replSetMetrics' has too many statements (41 > 40) (funlen)