prometheus_names.rs 5.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Prometheus metric name constants
//!
//! This module provides centralized Prometheus metric name constants for various components
//! to ensure consistency and avoid duplication across the codebase.

/// Builds a full metric name by prepending the component prefix
pub fn build_metric_name(metric_name: &str) -> String {
    format!("{}{}", name_prefix::COMPONENT, metric_name)
}

/// Metric name prefixes used across the metrics system
pub mod name_prefix {
    /// Prefix for all Prometheus metric names.
    pub const COMPONENT: &str = "dynamo_component_";

    // TODO(keivenc): uncomment below for the frontend
    // pub const FRONTEND: &str = "dynamo_frontend_";
}

/// Automatically inserted Prometheus label names used across the metrics system
pub mod labels {
    /// Label for component identification
    pub const COMPONENT: &str = "dynamo_component";

    /// Label for namespace identification
    pub const NAMESPACE: &str = "dynamo_namespace";

    /// Label for endpoint identification
    pub const ENDPOINT: &str = "dynamo_endpoint";
}

35
36
37
38
39
40
41
42
43
/// NATS client metrics. DistributedRuntime contains a NATS client shared by all children)
pub mod nats_client {
    /// Macro to generate NATS client metric names with the prefix
    macro_rules! nats_client_name {
        ($name:expr) => {
            concat!("nats_client_", $name)
        };
    }

44
    /// Prefix for all NATS client metrics
45
    pub const PREFIX: &str = nats_client_name!("");
46
47

    /// Total number of bytes received by NATS client
48
    pub const IN_TOTAL_BYTES: &str = nats_client_name!("in_total_bytes");
49
50

    /// Total number of bytes sent by NATS client
51
    pub const OUT_OVERHEAD_BYTES: &str = nats_client_name!("out_overhead_bytes");
52
53

    /// Total number of messages received by NATS client
54
    pub const IN_MESSAGES: &str = nats_client_name!("in_messages");
55
56

    /// Total number of messages sent by NATS client
57
    pub const OUT_MESSAGES: &str = nats_client_name!("out_messages");
58
59

    /// Total number of connections established by NATS client
60
    pub const CONNECTS: &str = nats_client_name!("connects");
61
62

    /// Current connection state of NATS client (0=disconnected, 1=connected, 2=reconnecting)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    pub const CONNECTION_STATE: &str = nats_client_name!("connection_state");
}

/// NATS service metrics, from the $SRV.STATS.<service_name> requests on NATS server
pub mod nats_service {
    /// Macro to generate NATS service metric names with the prefix
    macro_rules! nats_service_name {
        ($name:expr) => {
            concat!("nats_service_", $name)
        };
    }

    /// Prefix for all NATS service metrics
    pub const PREFIX: &str = nats_service_name!("");
77
78

    /// Average processing time in milliseconds (maps to: average_processing_time in ms)
79
    pub const AVG_PROCESSING_MS: &str = nats_service_name!("avg_processing_time_ms");
80
81

    /// Total errors across all endpoints (maps to: num_errors)
82
    pub const TOTAL_ERRORS: &str = nats_service_name!("total_errors");
83
84

    /// Total requests across all endpoints (maps to: num_requests)
85
    pub const TOTAL_REQUESTS: &str = nats_service_name!("total_requests");
86
87

    /// Total processing time in milliseconds (maps to: processing_time in ms)
88
    pub const TOTAL_PROCESSING_MS: &str = nats_service_name!("total_processing_time_ms");
89
90

    /// Number of active services (derived from ServiceSet.services)
91
    pub const ACTIVE_SERVICES: &str = nats_service_name!("active_services");
92
93

    /// Number of active endpoints (derived from ServiceInfo.endpoints)
94
    pub const ACTIVE_ENDPOINTS: &str = nats_service_name!("active_endpoints");
95
96
97
98
}

/// All NATS client Prometheus metric names as an array for iteration/validation
pub const DRT_NATS_METRICS: &[&str] = &[
99
100
101
102
103
104
    nats_client::CONNECTION_STATE,
    nats_client::CONNECTS,
    nats_client::IN_TOTAL_BYTES,
    nats_client::IN_MESSAGES,
    nats_client::OUT_OVERHEAD_BYTES,
    nats_client::OUT_MESSAGES,
105
106
107
108
109
];

/// All component service Prometheus metric names as an array for iteration/validation
/// (ordered to match NatsStatsMetrics fields)
pub const COMPONENT_NATS_METRICS: &[&str] = &[
110
111
112
113
114
115
    nats_service::AVG_PROCESSING_MS, // maps to: average_processing_time (nanoseconds)
    nats_service::TOTAL_ERRORS,      // maps to: num_errors
    nats_service::TOTAL_REQUESTS,    // maps to: num_requests
    nats_service::TOTAL_PROCESSING_MS, // maps to: processing_time (nanoseconds)
    nats_service::ACTIVE_SERVICES,   // derived from ServiceSet.services
    nats_service::ACTIVE_ENDPOINTS,  // derived from ServiceInfo.endpoints
116
117
118
119
120
121
122
123
124
125
126
127
128
129
];

/// Work handler Prometheus metric names
pub mod work_handler {
    /// Total number of requests processed by work handler
    pub const REQUESTS_TOTAL: &str = "requests_total";

    /// Total number of bytes received in requests by work handler
    pub const REQUEST_BYTES_TOTAL: &str = "request_bytes_total";

    /// Total number of bytes sent in responses by work handler
    pub const RESPONSE_BYTES_TOTAL: &str = "response_bytes_total";

    /// Number of requests currently being processed by work handler
130
    pub const INFLIGHT_REQUESTS: &str = "inflight_requests";
131
132
133
134

    /// Time spent processing requests by work handler (histogram)
    pub const REQUEST_DURATION_SECONDS: &str = "request_duration_seconds";
}