1use prometheus::{
5 Histogram, HistogramVec, IntCounter, IntCounterVec, Registry,
6 register_histogram_vec_with_registry, register_histogram_with_registry,
7 register_int_counter_vec_with_registry, register_int_counter_with_registry,
8};
9
10#[derive(Clone)]
11pub struct OracleMetrics {
12 pub(crate) data_source_successes: IntCounterVec,
13 pub(crate) data_source_errors: IntCounterVec,
14 pub(crate) data_staleness: IntCounterVec,
15 pub(crate) upload_successes: IntCounterVec,
16 pub(crate) upload_data_errors: IntCounterVec,
17 pub(crate) download_successes: IntCounterVec,
18 pub(crate) download_data_errors: IntCounterVec,
19 pub(crate) uploaded_values: HistogramVec,
20 pub(crate) downloaded_values: HistogramVec,
21
22 pub(crate) total_gas_cost: IntCounter,
23 pub(crate) total_gas_rebate: IntCounter,
24 pub(crate) computation_gas_used: Histogram,
25 pub(crate) total_data_points_uploaded: IntCounter,
26}
27
28impl OracleMetrics {
29 pub fn new(registry: &Registry) -> Self {
30 Self {
31 data_source_successes: register_int_counter_vec_with_registry!(
32 "oracle_data_source_successes",
33 "Total number of successful data retrieval requests to data sources",
34 &["feed", "source"],
35 registry,
36 )
37 .unwrap(),
38 data_source_errors: register_int_counter_vec_with_registry!(
39 "oracle_data_source_errors",
40 "Total number of erroneous data retrieval requests to data sources",
41 &["feed", "source"],
42 registry,
43 )
44 .unwrap(),
45 data_staleness: register_int_counter_vec_with_registry!(
46 "oracle_data_staleness",
47 "Total number of stale data that are skipped",
48 &["feed"],
49 registry,
50 )
51 .unwrap(),
52 upload_successes: register_int_counter_vec_with_registry!(
53 "oracle_upload_successes",
54 "Total number of successful data upload",
55 &["feed"],
56 registry,
57 )
58 .unwrap(),
59 upload_data_errors: register_int_counter_vec_with_registry!(
60 "oracle_upload_data_errors",
61 "Total number of erroneous data upload",
62 &["feed"],
63 registry,
64 )
65 .unwrap(),
66 download_successes: register_int_counter_vec_with_registry!(
67 "oracle_download_successes",
68 "Total number of successful data download",
69 &["feed", "object_id"],
70 registry,
71 )
72 .unwrap(),
73 download_data_errors: register_int_counter_vec_with_registry!(
74 "oracle_download_data_errors",
75 "Total number of erroneous data download",
76 &["feed", "object_id"],
77 registry,
78 )
79 .unwrap(),
80 uploaded_values: register_histogram_vec_with_registry!(
81 "oracle_uploaded_values",
82 "Values uploaded on chain",
83 &["feed"],
84 mysten_metrics::COUNT_BUCKETS.to_vec(),
85 registry,
86 )
87 .unwrap(),
88 downloaded_values: register_histogram_vec_with_registry!(
89 "oracle_downloaded_values",
90 "Values downloaded on chain",
91 &["feed"],
92 mysten_metrics::COUNT_BUCKETS.to_vec(),
93 registry,
94 )
95 .unwrap(),
96 total_gas_cost: register_int_counter_with_registry!(
97 "oracle_total_gas_cost",
98 "Total number of gas used, before gas rebate",
99 registry,
100 )
101 .unwrap(),
102 total_gas_rebate: register_int_counter_with_registry!(
103 "oracle_total_gas_rebate",
104 "Total number of gas rebate",
105 registry,
106 )
107 .unwrap(),
108 computation_gas_used: register_histogram_with_registry!(
109 "oracle_computation_gas_used",
110 "computation gas used",
111 mysten_metrics::COUNT_BUCKETS.to_vec(),
112 registry,
113 )
114 .unwrap(),
115 total_data_points_uploaded: register_int_counter_with_registry!(
116 "oracle_total_data_points_uploaded",
117 "Total number of data points uploaded",
118 registry,
119 )
120 .unwrap(),
121 }
122 }
123}