Skip to content

Commit 9926adb

Browse files
add cached and reasoning token to the metrics (#1465)
to be used in enterprise
1 parent 8cfced3 commit 9926adb

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/metrics/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,30 @@ pub static TOTAL_OUTPUT_LLM_TOKENS_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
334334
.expect("metric can be created")
335335
});
336336

337+
pub static TOTAL_CACHED_LLM_TOKENS_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
338+
IntCounterVec::new(
339+
Opts::new(
340+
"total_cached_llm_tokens_by_date",
341+
"Total cached LLM tokens used by date",
342+
)
343+
.namespace(METRICS_NAMESPACE),
344+
&["provider", "model", "date"],
345+
)
346+
.expect("metric can be created")
347+
});
348+
349+
pub static TOTAL_REASONING_LLM_TOKENS_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
350+
IntCounterVec::new(
351+
Opts::new(
352+
"total_reasoning_llm_tokens_by_date",
353+
"Total reasoning LLM tokens used by date",
354+
)
355+
.namespace(METRICS_NAMESPACE),
356+
&["provider", "model", "date"],
357+
)
358+
.expect("metric can be created")
359+
});
360+
337361
pub static STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| {
338362
HistogramVec::new(
339363
HistogramOpts::new("storage_request_response_time", "Storage Request Latency")
@@ -433,6 +457,12 @@ fn custom_metrics(registry: &Registry) {
433457
registry
434458
.register(Box::new(TOTAL_OUTPUT_LLM_TOKENS_BY_DATE.clone()))
435459
.expect("metric can be registered");
460+
registry
461+
.register(Box::new(TOTAL_CACHED_LLM_TOKENS_BY_DATE.clone()))
462+
.expect("metric can be registered");
463+
registry
464+
.register(Box::new(TOTAL_REASONING_LLM_TOKENS_BY_DATE.clone()))
465+
.expect("metric can be registered");
436466
registry
437467
.register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone()))
438468
.expect("metric can be registered");
@@ -566,6 +596,23 @@ pub fn increment_output_llm_tokens_by_date(provider: &str, model: &str, tokens:
566596
.inc_by(tokens);
567597
}
568598

599+
pub fn increment_cached_llm_tokens_by_date(provider: &str, model: &str, tokens: u64, date: &str) {
600+
TOTAL_CACHED_LLM_TOKENS_BY_DATE
601+
.with_label_values(&[provider, model, date])
602+
.inc_by(tokens);
603+
}
604+
605+
pub fn increment_reasoning_llm_tokens_by_date(
606+
provider: &str,
607+
model: &str,
608+
tokens: u64,
609+
date: &str,
610+
) {
611+
TOTAL_REASONING_LLM_TOKENS_BY_DATE
612+
.with_label_values(&[provider, model, date])
613+
.inc_by(tokens);
614+
}
615+
569616
use actix_web::HttpResponse;
570617

571618
pub async fn get() -> Result<impl Responder, MetricsError> {

0 commit comments

Comments
 (0)