mirror of https://github.com/fralalonde/dipstick
Final method rename PR changes - named() / add_name()
This commit is contained in:
parent
bae0fa6b5a
commit
9eb41aebeb
|
@ -7,11 +7,13 @@ use std::time::Duration;
|
|||
use dipstick::*;
|
||||
|
||||
fn main() {
|
||||
// adding a name to the bucket
|
||||
let bucket = AtomicBucket::new().named("test");
|
||||
|
||||
// Bucket::set_default_output(to_stdout());
|
||||
// adding two names to Graphite output
|
||||
// metrics will be prefixed with "machine1.application.test"
|
||||
bucket.drain(Graphite::send_to("localhost:2003").expect("Socket")
|
||||
.named("machine1").named("application"));
|
||||
.named("machine1").add_name("application"));
|
||||
|
||||
bucket.flush_every(Duration::from_secs(3));
|
||||
|
||||
|
|
|
@ -4,14 +4,12 @@
|
|||
extern crate dipstick;
|
||||
|
||||
use std::time::Duration;
|
||||
use std::io;
|
||||
use dipstick::*;
|
||||
|
||||
fn main() {
|
||||
let metrics = AtomicBucket::new().named("test");
|
||||
|
||||
// Bucket::set_default_output(to_stdout());
|
||||
metrics.drain(Stream::write_to(io::stdout()));
|
||||
metrics.drain(Stream::to_stdout());
|
||||
|
||||
metrics.flush_every(Duration::from_secs(3));
|
||||
|
||||
|
|
|
@ -4,14 +4,13 @@ extern crate dipstick;
|
|||
|
||||
use dipstick::*;
|
||||
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
use std::thread::sleep;
|
||||
|
||||
|
||||
fn main() {
|
||||
let bucket = AtomicBucket::new();
|
||||
AtomicBucket::default_drain(Stream::write_to(io::stdout()));
|
||||
AtomicBucket::default_drain(Stream::to_stdout());
|
||||
|
||||
let persistent_marker = bucket.marker("persistent");
|
||||
|
||||
|
|
|
@ -5,12 +5,11 @@ extern crate dipstick;
|
|||
|
||||
use std::time::Duration;
|
||||
use dipstick::*;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
|
||||
let app_metrics = AtomicBucket::new();
|
||||
app_metrics.drain(Stream::write_to(io::stdout()));
|
||||
app_metrics.drain(Stream::to_stdout());
|
||||
|
||||
app_metrics.flush_every(Duration::from_secs(3));
|
||||
|
||||
|
|
|
@ -26,9 +26,9 @@ fn main() {
|
|||
fifteen_minutes.flush_every(Duration::from_secs(900));
|
||||
|
||||
let all_buckets = MultiInputScope::new()
|
||||
.target(one_minute)
|
||||
.target(five_minutes)
|
||||
.target(fifteen_minutes)
|
||||
.add_target(one_minute)
|
||||
.add_target(five_minutes)
|
||||
.add_target(fifteen_minutes)
|
||||
.named("machine_name");
|
||||
|
||||
// send application metrics to aggregator
|
||||
|
|
|
@ -8,14 +8,14 @@ use std::time::Duration;
|
|||
fn main() {
|
||||
// will output metrics to graphite and to stdout
|
||||
let different_type_metrics = MultiInput::new()
|
||||
.target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.target(Stream::to_stdout())
|
||||
.add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.add_target(Stream::to_stdout())
|
||||
.metrics();
|
||||
|
||||
// will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
|
||||
let same_type_metrics = MultiInput::new()
|
||||
.target(Stream::to_stderr().named("yeah"))
|
||||
.target(Stream::to_stderr().named("ouch"))
|
||||
.add_target(Stream::to_stderr().named("yeah"))
|
||||
.add_target(Stream::to_stderr().named("ouch"))
|
||||
.named("both")
|
||||
.metrics();
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ use std::time::Duration;
|
|||
fn main() {
|
||||
// will output metrics to graphite and to stdout
|
||||
let different_type_metrics = MultiOutput::new()
|
||||
.target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.target(Stream::to_stdout())
|
||||
.add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
||||
.add_target(Stream::to_stdout())
|
||||
.metrics();
|
||||
|
||||
// will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
|
||||
let same_type_metrics = MultiOutput::new()
|
||||
.target(Stream::to_stderr().named("yeah"))
|
||||
.target(Stream::to_stderr().named("ouch"))
|
||||
.add_target(Stream::to_stderr().named("yeah"))
|
||||
.add_target(Stream::to_stderr().named("ouch"))
|
||||
.named("both").metrics();
|
||||
|
||||
loop {
|
||||
|
|
|
@ -56,11 +56,18 @@ pub trait Prefixed {
|
|||
/// Returns namespace of component.
|
||||
fn get_prefixes(&self) -> &NameParts;
|
||||
|
||||
/// Extend the namespace new metrics will be defined in.
|
||||
#[deprecated(since="0.7.2", note="Use named()")]
|
||||
/// Append a name to the existing names.
|
||||
/// Return a clone of the component with the updated names.
|
||||
#[deprecated(since="0.7.2", note="Use add_name()")]
|
||||
fn add_prefix<S: Into<String>>(&self, name: S) -> Self;
|
||||
|
||||
/// Extend the namespace new metrics will be defined in.
|
||||
/// Append a name to the existing names.
|
||||
/// Return a clone of the component with the updated names.
|
||||
fn add_name<S: Into<String>>(&self, name: S) -> Self;
|
||||
|
||||
/// 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.
|
||||
fn named<S: Into<String>>(&self, name: S) -> Self;
|
||||
|
||||
/// Append any name parts to the name's namespace.
|
||||
|
@ -91,17 +98,25 @@ impl<T: WithAttributes> Prefixed for T {
|
|||
&self.get_attributes().naming
|
||||
}
|
||||
|
||||
/// Adds a name part to any existing naming.
|
||||
/// Return a clone of the component with the updated naming.
|
||||
/// 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.
|
||||
fn named<S: Into<String>>(&self, name: S) -> Self {
|
||||
let parts = NameParts::from(name);
|
||||
self.with_attributes(|new_attr| new_attr.naming = parts.clone())
|
||||
}
|
||||
|
||||
/// Append a name to the existing names.
|
||||
/// Return a clone of the component with the updated names.
|
||||
fn add_name<S: Into<String>>(&self, name: S) -> Self {
|
||||
let name = name.into();
|
||||
self.with_attributes(|new_attr| new_attr.naming.push_back(name.clone()))
|
||||
}
|
||||
|
||||
/// Adds a name part to any existing naming.
|
||||
/// Return a clone of the component with the updated naming.
|
||||
/// Append a name to the existing names.
|
||||
/// Return a clone of the component with the updated names.
|
||||
fn add_prefix<S: Into<String>>(&self, name: S) -> Self {
|
||||
self.named(name)
|
||||
self.add_name(name)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,13 +43,7 @@ impl MultiInput {
|
|||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new target added to the list.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<OUT: Input + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
self.target(out)
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new target added to the list.
|
||||
pub fn target<OUT: Input + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.outputs.push(Arc::new(out));
|
||||
cloned
|
||||
|
@ -79,18 +73,12 @@ impl MultiInputScope {
|
|||
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<IN: InputScope + Send + Sync + 'static>(&self, scope: IN) -> Self {
|
||||
self.target(scope)
|
||||
}
|
||||
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
pub fn target<IN: InputScope + Send + Sync + 'static>(&self, scope: IN) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.scopes.push(Arc::new(scope));
|
||||
cloned
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl InputScope for MultiInputScope {
|
||||
|
|
|
@ -46,18 +46,12 @@ impl MultiOutput {
|
|||
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<OUT: Output + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
self.target(out)
|
||||
}
|
||||
|
||||
/// Add a target to the dispatch list.
|
||||
/// Returns a clone of the original object.
|
||||
pub fn target<OUT: Output + Send + Sync + 'static>(&self, out: OUT) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.outputs.push(Arc::new(out));
|
||||
cloned
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl WithAttributes for MultiOutput {
|
||||
|
@ -82,17 +76,12 @@ impl MultiOutputScope {
|
|||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
#[deprecated(since="0.7.2", note="Use target()")]
|
||||
pub fn add_target<IN: OutputScope + 'static>(&self, scope: IN) -> Self {
|
||||
self.target(scope)
|
||||
}
|
||||
|
||||
/// Returns a clone of the dispatch with the new output added to the list.
|
||||
pub fn target<IN: OutputScope + 'static>(&self, scope: IN) -> Self {
|
||||
let mut cloned = self.clone();
|
||||
cloned.scopes.push(Rc::new(scope));
|
||||
cloned
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl OutputScope for MultiOutputScope {
|
||||
|
|
Loading…
Reference in New Issue