pub trait TransmitsTelemetryData<L> {
Show 15 methods
// Required methods
fn transmit(&self, observation: Observation<L>) -> &Self;
fn add_handler<H: HandlesObservations<Label = L>>(
&self,
handler: H,
) -> &Self
where L: Send + 'static;
fn add_cockpit(&self, cockpit: Cockpit<L>) -> &Self;
fn remove_cockpit<T: Into<String>>(&self, name: T) -> &Self;
fn add_panel_to_cockpit<T: Into<String>>(
&self,
cockpit_name: T,
panel: Panel<L>,
) -> &Self;
fn remove_panel_from_cockpit<U: Into<String>, V: Into<String>>(
&self,
cockpit_name: U,
panel_name: V,
) -> &Self;
// Provided methods
fn observed(&self, label: L, count: u64, timestamp: Instant) -> &Self { ... }
fn observed_one(&self, label: L, timestamp: Instant) -> &Self { ... }
fn observed_one_value<V: Into<ObservedValue>>(
&self,
label: L,
value: V,
timestamp: Instant,
) -> &Self { ... }
fn observed_duration(
&self,
label: L,
duration: Duration,
timestamp: Instant,
) -> &Self { ... }
fn observed_now(&self, label: L, count: u64) -> &Self { ... }
fn observed_one_now(&self, label: L) -> &Self { ... }
fn observed_one_value_now<V: Into<ObservedValue>>(
&self,
label: L,
value: V,
) -> &Self { ... }
fn observed_one_duration_now(&self, label: L, duration: Duration) -> &Self { ... }
fn measure_time(&self, label: L, from: Instant) -> &Self { ... }
}
Expand description
Transmits telemetry data to the backend.
Implementors should transfer Observations
to
a backend and manipulate the instruments there to not
to interfere to much with the actual task being measured/observed
Required Methods§
Sourcefn transmit(&self, observation: Observation<L>) -> &Self
fn transmit(&self, observation: Observation<L>) -> &Self
Transit an observation to the backend.
Sourcefn add_handler<H: HandlesObservations<Label = L>>(&self, handler: H) -> &Selfwhere
L: Send + 'static,
fn add_handler<H: HandlesObservations<Label = L>>(&self, handler: H) -> &Selfwhere
L: Send + 'static,
Add a handler.
Sourcefn add_cockpit(&self, cockpit: Cockpit<L>) -> &Self
fn add_cockpit(&self, cockpit: Cockpit<L>) -> &Self
Add a Copckpit
If the cockpit has a name and another cockpit with the same name is already present the cockpit will not be added.
fn remove_cockpit<T: Into<String>>(&self, name: T) -> &Self
Sourcefn add_panel_to_cockpit<T: Into<String>>(
&self,
cockpit_name: T,
panel: Panel<L>,
) -> &Self
fn add_panel_to_cockpit<T: Into<String>>( &self, cockpit_name: T, panel: Panel<L>, ) -> &Self
Add a Panel
to a Cockpit
if that Cockpit
has the
given name.
Provided Methods§
Sourcefn observed(&self, label: L, count: u64, timestamp: Instant) -> &Self
fn observed(&self, label: L, count: u64, timestamp: Instant) -> &Self
Observed count
occurrences at time timestamp
Convenience method. Simply calls transmit
Sourcefn observed_one(&self, label: L, timestamp: Instant) -> &Self
fn observed_one(&self, label: L, timestamp: Instant) -> &Self
Observed one occurrence at time timestamp
Convenience method. Simply calls transmit
Sourcefn observed_one_value<V: Into<ObservedValue>>(
&self,
label: L,
value: V,
timestamp: Instant,
) -> &Self
fn observed_one_value<V: Into<ObservedValue>>( &self, label: L, value: V, timestamp: Instant, ) -> &Self
Observed one occurrence with value value
at time timestamp
Convenience method. Simply calls transmit
Examples found in repository?
149fn main() {
150 let builder = DriverBuilder::new("demo");
151 let mut driver = builder.build();
152 //driver.change_processing_stragtegy(ProcessingStrategy::DropAll);
153 //driver.pause();
154
155 let (foo_transmitter, foo_processor) = create_foo_metrics();
156 let (bar_transmitter, bar_processor) = create_bar_metrics();
157
158 driver.add_processor(foo_processor);
159 driver.add_processor(bar_processor);
160
161 let polled_counter = PolledCounter::new();
162 let mut polled_instrument =
163 PollingInstrument::new_with_defaults("polled_instrument_3", polled_counter);
164 polled_instrument.set_title("The polled counter 3");
165 polled_instrument.set_description("A counter that is increased when a snapshot is polled");
166
167 driver.add_snapshooter(polled_instrument);
168
169 let start = Instant::now();
170
171 let handle1 = {
172 let foo_transmitter = foo_transmitter.clone();
173 let bar_transmitter = bar_transmitter.clone();
174
175 thread::spawn(move || {
176 for n in 0..5_000_000 {
177 foo_transmitter.observed_one_value(FooLabel::A, n, Instant::now());
178 bar_transmitter.measure_time(BarLabel::C, start);
179 }
180 })
181 };
182
183 // Poll a snapshot for the counter
184 let _ = driver.snapshot(true).unwrap();
185
186 let handle2 = {
187 let foo_transmitter = foo_transmitter;
188 let bar_transmitter = bar_transmitter.clone();
189
190 thread::spawn(move || {
191 for n in 0..5_000_000u64 {
192 foo_transmitter.observed_one_value(FooLabel::B, n, Instant::now());
193 bar_transmitter.observed_one_value(BarLabel::B, n * n, Instant::now());
194 }
195 })
196 };
197
198 // Poll a snapshot for the counter
199 let _ = driver.snapshot(true).unwrap();
200
201 let handle3 = {
202 let bar_transmitter = bar_transmitter;
203
204 thread::spawn(move || {
205 for i in 0..5_000_000 {
206 bar_transmitter.observed_one_value(BarLabel::A, i, Instant::now());
207 }
208 })
209 };
210
211 handle1.join().unwrap();
212 handle2.join().unwrap();
213 handle3.join().unwrap();
214
215 //driver.resume();
216
217 println!(
218 "Sending observations took {:?}. Sleeping 1 secs to collect remaining data. \
219 Depending on your machine you might see that not all metrics have a count \
220 of 5 million observations.",
221 start.elapsed()
222 );
223
224 thread::sleep(Duration::from_secs(1));
225
226 println!("\n\n\n=======================\n\n");
227
228 println!(
229 "Get snapshot. If it still blocks here there are still many messages to be processed..."
230 );
231
232 println!("\n\n\n=======================\n\n");
233
234 let snapshot = driver.snapshot(true).unwrap();
235
236 let mut config = JsonConfig::default();
237 config.pretty = Some(4);
238
239 println!("{:?}", snapshot);
240 println!("\n\n\n=======================\n\n");
241 println!("{}", snapshot.to_json(&config));
242}
Sourcefn observed_duration(
&self,
label: L,
duration: Duration,
timestamp: Instant,
) -> &Self
fn observed_duration( &self, label: L, duration: Duration, timestamp: Instant, ) -> &Self
Sends a Duration
as an observed value observed at timestamp
.
The Duration
is converted to nanoseconds.
Sourcefn observed_now(&self, label: L, count: u64) -> &Self
fn observed_now(&self, label: L, count: u64) -> &Self
Observed count
occurrences at now.
Convenience method. Simply calls observed
with
the current timestamp.
Sourcefn observed_one_now(&self, label: L) -> &Self
fn observed_one_now(&self, label: L) -> &Self
Observed one occurrence now
Convenience method. Simply calls observed_one
with
the current timestamp.
Sourcefn observed_one_value_now<V: Into<ObservedValue>>(
&self,
label: L,
value: V,
) -> &Self
fn observed_one_value_now<V: Into<ObservedValue>>( &self, label: L, value: V, ) -> &Self
Observed one occurrence with value value
now
Convenience method. Simply calls observed_one_value
with
the current timestamp.
Sourcefn observed_one_duration_now(&self, label: L, duration: Duration) -> &Self
fn observed_one_duration_now(&self, label: L, duration: Duration) -> &Self
Sends a Duration
as an observed value observed with the current
timestamp.
The Duration
is converted to nanoseconds internally.
Sourcefn measure_time(&self, label: L, from: Instant) -> &Self
fn measure_time(&self, label: L, from: Instant) -> &Self
Measures the time from from
until now.
The resulting duration is an observed value with the measured duration in nanoseconds.
Examples found in repository?
149fn main() {
150 let builder = DriverBuilder::new("demo");
151 let mut driver = builder.build();
152 //driver.change_processing_stragtegy(ProcessingStrategy::DropAll);
153 //driver.pause();
154
155 let (foo_transmitter, foo_processor) = create_foo_metrics();
156 let (bar_transmitter, bar_processor) = create_bar_metrics();
157
158 driver.add_processor(foo_processor);
159 driver.add_processor(bar_processor);
160
161 let polled_counter = PolledCounter::new();
162 let mut polled_instrument =
163 PollingInstrument::new_with_defaults("polled_instrument_3", polled_counter);
164 polled_instrument.set_title("The polled counter 3");
165 polled_instrument.set_description("A counter that is increased when a snapshot is polled");
166
167 driver.add_snapshooter(polled_instrument);
168
169 let start = Instant::now();
170
171 let handle1 = {
172 let foo_transmitter = foo_transmitter.clone();
173 let bar_transmitter = bar_transmitter.clone();
174
175 thread::spawn(move || {
176 for n in 0..5_000_000 {
177 foo_transmitter.observed_one_value(FooLabel::A, n, Instant::now());
178 bar_transmitter.measure_time(BarLabel::C, start);
179 }
180 })
181 };
182
183 // Poll a snapshot for the counter
184 let _ = driver.snapshot(true).unwrap();
185
186 let handle2 = {
187 let foo_transmitter = foo_transmitter;
188 let bar_transmitter = bar_transmitter.clone();
189
190 thread::spawn(move || {
191 for n in 0..5_000_000u64 {
192 foo_transmitter.observed_one_value(FooLabel::B, n, Instant::now());
193 bar_transmitter.observed_one_value(BarLabel::B, n * n, Instant::now());
194 }
195 })
196 };
197
198 // Poll a snapshot for the counter
199 let _ = driver.snapshot(true).unwrap();
200
201 let handle3 = {
202 let bar_transmitter = bar_transmitter;
203
204 thread::spawn(move || {
205 for i in 0..5_000_000 {
206 bar_transmitter.observed_one_value(BarLabel::A, i, Instant::now());
207 }
208 })
209 };
210
211 handle1.join().unwrap();
212 handle2.join().unwrap();
213 handle3.join().unwrap();
214
215 //driver.resume();
216
217 println!(
218 "Sending observations took {:?}. Sleeping 1 secs to collect remaining data. \
219 Depending on your machine you might see that not all metrics have a count \
220 of 5 million observations.",
221 start.elapsed()
222 );
223
224 thread::sleep(Duration::from_secs(1));
225
226 println!("\n\n\n=======================\n\n");
227
228 println!(
229 "Get snapshot. If it still blocks here there are still many messages to be processed..."
230 );
231
232 println!("\n\n\n=======================\n\n");
233
234 let snapshot = driver.snapshot(true).unwrap();
235
236 let mut config = JsonConfig::default();
237 config.pretty = Some(4);
238
239 println!("{:?}", snapshot);
240 println!("\n\n\n=======================\n\n");
241 println!("{}", snapshot.to_json(&config));
242}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.