Skip to main content

canic_core/dto/
metrics.rs

1use crate::dto::prelude::*;
2
3//
4// Metrics DTOs
5//
6
7//
8// MetricsKind
9//
10// Metric family selector.
11//
12
13#[derive(CandidType, Clone, Copy, Deserialize)]
14#[remain::sorted]
15pub enum MetricsKind {
16    Access,
17    CanisterOps,
18    Cascade,
19    CyclesFunding,
20    CyclesTopup,
21    DelegatedAuth,
22    Directory,
23    Http,
24    Icc,
25    Lifecycle,
26    Perf,
27    Pool,
28    RootCapability,
29    Scaling,
30    #[cfg(feature = "sharding")]
31    Sharding,
32    System,
33    Timer,
34    WasmStore,
35}
36
37//
38// MetricEntry
39//
40// Unified metrics row.
41//
42
43#[derive(CandidType, Deserialize)]
44pub struct MetricEntry {
45    // Ordered labels.
46    pub labels: Vec<String>,
47
48    // Optional principal dimension.
49    pub principal: Option<Principal>,
50
51    // Metric payload.
52    pub value: MetricValue,
53}
54
55//
56// MetricValue
57//
58
59#[derive(CandidType, Deserialize)]
60pub enum MetricValue {
61    Count(u64),
62    CountAndU64 { count: u64, value_u64: u64 },
63    U128(u128),
64}
65
66//
67// QueryPerfSample
68//
69// Same-call query performance sample.
70//
71
72#[derive(CandidType, Deserialize)]
73pub struct QueryPerfSample<T> {
74    // Query result returned by the probe.
75    pub value: T,
76
77    // Local instruction counter observed in the same query call context.
78    pub local_instructions: u64,
79}