Class StatsdMetricWriter
- java.lang.Object
- org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,CounterWriter
,GaugeWriter
,MetricWriter
public class StatsdMetricWriter extends Object implements MetricWriter, Closeable
AMetricWriter
that pushes data to statsd. Statsd has the concept of counters and gauges, but only supports gauges with data type Long, so values will be truncated towards zero. Metrics whose name contains "timer." (but not "gauge." or "counter.") will be treated as execution times (in statsd terms). Anything incremented is treated as a counter, and anything with a snapshot value inset(Metric)
is treated as a gauge.- Since:
- 1.3.0
Constructor Summary
Constructors Constructor Description StatsdMetricWriter(com.timgroup.statsd.StatsDClient client)
Create a new writer with the given client.StatsdMetricWriter(String host, int port)
Create a new writer instance with the given parameters.StatsdMetricWriter(String prefix, String host, int port)
Create a new writer with the given parameters.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
increment(Delta<?> delta)
Increment the value of a metric (or decrement if the delta is negative).void
reset(String name)
Reset the value of a metric, usually to zero value.void
set(Metric<?> value)
Set the value of a metric.
Constructor Detail
StatsdMetricWriter
public StatsdMetricWriter(String host, int port)
Create a new writer instance with the given parameters.- Parameters:
host
- the hostname for the statsd serverport
- the port for the statsd server
StatsdMetricWriter
public StatsdMetricWriter(String prefix, String host, int port)
Create a new writer with the given parameters.- Parameters:
prefix
- the prefix to apply to all metric names (can be null)host
- the hostname for the statsd serverport
- the port for the statsd server
StatsdMetricWriter
public StatsdMetricWriter(com.timgroup.statsd.StatsDClient client)
Create a new writer with the given client.- Parameters:
client
- StatsD client to write metrics with
Method Detail
increment
public void increment(Delta<?> delta)
Description copied from interface:CounterWriter
Increment the value of a metric (or decrement if the delta is negative). The name of the delta is the name of the metric to increment.- Specified by:
increment
in interfaceCounterWriter
- Parameters:
delta
- the amount to increment by
set
public void set(Metric<?> value)
Description copied from interface:GaugeWriter
Set the value of a metric.- Specified by:
set
in interfaceGaugeWriter
- Parameters:
value
- the value
reset
public void reset(String name)
Description copied from interface:CounterWriter
Reset the value of a metric, usually to zero value. Implementations can discard the old values if desired, but may choose not to. This operation is optional (some implementations may not be able to fulfill the contract, in which case they should simply do nothing).- Specified by:
reset
in interfaceCounterWriter
- Parameters:
name
- the name to reset
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable