Struct dipstick::Prometheus

source ·
pub struct Prometheus { /* private fields */ }
Expand description

Prometheus Input holds a socket to a Prometheus server. The socket is shared between scopes opened from the Input.

Implementations§

Send metrics to a Prometheus “push gateway” at the URL provided. URL path must include group identifier labels job as shown in https://github.com/prometheus/pushgateway#command-line For example http://pushgateway.example.org:9091/metrics/job/some_job

Examples found in repository?
examples/prometheus_labels.rs (line 7)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let metrics = Prometheus::push_to("http://localhost:9091/metrics/job/prometheus_example")
        .expect("Prometheus Socket")
        .named("my_app")
        .metrics();

    AppLabel::set("abc", "456");
    ThreadLabel::set("xyz", "123");

    loop {
        metrics.counter("counter_a").count(123);
        metrics.timer("timer_a").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(40));
    }
}
More examples
Hide additional examples
examples/proxy_multi.rs (line 28)
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§

Return a clone with the specified buffering set.
Return the current buffering strategy.
Returns false if the current buffering strategy is Buffering::Unbuffered. Returns true otherwise.
Wrap an input with a metric definition cache. This can provide performance benefits for metrics that are dynamically defined at runtime on each access. Caching is useless if all metrics are statically declared or instantiated programmatically in advance and referenced by a long living variable.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The type of Scope returned byt this input.
Open a new scope from this input.
👎Deprecated since 0.7.2: Use metrics()
Open a new scope from this input.
👎Deprecated since 0.8.0: Use metrics()
Open a new scope from this input.
Wrap this output with an asynchronous dispatch queue of specified length.
Return attributes of component.
Return attributes of component for mutation.
Clone the component and mutate its attributes at once.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.