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