use ::metrics::{counter, describe_counter, describe_gauge, describe_histogram, gauge, histogram};
const TARGET_TLS_RELOAD_TOTAL: &str = "rustfs_target_tls_reload_total";
const TARGET_TLS_RELOAD_SKIPPED_TOTAL: &str = "rustfs_target_tls_reload_skipped_total";
const TARGET_TLS_GENERATION: &str = "rustfs_target_tls_generation";
const TARGET_TLS_RELOAD_DURATION_SECONDS: &str = "rustfs_target_tls_reload_duration_seconds";
const TARGET_TLS_PUBLICATION_FAIL_TOTAL: &str = "rustfs_target_tls_publication_fail_total";
const TARGET_TLS_ACTIVE_GENERATION_MISMATCH_TOTAL: &str = "rustfs_target_tls_active_generation_mismatch_total";
pub fn init_target_tls_metrics() {
describe_counter!(TARGET_TLS_RELOAD_TOTAL, "Total number of TLS reload attempts per target");
describe_counter!(
TARGET_TLS_RELOAD_SKIPPED_TOTAL,
"Number of TLS reloads skipped per target (unchanged, etc.)"
);
describe_gauge!(TARGET_TLS_GENERATION, "Current TLS generation per target");
describe_histogram!(TARGET_TLS_RELOAD_DURATION_SECONDS, "Duration of TLS reload attempts per target");
describe_counter!(TARGET_TLS_PUBLICATION_FAIL_TOTAL, "Number of TLS reload publication failures per target");
describe_counter!(
TARGET_TLS_ACTIVE_GENERATION_MISMATCH_TOTAL,
"Number of times a target's active connection used a stale TLS generation"
);
}
pub fn record_target_tls_reload_result(target: &str, result: &str, duration_secs: f64, generation: u64) {
counter!(TARGET_TLS_RELOAD_TOTAL, "target_id" => target.to_string(), "result" => result.to_string()).increment(1);
histogram!(TARGET_TLS_RELOAD_DURATION_SECONDS, "target_id" => target.to_string(), "result" => result.to_string())
.record(duration_secs);
gauge!(TARGET_TLS_GENERATION, "target_id" => target.to_string()).set(generation as f64);
}
pub fn record_target_tls_reload_skipped(target: &str, reason: &str) {
counter!(TARGET_TLS_RELOAD_SKIPPED_TOTAL, "target_id" => target.to_string(), "reason" => reason.to_string()).increment(1);
}
pub fn record_target_tls_publication_fail(target: &str) {
counter!(TARGET_TLS_PUBLICATION_FAIL_TOTAL, "target_id" => target.to_string()).increment(1);
}
pub fn record_target_tls_stale_generation(target: &str) {
counter!(TARGET_TLS_ACTIVE_GENERATION_MISMATCH_TOTAL, "target_id" => target.to_string()).increment(1);
}