Struct dipstick::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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    // will output metrics to graphite and to stdout
    let different_type_metrics = MultiInput::new()
        .add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
        .add_target(Stream::write_to_stdout())
        .metrics();

    // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
    let same_type_metrics = MultiInput::new()
        .add_target(Stream::write_to_stderr().named("yeah"))
        .add_target(Stream::write_to_stderr().named("ouch"))
        .named("both")
        .metrics();

    loop {
        different_type_metrics.counter("counter_a").count(123);
        same_type_metrics.timer("timer_a").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(400));
    }
}
More examples
Hide additional examples
examples/proxy_multi.rs (line 24)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() {
    // Placeholder to collect output targets
    // This will prefix all metrics with "my_stats"
    // before flushing them.
    let mut targets = MultiInput::new().named("my_stats");

    // Skip the metrics here... we just use this for the output
    // Follow the same pattern for Statsd, Graphite, etc.
    let prometheus = Prometheus::push_to("http://localhost:9091/metrics/job/dipstick_example")
        .expect("Prometheus Socket");
    targets = targets.add_target(prometheus);

    // Add stdout
    targets = targets.add_target(Stream::write_to_stdout());

    // Create the stats and drain targets
    let bucket = AtomicBucket::new();
    bucket.drain(targets);
    // Crucial, set the flush interval, otherwise risk hammering targets
    bucket.flush_every(Duration::from_secs(3));

    // Now wire up the proxy target with the stats and you're all set
    let proxy = Proxy::default();
    proxy.target(bucket.clone());

    // Example using the macro! Proxy sugar
    PROXY.target(bucket.named("global"));

    loop {
        // Using the default proxy
        proxy.counter("beans").count(100);
        proxy.timer("braincells").interval_us(420);
        // global example
        PROXY.counter("my_proxy_counter").count(123);
        PROXY.timer("my_proxy_timer").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(100));
    }
}
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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    // will output metrics to graphite and to stdout
    let different_type_metrics = MultiInput::new()
        .add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
        .add_target(Stream::write_to_stdout())
        .metrics();

    // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
    let same_type_metrics = MultiInput::new()
        .add_target(Stream::write_to_stderr().named("yeah"))
        .add_target(Stream::write_to_stderr().named("ouch"))
        .named("both")
        .metrics();

    loop {
        different_type_metrics.counter("counter_a").count(123);
        same_type_metrics.timer("timer_a").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(400));
    }
}
More examples
Hide additional examples
examples/proxy_multi.rs (line 30)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() {
    // Placeholder to collect output targets
    // This will prefix all metrics with "my_stats"
    // before flushing them.
    let mut targets = MultiInput::new().named("my_stats");

    // Skip the metrics here... we just use this for the output
    // Follow the same pattern for Statsd, Graphite, etc.
    let prometheus = Prometheus::push_to("http://localhost:9091/metrics/job/dipstick_example")
        .expect("Prometheus Socket");
    targets = targets.add_target(prometheus);

    // Add stdout
    targets = targets.add_target(Stream::write_to_stdout());

    // Create the stats and drain targets
    let bucket = AtomicBucket::new();
    bucket.drain(targets);
    // Crucial, set the flush interval, otherwise risk hammering targets
    bucket.flush_every(Duration::from_secs(3));

    // Now wire up the proxy target with the stats and you're all set
    let proxy = Proxy::default();
    proxy.target(bucket.clone());

    // Example using the macro! Proxy sugar
    PROXY.target(bucket.named("global"));

    loop {
        // Using the default proxy
        proxy.counter("beans").count(100);
        proxy.timer("braincells").interval_us(420);
        // global example
        PROXY.counter("my_proxy_counter").count(123);
        PROXY.timer("my_proxy_timer").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(100));
    }
}

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

§

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> 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,

§

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>,

§

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>,

§

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.