Skip to content

Commit

Permalink
Merge pull request #4 from minato128/f/pull-from-origin
Browse files Browse the repository at this point in the history
Pull from upstream/origin 0.14.1
  • Loading branch information
minato128 authored Apr 3, 2021
2 parents 1385eb1 + 3c2e96b commit e4bf2b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "datadog-statsd"
version = "0.1.0"
version = "0.1.1"
description = "A dogstatsd client for rust."
homepage = "https://github.com/minato128/rust-dogstatsd"
repository = "https://github.com/minato128/rust-dogstatsd"
documentation = "https://docs.rs/datadog-statsd/"
readme = "README.md"
license = "MIT"
authors = ["Mark Story <[email protected]>"]
Expand All @@ -12,7 +14,7 @@ include = [
"README.md",
"LICENSE.txt",
]
keywords = [ "datadog", "dogstatsd" ]
keywords = [ "datadog", "dogstatsd", "statsd" ]

[dependencies]
rand = "^0.3"
26 changes: 13 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl error::Error for StatsdError {}
/// ```ignore
/// use datadog_statsd::client::Client;
///
/// let client = Client::new("127.0.0.1:8125", "myapp");
/// let client = Client::new("127.0.0.1:8125", "myapp", tags);
/// client.incr("some.metric.completed");
/// ```
pub struct Client {
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Client {
///
/// ```ignore
/// # Increment a given metric by 1.
/// client.incr("metric.completed");
/// client.incr("metric.completed", tags);
/// ```
///
/// This modifies a counter with an effective sampling
Expand All @@ -106,7 +106,7 @@ impl Client {
///
/// ```ignore
/// # Decrement a given metric by 1
/// client.decr("metric.completed");
/// client.decr("metric.completed", tags);
/// ```
///
/// This modifies a counter with an effective sampling
Expand All @@ -122,7 +122,7 @@ impl Client {
///
/// ```ignore
/// // Increment by 12
/// client.count("metric.completed", 12.0);
/// client.count("metric.completed", 12.0, tags);
/// ```
pub fn count(&self, metric: &str, value: f64, tags: &Option<Vec<&str>>) {
let data = self.prepare_with_tags(format!("{}:{}|c", metric, value), tags);
Expand All @@ -137,21 +137,21 @@ impl Client {
///
/// ```ignore
/// // Increment by 4 50% of the time.
/// client.sampled_count("metric.completed", 4, 0.5);
/// client.sampled_count("metric.completed", 4, 0.5, tags);
/// ```
pub fn sampled_count(&self, metric: &str, value: f64, rate: f64, tags: &Option<Vec<&str>>) {
if rand::random::<f64>() < rate {
if rand::random::<f64>() >= rate {
return;
}
let data = self.prepare_with_tags(format!("{}:{}|c", metric, value), tags);
let data = self.prepare_with_tags(format!("{}:{}|c|@{}", metric, value, rate), tags);
self.send(data);
}

/// Set a gauge value.
///
/// ```ignore
/// // set a gauge to 9001
/// client.gauge("power_level.observed", 9001.0);
/// client.gauge("power_level.observed", 9001.0, tags);
/// ```
pub fn gauge(&self, metric: &str, value: f64, tags: &Option<Vec<&str>>) {
let data = self.prepare_with_tags(format!("{}:{}|g", metric, value), tags);
Expand All @@ -164,7 +164,7 @@ impl Client {
///
/// ```ignore
/// // pass a duration value
/// client.timer("response.duration", 10.123);
/// client.timer("response.duration", 10.123, tags);
/// ```
pub fn timer(&self, metric: &str, value: f64, tags: &Option<Vec<&str>>) {
let data = self.prepare_with_tags(format!("{}:{}|ms", metric, value), tags);
Expand All @@ -178,7 +178,7 @@ impl Client {
///
/// ```ignore
/// // pass a duration value
/// client.time("response.duration", || {
/// client.time("response.duration", tags, || {
/// // Your code here.
/// });
/// ```
Expand Down Expand Up @@ -247,7 +247,7 @@ impl Client {
///
/// ```ignore
/// // pass response size value
/// client.histogram("response.size", 128.0);
/// client.histogram("response.size", 128.0, tags);
/// ```
pub fn histogram(&self, metric: &str, value: f64, tags: &Option<Vec<&str>>) {
let data = self.prepare_with_tags(format!("{}:{}|h", metric, value), tags);
Expand Down Expand Up @@ -402,10 +402,10 @@ impl Pipeline {
/// pipe.sampled_count("metric.completed", 4.0, 0.5);
/// ```
pub fn sampled_count(&mut self, metric: &str, value: f64, rate: f64) {
if rand::random::<f64>() < rate {
if rand::random::<f64>() >= rate {
return;
}
let data = format!("{}:{}|c", metric, value);
let data = format!("{}:{}|c|@{}", metric, value, rate);
self.stats.push_back(data);
}

Expand Down

0 comments on commit e4bf2b0

Please sign in to comment.