cat_gateway/metrics/
health.rs1use crate::{
4 service::api::health::{live_get, ready_get, started_get},
5 settings::Settings,
6};
7
8pub(crate) async fn update() {
10 let api_host_names = Settings::api_host_names().join(",");
11 let service_id = Settings::service_id();
12
13 if matches!(
14 live_get::endpoint().await,
15 live_get::AllResponses::With(live_get::Responses::NoContent)
16 ) {
17 reporter::LIVE_INDICATOR
18 .with_label_values(&[&api_host_names, service_id])
19 .set(1);
20 } else {
21 reporter::LIVE_INDICATOR
22 .with_label_values(&[&api_host_names, service_id])
23 .set(0);
24 }
25
26 if matches!(
27 ready_get::endpoint().await,
28 ready_get::AllResponses::With(ready_get::Responses::NoContent)
29 ) {
30 reporter::READY_INDICATOR
31 .with_label_values(&[&api_host_names, service_id])
32 .set(1);
33 } else {
34 reporter::READY_INDICATOR
35 .with_label_values(&[&api_host_names, service_id])
36 .set(0);
37 }
38
39 if matches!(
40 started_get::endpoint().await,
41 started_get::AllResponses::With(started_get::Responses::NoContent)
42 ) {
43 reporter::STARTED_INDICATOR
44 .with_label_values(&[&api_host_names, service_id])
45 .set(1);
46 } else {
47 reporter::STARTED_INDICATOR
48 .with_label_values(&[&api_host_names, service_id])
49 .set(0);
50 }
51}
52
53pub(crate) mod reporter {
56 use std::sync::LazyLock;
57
58 use prometheus::{register_int_gauge_vec, IntGaugeVec};
59
60 const METRIC_LABELS: [&str; 2] = ["api_host_names", "service_id"];
62
63 pub(crate) static LIVE_INDICATOR: LazyLock<IntGaugeVec> = LazyLock::new(|| {
65 register_int_gauge_vec!(
66 "health_live_indicator",
67 "Health `live` endpoint indicator whether its healthy or not, returns the response `204` or something else.",
68 &METRIC_LABELS
69 )
70 .unwrap()
71 });
72
73 pub(crate) static STARTED_INDICATOR: LazyLock<IntGaugeVec> = LazyLock::new(|| {
75 register_int_gauge_vec!(
76 "health_started_indicator",
77 "Health `started` endpoint indicator whether its healthy or not, returns the response `204` or something else.",
78 &METRIC_LABELS
79 )
80 .unwrap()
81 });
82
83 pub(crate) static READY_INDICATOR: LazyLock<IntGaugeVec> = LazyLock::new(|| {
85 register_int_gauge_vec!(
86 "health_ready_indicator",
87 "Health `ready` endpoint indicator whether its healthy or not, returns the response `204` or something else.",
88 &METRIC_LABELS
89 )
90 .unwrap()
91 });
92}