Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,30 @@ pub static TOTAL_OUTPUT_LLM_TOKENS_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
.expect("metric can be created")
});

pub static TOTAL_CACHED_LLM_TOKENS_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
IntCounterVec::new(
Opts::new(
"total_cached_llm_tokens_by_date",
"Total cached LLM tokens used by date",
)
.namespace(METRICS_NAMESPACE),
&["provider", "model", "date"],
)
.expect("metric can be created")
});

pub static TOTAL_REASONING_LLM_TOKENS_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
IntCounterVec::new(
Opts::new(
"total_reasoning_llm_tokens_by_date",
"Total reasoning LLM tokens used by date",
)
.namespace(METRICS_NAMESPACE),
&["provider", "model", "date"],
)
.expect("metric can be created")
});

pub static STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| {
HistogramVec::new(
HistogramOpts::new("storage_request_response_time", "Storage Request Latency")
Expand Down Expand Up @@ -433,6 +457,12 @@ fn custom_metrics(registry: &Registry) {
registry
.register(Box::new(TOTAL_OUTPUT_LLM_TOKENS_BY_DATE.clone()))
.expect("metric can be registered");
registry
.register(Box::new(TOTAL_CACHED_LLM_TOKENS_BY_DATE.clone()))
.expect("metric can be registered");
registry
.register(Box::new(TOTAL_REASONING_LLM_TOKENS_BY_DATE.clone()))
.expect("metric can be registered");
registry
.register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone()))
.expect("metric can be registered");
Expand Down Expand Up @@ -566,6 +596,23 @@ pub fn increment_output_llm_tokens_by_date(provider: &str, model: &str, tokens:
.inc_by(tokens);
}

pub fn increment_cached_llm_tokens_by_date(provider: &str, model: &str, tokens: u64, date: &str) {
TOTAL_CACHED_LLM_TOKENS_BY_DATE
.with_label_values(&[provider, model, date])
.inc_by(tokens);
}

pub fn increment_reasoning_llm_tokens_by_date(
provider: &str,
model: &str,
tokens: u64,
date: &str,
) {
TOTAL_REASONING_LLM_TOKENS_BY_DATE
.with_label_values(&[provider, model, date])
.inc_by(tokens);
}

use actix_web::HttpResponse;

pub async fn get() -> Result<impl Responder, MetricsError> {
Expand Down
Loading