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    Auth,
18    CanisterOps,
19    Cascade,
20    CyclesFunding,
21    CyclesTopup,
22    DelegatedAuth,
23    Directory,
24    Http,
25    Icc,
26    Lifecycle,
27    Perf,
28    Pool,
29    Replay,
30    RootCapability,
31    Scaling,
32    #[cfg(feature = "sharding")]
33    Sharding,
34    System,
35    Timer,
36    WasmStore,
37}
38
39//
40// MetricEntry
41//
42// Unified metrics row.
43//
44
45#[derive(CandidType, Deserialize)]
46pub struct MetricEntry {
47    // Ordered labels.
48    pub labels: Vec<String>,
49
50    // Optional principal dimension.
51    pub principal: Option<Principal>,
52
53    // Metric payload.
54    pub value: MetricValue,
55}
56
57//
58// MetricValue
59//
60
61#[derive(CandidType, Deserialize)]
62pub enum MetricValue {
63    Count(u64),
64    CountAndU64 { count: u64, value_u64: u64 },
65    U128(u128),
66}
67
68//
69// QueryPerfSample
70//
71// Same-call query performance sample.
72//
73
74#[derive(CandidType, Deserialize)]
75pub struct QueryPerfSample<T> {
76    // Query result returned by the probe.
77    pub value: T,
78
79    // Local instruction counter observed in the same query call context.
80    pub local_instructions: u64,
81}