Skip to content

Commit

Permalink
Add shard label in collstats metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
steveteuber committed Nov 1, 2024
1 parent deaf106 commit 0b97543
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions exporter/collstats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (d *collstatsCollector) collect(ch chan<- prometheus.Metric) {
labels["collection"] = collection

for _, metrics := range stats {
if shard, ok := metrics["shard"].(string); ok {
labels["shard"] = shard
}

for _, metric := range makeMetrics(prefix, metrics, labels, d.compatibleMode) {
ch <- metric
}
Expand Down
18 changes: 9 additions & 9 deletions exporter/collstats_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ func TestCollStatsCollector(t *testing.T) {
expected := strings.NewReader(`
# HELP mongodb_collstats_latencyStats_commands_latency collstats.latencyStats.commands.
# TYPE mongodb_collstats_latencyStats_commands_latency untyped
mongodb_collstats_latencyStats_commands_latency{collection="testcol_00",database="testdb"} 0
mongodb_collstats_latencyStats_commands_latency{collection="testcol_01",database="testdb"} 0
mongodb_collstats_latencyStats_commands_latency{collection="testcol_02",database="testdb"} 0
mongodb_collstats_latencyStats_commands_latency{collection="testcol_00",database="testdb",shard="rs1"} 0
mongodb_collstats_latencyStats_commands_latency{collection="testcol_01",database="testdb",shard="rs1"} 0
mongodb_collstats_latencyStats_commands_latency{collection="testcol_02",database="testdb",shard="rs1"} 0
# HELP mongodb_collstats_latencyStats_transactions_ops collstats.latencyStats.transactions.
# TYPE mongodb_collstats_latencyStats_transactions_ops untyped
mongodb_collstats_latencyStats_transactions_ops{collection="testcol_00",database="testdb"} 0
mongodb_collstats_latencyStats_transactions_ops{collection="testcol_01",database="testdb"} 0
mongodb_collstats_latencyStats_transactions_ops{collection="testcol_02",database="testdb"} 0
mongodb_collstats_latencyStats_transactions_ops{collection="testcol_00",database="testdb",shard="rs1"} 0
mongodb_collstats_latencyStats_transactions_ops{collection="testcol_01",database="testdb",shard="rs1"} 0
mongodb_collstats_latencyStats_transactions_ops{collection="testcol_02",database="testdb",shard="rs1"} 0
# HELP mongodb_collstats_storageStats_capped collstats.storageStats.
# TYPE mongodb_collstats_storageStats_capped untyped
mongodb_collstats_storageStats_capped{collection="testcol_00",database="testdb"} 0
mongodb_collstats_storageStats_capped{collection="testcol_01",database="testdb"} 0
mongodb_collstats_storageStats_capped{collection="testcol_02",database="testdb"} 0` +
mongodb_collstats_storageStats_capped{collection="testcol_00",database="testdb",shard="rs1"} 0
mongodb_collstats_storageStats_capped{collection="testcol_01",database="testdb",shard="rs1"} 0
mongodb_collstats_storageStats_capped{collection="testcol_02",database="testdb",shard="rs1"} 0` +
"\n")

// Filter metrics for 2 reasons:
Expand Down

0 comments on commit 0b97543

Please sign in to comment.