agentmail/types/
metrics.rs1use std::collections::BTreeMap;
2
3use crate::util::QueryBuilder;
4use serde::Deserialize;
5
6#[derive(Clone, Debug, Deserialize)]
8pub struct MetricBucket {
9 pub timestamp: String,
11 pub count: i64,
13}
14
15#[derive(Clone, Debug, Deserialize)]
17pub struct UsagePoint {
18 pub timestamp: String,
20 pub value: i64,
22}
23
24pub type MetricsEvents = BTreeMap<String, Vec<MetricBucket>>;
26
27pub type MetricsUsage = BTreeMap<String, Vec<UsagePoint>>;
29
30#[derive(Clone, Debug, Default)]
34pub struct MetricsQuery {
35 pub types: Vec<String>,
37 pub start: Option<String>,
39 pub end: Option<String>,
41 pub period: Option<u32>,
43 pub limit: Option<u32>,
45 pub descending: Option<bool>,
47}
48
49impl MetricsQuery {
50 pub(crate) fn query(&self, types_key: &'static str) -> Vec<(&'static str, String)> {
51 QueryBuilder::new()
52 .many(types_key, &self.types)
53 .opt("start", self.start.as_ref())
54 .opt("end", self.end.as_ref())
55 .opt("period", self.period.as_ref())
56 .opt("limit", self.limit.as_ref())
57 .opt("descending", self.descending.as_ref())
58 .build()
59 }
60}