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    System,
31    Timer,
32    WasmStore,
33}
34
35//
36// MetricEntry
37//
38// Unified metrics row.
39//
40
41#[derive(CandidType, Deserialize)]
42pub struct MetricEntry {
43    // Ordered labels.
44    pub labels: Vec<String>,
45
46    // Optional principal dimension.
47    pub principal: Option<Principal>,
48
49    // Metric payload.
50    pub value: MetricValue,
51}
52
53//
54// MetricValue
55//
56
57#[derive(CandidType, Deserialize)]
58pub enum MetricValue {
59    Count(u64),
60    CountAndU64 { count: u64, value_u64: u64 },
61    U128(u128),
62}
63
64//
65// QueryPerfSample
66//
67// Same-call query performance sample.
68//
69
70#[derive(CandidType, Deserialize)]
71pub struct QueryPerfSample<T> {
72    // Query result returned by the probe.
73    pub value: T,
74
75    // Local instruction counter observed in the same query call context.
76    pub local_instructions: u64,
77}