1 + | /*
|
2 + | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 + | * SPDX-License-Identifier: Apache-2.0
|
4 + | */
|
5 + |
|
6 + | //! Metrics are used to gain insight into the operational performance and health of a system in
|
7 + | //! real time.
|
8 + |
|
9 + | use crate::attributes::{Attributes, Context};
|
10 + |
|
11 + | /// Provides named instances of [Meter].
|
12 + | pub trait MeterProvider {
|
13 + | /// Get or create a named [Meter].
|
14 + | fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Box<dyn Meter>;
|
15 + |
|
16 + | /// Foo
|
17 + | fn as_any(&self) -> &dyn std::any::Any;
|
18 + | }
|
19 + |
|
20 + | /// The entry point to creating instruments. A grouping of related metrics.
|
21 + | pub trait Meter {
|
22 + | /// Create a new Gauge.
|
23 + | #[allow(clippy::type_complexity)]
|
24 + | fn create_gauge(
|
25 + | &self,
|
26 + | name: String,
|
27 + | callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
|
28 + | units: Option<String>,
|
29 + | description: Option<String>,
|
30 + | ) -> Box<dyn AsyncMeasurement<Value = f64>>;
|
31 + |
|
32 + | /// Create a new [UpDownCounter].
|
33 + | fn create_up_down_counter(
|
34 + | &self,
|
35 + | name: String,
|
36 + | units: Option<String>,
|
37 + | description: Option<String>,
|
38 + | ) -> Box<dyn UpDownCounter>;
|
39 + |
|
40 + | /// Create a new AsyncUpDownCounter.
|
41 + | #[allow(clippy::type_complexity)]
|
42 + | fn create_async_up_down_counter(
|
43 + | &self,
|
44 + | name: String,
|
45 + | callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
|
46 + | units: Option<String>,
|
47 + | description: Option<String>,
|
48 + | ) -> Box<dyn AsyncMeasurement<Value = i64>>;
|
49 + |
|
50 + | /// Create a new [MonotonicCounter].
|
51 + | fn create_monotonic_counter(
|
52 + | &self,
|
53 + | name: String,
|
54 + | units: Option<String>,
|
55 + | description: Option<String>,
|
56 + | ) -> Box<dyn MonotonicCounter>;
|
57 + |
|
58 + | /// Create a new AsyncMonotonicCounter.
|
59 + | #[allow(clippy::type_complexity)]
|
60 + | fn create_async_monotonic_counter(
|
61 + | &self,
|
62 + | name: String,
|
63 + | callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
|
64 + | units: Option<String>,
|
65 + | description: Option<String>,
|
66 + | ) -> Box<dyn AsyncMeasurement<Value = u64>>;
|
67 + |
|
68 + | /// Create a new [Histogram].
|
69 + | fn create_histogram(
|
70 + | &self,
|
71 + | name: String,
|
72 + | units: Option<String>,
|
73 + | description: Option<String>,
|
74 + | ) -> Box<dyn Histogram>;
|
75 + | }
|
76 + |
|
77 + | /// Collects a set of events with an event count and sum for all events.
|
78 + | pub trait Histogram {
|
79 + | /// Record a value.
|
80 + | fn record(&self, value: f64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
|
81 + | }
|
82 + |
|
83 + | /// A counter that monotonically increases.
|
84 + | pub trait MonotonicCounter {
|
85 + | /// Increment a counter by a fixed amount.
|
86 + | fn add(&self, value: u64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
|
87 + | }
|
88 + |
|
89 + | /// A counter that can increase or decrease.
|
90 + | pub trait UpDownCounter {
|
91 + | /// Increment or decrement a counter by a fixed amount.
|
92 + | fn add(&self, value: i64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
|
93 + | }
|
94 + |
|
95 + | /// A measurement that can be taken asynchronously.
|
96 + | pub trait AsyncMeasurement {
|
97 + | /// The type recorded by the measurement.
|
98 + | type Value;
|
99 + |
|
100 + | /// Record a value
|
101 + | fn record(
|
102 + | &self,
|
103 + | value: Self::Value,
|
104 + | attributes: Option<&Attributes>,
|
105 + | context: Option<&dyn Context>,
|
106 + | );
|
107 + |
|
108 + | /// Stop recording , unregister callback.
|
109 + | fn stop(&self);
|
110 + | }
|