Struct MultiInput

Source
pub struct MultiInput { /* private fields */ }
Expand description

Opens multiple scopes at a time from just as many outputs.

Implementations§

Source§

impl MultiInput

Source

pub fn input() -> Self

👎Deprecated since 0.7.2: Use new()

Create a new multi-input dispatcher.

Source

pub fn new() -> Self

Create a new multi-input dispatcher.

Examples found in repository?
examples/multi_input.rs (line 8)
6fn main() {
7    // will output metrics to graphite and to stdout
8    let different_type_metrics = MultiInput::new()
9        .add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
10        .add_target(Stream::write_to_stdout())
11        .metrics();
12
13    // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
14    let same_type_metrics = MultiInput::new()
15        .add_target(Stream::write_to_stderr().named("yeah"))
16        .add_target(Stream::write_to_stderr().named("ouch"))
17        .named("both")
18        .metrics();
19
20    loop {
21        different_type_metrics.counter("counter_a").count(123);
22        same_type_metrics.timer("timer_a").interval_us(2000000);
23        std::thread::sleep(Duration::from_millis(400));
24    }
25}
More examples
Hide additional examples
examples/proxy_multi.rs (line 24)
20fn main() {
21    // Placeholder to collect output targets
22    // This will prefix all metrics with "my_stats"
23    // before flushing them.
24    let mut targets = MultiInput::new().named("my_stats");
25
26    // Skip the metrics here... we just use this for the output
27    // Follow the same pattern for Statsd, Graphite, etc.
28    let prometheus = Prometheus::push_to("http://localhost:9091/metrics/job/dipstick_example")
29        .expect("Prometheus Socket");
30    targets = targets.add_target(prometheus);
31
32    // Add stdout
33    targets = targets.add_target(Stream::write_to_stdout());
34
35    // Create the stats and drain targets
36    let bucket = AtomicBucket::new();
37    bucket.drain(targets);
38    // Crucial, set the flush interval, otherwise risk hammering targets
39    bucket.flush_every(Duration::from_secs(3));
40
41    // Now wire up the proxy target with the stats and you're all set
42    let proxy = Proxy::default();
43    proxy.target(bucket.clone());
44
45    // Example using the macro! Proxy sugar
46    PROXY.target(bucket.named("global"));
47
48    loop {
49        // Using the default proxy
50        proxy.counter("beans").count(100);
51        proxy.timer("braincells").interval_us(420);
52        // global example
53        PROXY.counter("my_proxy_counter").count(123);
54        PROXY.timer("my_proxy_timer").interval_us(2000000);
55        std::thread::sleep(Duration::from_millis(100));
56    }
57}
Source

pub fn add_target<OUT: Input + Send + Sync + 'static>(&self, out: OUT) -> Self

Returns a clone of the dispatch with the new target added to the list.

Examples found in repository?
examples/multi_input.rs (line 9)
6fn main() {
7    // will output metrics to graphite and to stdout
8    let different_type_metrics = MultiInput::new()
9        .add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
10        .add_target(Stream::write_to_stdout())
11        .metrics();
12
13    // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
14    let same_type_metrics = MultiInput::new()
15        .add_target(Stream::write_to_stderr().named("yeah"))
16        .add_target(Stream::write_to_stderr().named("ouch"))
17        .named("both")
18        .metrics();
19
20    loop {
21        different_type_metrics.counter("counter_a").count(123);
22        same_type_metrics.timer("timer_a").interval_us(2000000);
23        std::thread::sleep(Duration::from_millis(400));
24    }
25}
More examples
Hide additional examples
examples/proxy_multi.rs (line 30)
20fn main() {
21    // Placeholder to collect output targets
22    // This will prefix all metrics with "my_stats"
23    // before flushing them.
24    let mut targets = MultiInput::new().named("my_stats");
25
26    // Skip the metrics here... we just use this for the output
27    // Follow the same pattern for Statsd, Graphite, etc.
28    let prometheus = Prometheus::push_to("http://localhost:9091/metrics/job/dipstick_example")
29        .expect("Prometheus Socket");
30    targets = targets.add_target(prometheus);
31
32    // Add stdout
33    targets = targets.add_target(Stream::write_to_stdout());
34
35    // Create the stats and drain targets
36    let bucket = AtomicBucket::new();
37    bucket.drain(targets);
38    // Crucial, set the flush interval, otherwise risk hammering targets
39    bucket.flush_every(Duration::from_secs(3));
40
41    // Now wire up the proxy target with the stats and you're all set
42    let proxy = Proxy::default();
43    proxy.target(bucket.clone());
44
45    // Example using the macro! Proxy sugar
46    PROXY.target(bucket.named("global"));
47
48    loop {
49        // Using the default proxy
50        proxy.counter("beans").count(100);
51        proxy.timer("braincells").interval_us(420);
52        // global example
53        PROXY.counter("my_proxy_counter").count(123);
54        PROXY.timer("my_proxy_timer").interval_us(2000000);
55        std::thread::sleep(Duration::from_millis(100));
56    }
57}

Trait Implementations§

Source§

impl Clone for MultiInput

Source§

fn clone(&self) -> MultiInput

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for MultiInput

Source§

fn default() -> MultiInput

Returns the “default value” for a type. Read more
Source§

impl Input for MultiInput

Source§

type SCOPE = MultiInputScope

The type of Scope returned byt this input.
Source§

fn metrics(&self) -> Self::SCOPE

Open a new scope from this input.
Source§

fn input(&self) -> Self::SCOPE

👎Deprecated since 0.7.2: Use metrics()
Open a new scope from this input.
Source§

fn new_scope(&self) -> Self::SCOPE

👎Deprecated since 0.8.0: Use metrics()
Open a new scope from this input.
Source§

impl WithAttributes for MultiInput

Source§

fn get_attributes(&self) -> &Attributes

Return attributes of component.
Source§

fn mut_attributes(&mut self) -> &mut Attributes

Return attributes of component for mutation.
Source§

fn with_attributes<F: Fn(&mut Attributes)>(&self, edit: F) -> Self

Clone the component and mutate its attributes at once.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InputDyn for T
where T: Input + Send + Sync + 'static,

Source§

fn input_dyn(&self) -> Arc<dyn InputScope + Send + Sync>

Open a new scope from this output.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Prefixed for T
where T: WithAttributes,

Source§

fn get_prefixes(&self) -> &NameParts

Returns namespace of component.

Source§

fn add_prefix<S>(&self, name: S) -> T
where S: Into<String>,

👎Deprecated since 0.7.2: Use named() or add_name()

Append a name to the existing names. Return a clone of the component with the updated names.

Source§

fn add_name<S>(&self, name: S) -> T
where S: Into<String>,

Append a name to the existing names. Return a clone of the component with the updated names.

Source§

fn named<S>(&self, name: S) -> T
where S: Into<String>,

Replace any existing names with a single name. Return a clone of the component with the new name. If multiple names are required, add_name may also be used.

Source§

fn prefix_append<S: Into<MetricName>>(&self, name: S) -> MetricName

Append any name parts to the name’s namespace.
Source§

fn prefix_prepend<S: Into<MetricName>>(&self, name: S) -> MetricName

Prepend any name parts to the name’s namespace.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.