@@ -12,6 +12,9 @@ pub use prometheus::Registry;
1212
1313use super :: RouteDoc ;
1414
15+ /// Metric prefix for all HTTP service metrics
16+ pub const FRONTEND_METRIC_PREFIX : & str = "dynamo_frontend" ;
17+
1518/// Value for the `status` label in the request counter for successful requests
1619pub const REQUEST_STATUS_SUCCESS : & str = "success" ;
1720
@@ -24,6 +27,11 @@ pub const REQUEST_TYPE_STREAM: &str = "stream";
2427/// Partial value for the `type` label in the request counter for unary requests
2528pub const REQUEST_TYPE_UNARY : & str = "unary" ;
2629
30+ /// Helper function to construct metric names with the standard prefix
31+ fn frontend_metric_name ( suffix : & str ) -> String {
32+ format ! ( "{}_{}" , FRONTEND_METRIC_PREFIX , suffix)
33+ }
34+
2735pub struct Metrics {
2836 request_counter : IntCounterVec ,
2937 inflight_gauge : IntGaugeVec ,
@@ -99,7 +107,7 @@ impl Default for Metrics {
99107}
100108
101109impl Metrics {
102- /// Create Metrics with hardcoded "dynamo" prefix
110+ /// Create Metrics with the standard prefix defined by [`FRONTEND_METRIC_PREFIX`]
103111 /// The following metrics will be created:
104112 /// - `dynamo_frontend_requests_total` - IntCounterVec for the total number of requests processed
105113 /// - `dynamo_frontend_inflight_requests` - IntGaugeVec for the number of inflight requests
@@ -111,7 +119,7 @@ impl Metrics {
111119 pub fn new ( ) -> Self {
112120 let request_counter = IntCounterVec :: new (
113121 Opts :: new (
114- "dynamo_frontend_requests_total" ,
122+ frontend_metric_name ( "requests_total" ) ,
115123 "Total number of LLM requests processed" ,
116124 ) ,
117125 & [ "model" , "endpoint" , "request_type" , "status" ] ,
@@ -120,7 +128,7 @@ impl Metrics {
120128
121129 let inflight_gauge = IntGaugeVec :: new (
122130 Opts :: new (
123- "dynamo_frontend_inflight_requests" ,
131+ frontend_metric_name ( "inflight_requests" ) ,
124132 "Number of inflight requests" ,
125133 ) ,
126134 & [ "model" ] ,
@@ -131,7 +139,7 @@ impl Metrics {
131139
132140 let request_duration = HistogramVec :: new (
133141 HistogramOpts :: new (
134- "dynamo_frontend_request_duration_seconds" ,
142+ frontend_metric_name ( "request_duration_seconds" ) ,
135143 "Duration of LLM requests" ,
136144 )
137145 . buckets ( buckets) ,
@@ -141,7 +149,7 @@ impl Metrics {
141149
142150 let input_sequence_length = HistogramVec :: new (
143151 HistogramOpts :: new (
144- "dynamo_frontend_input_sequence_tokens" ,
152+ frontend_metric_name ( "input_sequence_tokens" ) ,
145153 "Input sequence length in tokens" ,
146154 )
147155 . buckets ( vec ! [
@@ -154,7 +162,7 @@ impl Metrics {
154162
155163 let output_sequence_length = HistogramVec :: new (
156164 HistogramOpts :: new (
157- "dynamo_frontend_output_sequence_tokens" ,
165+ frontend_metric_name ( "output_sequence_tokens" ) ,
158166 "Output sequence length in tokens" ,
159167 )
160168 . buckets ( vec ! [
@@ -166,7 +174,7 @@ impl Metrics {
166174
167175 let time_to_first_token = HistogramVec :: new (
168176 HistogramOpts :: new (
169- "dynamo_frontend_time_to_first_token_seconds" ,
177+ frontend_metric_name ( "time_to_first_token_seconds" ) ,
170178 "Time to first token in seconds" ,
171179 )
172180 . buckets ( vec ! [
@@ -179,7 +187,7 @@ impl Metrics {
179187
180188 let inter_token_latency = HistogramVec :: new (
181189 HistogramOpts :: new (
182- "dynamo_frontend_inter_token_latency_seconds" ,
190+ frontend_metric_name ( "inter_token_latency_seconds" ) ,
183191 "Inter-token latency in seconds" ,
184192 )
185193 . buckets ( vec ! [
0 commit comments