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§
source§impl Prometheus
impl Prometheus
sourcepub fn push_to(url: &str) -> Result<Prometheus>
pub fn push_to(url: &str) -> Result<Prometheus>
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
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§
source§impl Buffered for Prometheus
impl Buffered for Prometheus
source§fn buffered(&self, buffering: Buffering) -> Self
fn buffered(&self, buffering: Buffering) -> Self
Return a clone with the specified buffering set.
source§fn get_buffering(&self) -> Buffering
fn get_buffering(&self) -> Buffering
Return the current buffering strategy.
source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Returns false if the current buffering strategy is
Buffering::Unbuffered
.
Returns true otherwise.source§impl CachedInput for Prometheus
impl CachedInput for Prometheus
source§fn cached(self, max_size: usize) -> InputCache
fn cached(self, max_size: usize) -> InputCache
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.
source§impl Clone for Prometheus
impl Clone for Prometheus
source§fn clone(&self) -> Prometheus
fn clone(&self) -> Prometheus
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Prometheus
impl Debug for Prometheus
source§impl Input for Prometheus
impl Input for Prometheus
source§impl QueuedInput for Prometheus
impl QueuedInput for Prometheus
source§fn queued(self, max_size: usize) -> InputQueue
fn queued(self, max_size: usize) -> InputQueue
Wrap this output with an asynchronous dispatch queue of specified length.
source§impl WithAttributes for Prometheus
impl WithAttributes for Prometheus
source§fn get_attributes(&self) -> &Attributes
fn get_attributes(&self) -> &Attributes
Return attributes of component.
source§fn mut_attributes(&mut self) -> &mut Attributes
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
fn with_attributes<F: Fn(&mut Attributes)>(&self, edit: F) -> Self
Clone the component and mutate its attributes at once.
Auto Trait Implementations§
impl Freeze for Prometheus
impl !RefUnwindSafe for Prometheus
impl Send for Prometheus
impl Sync for Prometheus
impl Unpin for Prometheus
impl !UnwindSafe for Prometheus
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Prefixed for Twhere
T: WithAttributes,
impl<T> Prefixed for Twhere
T: WithAttributes,
source§fn get_prefixes(&self) -> &NameParts
fn get_prefixes(&self) -> &NameParts
Returns namespace of component.
source§fn add_prefix<S>(&self, name: S) -> T
👎Deprecated since 0.7.2: Use named() or add_name()
fn add_prefix<S>(&self, name: S) -> T
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
fn add_name<S>(&self, name: S) -> T
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
fn named<S>(&self, name: S) -> T
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
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
fn prefix_prepend<S: Into<MetricName>>(&self, name: S) -> MetricName
Prepend any name parts to the name’s namespace.