Skip to content

Commit 4c23e30

Browse files
committed
fix metrics named by mongodb_connPoolStats_replicaSets_{shardReplSetName/configReplSetName}_{childKey}_{grandChildKey} raise error with '...was collected before with the same name and label values...'
1 parent 744526a commit 4c23e30

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

exporter/metrics.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func processSlice(prefix string, v []interface{}, commonLabels map[string]string
391391
continue
392392
}
393393

394-
// use the replicaset or server name as a label
394+
// use the replicaset or server name or addr as a label
395395
if name, ok := s["name"].(string); ok {
396396
labels["member_idx"] = name
397397
}
@@ -401,6 +401,9 @@ func processSlice(prefix string, v []interface{}, commonLabels map[string]string
401401
if host, ok := s["host"].(string); ok {
402402
labels["member_idx"] = host
403403
}
404+
if addr, ok := s["addr"].(string); ok {
405+
labels["member_addr"] = addr
406+
}
404407

405408
metrics = append(metrics, makeMetrics(prefix, s, labels, compatibleMode)...)
406409
}

exporter/testdata/get_diagnostic_data.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,65 @@
21332133
"uri": "statistics:"
21342134
}
21352135
},
2136+
"connPoolStats" : {
2137+
"start" : "2025-08-04T07:10:00.002Z",
2138+
"numClientConnections" : 24,
2139+
"numAScopedConnections" : 0,
2140+
"totalInUse" : 0,
2141+
"totalAvailable" : 156,
2142+
"totalCreated" : 143694,
2143+
"totalRefreshing" : 0,
2144+
"replicaSets" : {
2145+
"shard_001" : {
2146+
"hosts" : [
2147+
{
2148+
"addr" : "1.1.1.1:36001",
2149+
"ok" : true,
2150+
"ismaster" : true,
2151+
"hidden" : false,
2152+
"secondary" : false,
2153+
"pingTimeMillis" : 0
2154+
},
2155+
{
2156+
"addr" : "2.2.2.2:36001",
2157+
"ok" : true,
2158+
"ismaster" : false,
2159+
"hidden" : false,
2160+
"secondary" : true,
2161+
"pingTimeMillis" : 0
2162+
}
2163+
]
2164+
},
2165+
"configsvr" : {
2166+
"hosts" : [
2167+
{
2168+
"addr" : "3.3.3.3:27001",
2169+
"ok" : true,
2170+
"ismaster" : true,
2171+
"hidden" : false,
2172+
"secondary" : false,
2173+
"pingTimeMillis" : 0
2174+
},
2175+
{
2176+
"addr" : "4.4.4.4:27001",
2177+
"ok" : true,
2178+
"ismaster" : false,
2179+
"hidden" : false,
2180+
"secondary" : true,
2181+
"pingTimeMillis" : 0
2182+
},
2183+
{
2184+
"addr" : "5.5.5.5:27001",
2185+
"ok" : true,
2186+
"ismaster" : false,
2187+
"hidden" : false,
2188+
"secondary" : true,
2189+
"pingTimeMillis" : 0
2190+
}
2191+
]
2192+
}
2193+
}
2194+
},
21362195
"start": "2020-09-10T14:39:52-03:00",
21372196
"systemMetrics": {
21382197
"cpu": {

0 commit comments

Comments
 (0)