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