feat: expose transaction types via /metrics (#2336)

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2023-12-26 15:22:14 +02:00 committed by GitHub
parent 1caa4ee0f1
commit 5b81ccda18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -887,6 +887,32 @@ void PrintPrometheusMetrics(const Metrics& m, StringResponse* resp) {
AppendMetricWithoutLabels("fiber_longrun_seconds_total", "", longrun_seconds, MetricType::COUNTER,
&resp->body());
AppendMetricWithoutLabels("tx_queue_len", "", m.tx_queue_len, MetricType::GAUGE, &resp->body());
AppendMetricHeader("transaction_widths_total", "Transaction counts by their widths",
MetricType::COUNTER, &resp->body());
for (unsigned width = 0; width < shard_set->size(); ++width) {
uint64_t count = m.coordinator_stats.tx_width_freq_arr[width];
if (count > 0) {
AppendMetricValue("transaction_widths_total", count, {"width"}, {StrCat("w", width + 1)},
&resp->body());
}
}
const auto& tc = m.coordinator_stats.tx_type_cnt;
AppendMetricHeader("transaction_types_total", "Transaction counts by their types",
MetricType::COUNTER, &resp->body());
const char* kTxTypeNames[ServerState::NUM_TX_TYPES] = {"global", "normal", "ooo", "quick",
"inline"};
for (unsigned type = 0; type < ServerState::NUM_TX_TYPES; ++type) {
if (tc[type] > 0) {
AppendMetricValue("transaction_types_total", tc[type], {"type"}, {kTxTypeNames[type]},
&resp->body());
}
}
absl::StrAppend(&resp->body(), db_key_metrics);
absl::StrAppend(&resp->body(), db_key_expire_metrics);
}