prometheus/
plain_model.rs

1// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
2
3//! Non-generated version of required structures provided by the protobuf.
4//! This version is used when the `protobuf` feature is turned off.
5
6#![allow(missing_docs)]
7
8#[derive(PartialEq, Clone, Default, Debug)]
9pub struct LabelPair {
10    name: String,
11    value: String,
12}
13
14impl LabelPair {
15    #[deprecated(note = "Use default()", since = "0.5.1")]
16    pub fn new() -> LabelPair {
17        Default::default()
18    }
19
20    #[deprecated(
21        note = "This method is protobuf specific and will be removed in a future version",
22        since = "0.5.1"
23    )]
24    pub fn clear_name(&mut self) {
25        self.name.clear();
26    }
27
28    pub fn set_name(&mut self, v: String) {
29        self.name = v;
30    }
31
32    #[deprecated(since = "0.14.0", note = "Please use `.name()` instead")]
33    pub fn get_name(&self) -> &str {
34        self.name()
35    }
36
37    /// Returns the name of this label pair.
38    pub fn name(&self) -> &str {
39        &self.name
40    }
41
42    pub fn set_value(&mut self, v: String) {
43        self.value = v;
44    }
45
46    #[deprecated(since = "0.14.0", note = "Please use `.value()` instead")]
47    pub fn get_value(&self) -> &str {
48        self.value()
49    }
50
51    /// Returns the value of this label pair.
52    pub fn value(&self) -> &str {
53        &self.value
54    }
55}
56
57#[derive(PartialEq, Clone, Default, Debug)]
58pub struct Gauge {
59    value: f64,
60}
61
62impl Gauge {
63    #[deprecated(note = "Use default()", since = "0.5.1")]
64    pub fn new() -> Gauge {
65        Default::default()
66    }
67
68    pub fn set_value(&mut self, v: f64) {
69        self.value = v;
70    }
71
72    pub fn get_value(&self) -> f64 {
73        self.value
74    }
75}
76
77#[derive(PartialEq, Clone, Default, Debug)]
78pub struct Counter {
79    value: f64,
80}
81
82impl Counter {
83    #[deprecated(note = "Use default()", since = "0.5.1")]
84    pub fn new() -> Counter {
85        Default::default()
86    }
87
88    // Param is passed by value, moved
89    pub fn set_value(&mut self, v: f64) {
90        self.value = v;
91    }
92
93    pub fn get_value(&self) -> f64 {
94        self.value
95    }
96}
97
98#[derive(PartialEq, Clone, Default, Debug)]
99pub struct Quantile {
100    quantile: f64,
101    value: f64,
102}
103
104impl Quantile {
105    #[deprecated(note = "Use default()", since = "0.5.1")]
106    pub fn new() -> Quantile {
107        Default::default()
108    }
109
110    pub fn set_quantile(&mut self, v: f64) {
111        self.quantile = v;
112    }
113
114    #[deprecated(since = "0.14.0", note = "Please use `.quantile()` instead")]
115    pub fn get_quantile(&self) -> f64 {
116        self.quantile()
117    }
118
119    /// Returns the quantile of this quantile.
120    pub fn quantile(&self) -> f64 {
121        self.quantile
122    }
123
124    pub fn set_value(&mut self, v: f64) {
125        self.value = v;
126    }
127
128    #[deprecated(since = "0.14.0", note = "Please use `.value()` instead")]
129    pub fn get_value(&self) -> f64 {
130        self.value()
131    }
132
133    /// Returns the value of this quantile.
134    pub fn value(&self) -> f64 {
135        self.value
136    }
137}
138
139#[derive(PartialEq, Clone, Default, Debug)]
140pub struct Summary {
141    sample_count: u64,
142    sample_sum: f64,
143    quantile: Vec<Quantile>,
144}
145
146impl Summary {
147    #[deprecated(note = "Use default()", since = "0.5.1")]
148    pub fn new() -> Summary {
149        Default::default()
150    }
151
152    pub fn set_sample_count(&mut self, v: u64) {
153        self.sample_count = v;
154    }
155
156    #[deprecated(since = "0.14.0", note = "Please use `.sample_count()` instead")]
157    pub fn get_sample_count(&self) -> u64 {
158        self.sample_count
159    }
160
161    /// Returns the sample count of this summary.
162    pub fn sample_count(&self) -> u64 {
163        self.sample_count
164    }
165
166    pub fn set_sample_sum(&mut self, v: f64) {
167        self.sample_sum = v;
168    }
169
170    #[deprecated(since = "0.14.0", note = "Please use `.sample_sum()` instead")]
171    pub fn get_sample_sum(&self) -> f64 {
172        self.sample_sum()
173    }
174
175    /// Returns the sample sum of this summary.
176    pub fn sample_sum(&self) -> f64 {
177        self.sample_sum
178    }
179
180    pub fn set_quantile(&mut self, v: Vec<Quantile>) {
181        self.quantile = v;
182    }
183
184    pub fn get_quantile(&self) -> &[Quantile] {
185        &self.quantile
186    }
187}
188
189#[derive(PartialEq, Clone, Default, Debug)]
190pub struct Untyped {
191    value: f64,
192}
193
194impl Untyped {
195    #[deprecated(note = "Use default()", since = "0.5.1")]
196    pub fn new() -> Untyped {
197        Default::default()
198    }
199
200    #[deprecated(
201        note = "Untyped struct is protobuf specific and will be removed in a future version",
202        since = "0.5.1"
203    )]
204    pub fn set_value(&mut self, v: f64) {
205        self.value = v;
206    }
207
208    #[deprecated(
209        note = "Untyped struct is protobuf specific and will be removed in a future version",
210        since = "0.5.1"
211    )]
212    pub fn get_value(&self) -> f64 {
213        self.value
214    }
215}
216
217#[derive(PartialEq, Clone, Default, Debug)]
218pub struct Histogram {
219    sample_count: u64,
220    sample_sum: f64,
221    bucket: Vec<Bucket>,
222}
223
224impl Histogram {
225    #[deprecated(note = "Use default()", since = "0.5.1")]
226    pub fn new() -> Histogram {
227        Default::default()
228    }
229
230    pub fn set_sample_count(&mut self, v: u64) {
231        self.sample_count = v;
232    }
233
234    pub fn get_sample_count(&self) -> u64 {
235        self.sample_count
236    }
237
238    pub fn set_sample_sum(&mut self, v: f64) {
239        self.sample_sum = v;
240    }
241
242    pub fn get_sample_sum(&self) -> f64 {
243        self.sample_sum
244    }
245
246    pub fn set_bucket(&mut self, v: Vec<Bucket>) {
247        self.bucket = v;
248    }
249
250    pub fn get_bucket(&self) -> &[Bucket] {
251        &self.bucket
252    }
253}
254
255#[derive(PartialEq, Clone, Default, Debug)]
256pub struct Bucket {
257    cumulative_count: u64,
258    upper_bound: f64,
259}
260
261impl Bucket {
262    #[deprecated(note = "Use default()", since = "0.5.1")]
263    pub fn new() -> Bucket {
264        Default::default()
265    }
266
267    pub fn set_cumulative_count(&mut self, v: u64) {
268        self.cumulative_count = v;
269    }
270
271    #[deprecated(since = "0.14.0", note = "Please use `.cumulative_count()` instead")]
272    pub fn get_cumulative_count(&self) -> u64 {
273        self.cumulative_count()
274    }
275
276    /// Returns the cumulative count of this bucket.
277    pub fn cumulative_count(&self) -> u64 {
278        self.cumulative_count
279    }
280
281    pub fn set_upper_bound(&mut self, v: f64) {
282        self.upper_bound = v;
283    }
284
285    #[deprecated(since = "0.14.0", note = "Please use `.upper_bound()` instead")]
286    pub fn get_upper_bound(&self) -> f64 {
287        self.upper_bound()
288    }
289
290    /// Returns the upper bound of this bucket.
291    pub fn upper_bound(&self) -> f64 {
292        self.upper_bound
293    }
294}
295
296#[derive(PartialEq, Clone, Default, Debug)]
297pub struct Metric {
298    // message fields
299    label: Vec<LabelPair>,
300    gauge: Gauge,
301    counter: Counter,
302    summary: Summary,
303    untyped: Untyped,
304    histogram: Histogram,
305    timestamp_ms: i64,
306}
307
308impl Metric {
309    #[deprecated(note = "Use default()", since = "0.5.1")]
310    pub fn new() -> Metric {
311        Default::default()
312    }
313
314    /// Creates a new metric with the specified label pairs.
315    pub fn from_label(label: Vec<LabelPair>) -> Self {
316        Metric {
317            label,
318            ..Default::default()
319        }
320    }
321
322    /// Creates a new metric with the specified gauge value.
323    pub fn from_gauge(gauge: Gauge) -> Self {
324        Metric {
325            gauge: gauge.into(),
326            ..Default::default()
327        }
328    }
329
330    pub fn set_label(&mut self, v: Vec<LabelPair>) {
331        self.label = v;
332    }
333
334    pub fn mut_label(&mut self) -> &mut [LabelPair] {
335        &mut self.label
336    }
337
338    pub fn take_label(&mut self) -> Vec<LabelPair> {
339        ::std::mem::replace(&mut self.label, Vec::new())
340    }
341
342    pub fn get_label(&self) -> &[LabelPair] {
343        &self.label
344    }
345
346    pub fn set_gauge(&mut self, v: Gauge) {
347        self.gauge = v;
348    }
349
350    pub fn get_gauge(&self) -> &Gauge {
351        &self.gauge
352    }
353
354    pub fn set_counter(&mut self, v: Counter) {
355        self.counter = v;
356    }
357
358    pub fn get_counter(&self) -> &Counter {
359        &self.counter
360    }
361
362    pub fn set_summary(&mut self, v: Summary) {
363        self.summary = v;
364    }
365
366    pub fn get_summary(&self) -> &Summary {
367        &self.summary
368    }
369
370    #[deprecated(
371        note = "This method is protobuf specific and will be removed in a future version",
372        since = "0.5.1"
373    )]
374    pub fn set_untyped(&mut self, v: Untyped) {
375        self.untyped = v;
376    }
377
378    #[deprecated(
379        note = "This method is protobuf specific and will be removed in a future version",
380        since = "0.5.1"
381    )]
382    pub fn get_untyped(&self) -> &Untyped {
383        &self.untyped
384    }
385
386    pub fn set_histogram(&mut self, v: Histogram) {
387        self.histogram = v;
388    }
389
390    pub fn get_histogram(&self) -> &Histogram {
391        &self.histogram
392    }
393
394    pub fn set_timestamp_ms(&mut self, v: i64) {
395        self.timestamp_ms = v;
396    }
397
398    #[deprecated(since = "0.14.0", note = "Please use `.timestamp_ms()` instead")]
399    pub fn get_timestamp_ms(&self) -> i64 {
400        self.timestamp_ms()
401    }
402
403    /// Returns the timestamp of this metric.
404    pub fn timestamp_ms(&self) -> i64 {
405        self.timestamp_ms
406    }
407}
408
409#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)]
410pub enum MetricType {
411    COUNTER,
412    GAUGE,
413    SUMMARY,
414    UNTYPED,
415    HISTOGRAM,
416}
417
418impl Default for MetricType {
419    fn default() -> Self {
420        MetricType::COUNTER
421    }
422}
423
424#[derive(PartialEq, Clone, Default, Debug)]
425pub struct MetricFamily {
426    name: String,
427    help: String,
428    field_type: MetricType,
429    metric: Vec<Metric>,
430}
431
432impl MetricFamily {
433    #[deprecated(note = "Use default()", since = "0.5.1")]
434    pub fn new() -> MetricFamily {
435        Default::default()
436    }
437
438    pub fn clear_name(&mut self) {
439        self.name.clear();
440    }
441
442    pub fn set_name(&mut self, v: String) {
443        self.name = v;
444    }
445
446    #[deprecated(since = "0.14.0", note = "Please use `.name()` instead")]
447    pub fn get_name(&self) -> &str {
448        self.name()
449    }
450
451    /// Returns the name of this metric family.
452    pub fn name(&self) -> &str {
453        &self.name
454    }
455
456    pub fn set_help(&mut self, v: String) {
457        self.help = v;
458    }
459
460    #[deprecated(since = "0.14.0", note = "Please use `.help()` instead")]
461    pub fn get_help(&self) -> &str {
462        self.help()
463    }
464
465    /// Returns the help text of this metric family.
466    pub fn help(&self) -> &str {
467        &self.help
468    }
469
470    pub fn set_field_type(&mut self, v: MetricType) {
471        self.field_type = v;
472    }
473
474    pub fn get_field_type(&self) -> MetricType {
475        self.field_type
476    }
477
478    #[deprecated(
479        note = "This method is protobuf specific and will be removed in a future version",
480        since = "0.5.1"
481    )]
482    pub fn clear_metric(&mut self) {
483        self.metric.clear();
484    }
485
486    pub fn set_metric(&mut self, v: Vec<Metric>) {
487        self.metric = v;
488    }
489
490    pub fn mut_metric(&mut self) -> &mut Vec<Metric> {
491        &mut self.metric
492    }
493
494    pub fn take_metric(&mut self) -> Vec<Metric> {
495        ::std::mem::replace(&mut self.metric, Vec::new())
496    }
497
498    pub fn get_metric(&self) -> &[Metric] {
499        &self.metric
500    }
501}