public class NonBlockingStatsDClient extends Object implements StatsDClient
Upon instantiation, this client will establish a socket connection to a StatsD instance running on the specified host and port. Metrics are then sent over this connection as they are received by the client.
Three key methods are provided for the submission of data-points for the application under scrutiny:
incrementCounter(java.lang.String, java.lang.String...) - adds one to the value of the specified named counterrecordGaugeValue(java.lang.String, double, java.lang.String...) - records the latest fixed value for the specified named gaugerecordExecutionTime(java.lang.String, long, java.lang.String...) - records an execution time in milliseconds for the specified named operationrecordHistogramValue(java.lang.String, double, java.lang.String...) - records a value, to be tracked with average, maximum, and percentilesrecordEvent(com.timgroup.statsd.Event, java.lang.String...) - records an eventrecordSetValue(java.lang.String, java.lang.String, java.lang.String...) - records a value in a setAs part of a clean system shutdown, the stop() method should be invoked
on any StatsD clients.
| Constructor and Description |
|---|
NonBlockingStatsDClient(NonBlockingStatsDClientBuilder builder)
Create a new StatsD client communicating with a StatsD instance on the
host and port specified by the given builder.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Stop the statsd client.
|
void |
count(String aspect,
double delta,
double sampleRate,
String... tags)
Adjusts the specified counter by a given delta.
|
void |
count(String aspect,
double delta,
String... tags)
Adjusts the specified counter by a given delta.
|
void |
count(String aspect,
long delta,
double sampleRate,
String... tags)
Adjusts the specified counter by a given delta.
|
void |
count(String aspect,
long delta,
String... tags)
Adjusts the specified counter by a given delta.
|
protected StatsDProcessor |
createProcessor(int queueSize,
StatsDClientErrorHandler handler,
int maxPacketSizeBytes,
int bufferPoolSize,
int workers,
boolean blocking,
int aggregationFlushInterval,
int aggregationShards,
ThreadFactory threadFactory) |
protected StatsDSender |
createSender(StatsDClientErrorHandler handler,
WritableByteChannel clientChannel,
BufferPool pool,
BlockingQueue<ByteBuffer> buffers,
int senderWorkers,
ThreadFactory threadFactory) |
void |
decrement(String aspect,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.decrementCounter(String, double, String[]). |
void |
decrement(String aspect,
String... tags)
Convenience method equivalent to
decrementCounter(String, String[]). |
void |
decrementCounter(String aspect,
double sampleRate,
String... tags)
Decrements the specified counter by one.
|
void |
decrementCounter(String aspect,
String... tags)
Decrements the specified counter by one.
|
void |
distribution(String aspect,
double value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordDistributionValue(String, double, double, String[]). |
void |
distribution(String aspect,
double value,
String... tags)
Convenience method equivalent to
recordDistributionValue(String, double, String[]). |
void |
distribution(String aspect,
long value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordDistributionValue(String, long, double, String[]). |
void |
distribution(String aspect,
long value,
String... tags)
Convenience method equivalent to
recordDistributionValue(String, long, String[]). |
protected static String |
format(ThreadLocal<NumberFormat> formatter,
Number value) |
void |
gauge(String aspect,
double value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordGaugeValue(String, double, double, String[]). |
void |
gauge(String aspect,
double value,
String... tags)
Convenience method equivalent to
recordGaugeValue(String, double, String[]). |
void |
gauge(String aspect,
long value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordGaugeValue(String, long, double, String[]). |
void |
gauge(String aspect,
long value,
String... tags)
Convenience method equivalent to
recordGaugeValue(String, long, String[]). |
void |
histogram(String aspect,
double value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordHistogramValue(String, double, double, String[]). |
void |
histogram(String aspect,
double value,
String... tags)
Convenience method equivalent to
recordHistogramValue(String, double, String[]). |
void |
histogram(String aspect,
long value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordHistogramValue(String, long, double, String[]). |
void |
histogram(String aspect,
long value,
String... tags)
Convenience method equivalent to
recordHistogramValue(String, long, String[]). |
void |
increment(String aspect,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.incrementCounter(String, double, String[]). |
void |
increment(String aspect,
String... tags)
Convenience method equivalent to
incrementCounter(String, String[]). |
void |
incrementCounter(String aspect,
double sampleRate,
String... tags)
Increments the specified counter by one.
|
void |
incrementCounter(String aspect,
String... tags)
Increments the specified counter by one.
|
protected boolean |
isInvalidSample(double sampleRate) |
void |
recordDistributionValue(String aspect,
double value,
double sampleRate,
String... tags)
Records a value for the specified named distribution.
|
void |
recordDistributionValue(String aspect,
double value,
String... tags)
Records a value for the specified named distribution.
|
void |
recordDistributionValue(String aspect,
long value,
double sampleRate,
String... tags)
Records a value for the specified named distribution.
|
void |
recordDistributionValue(String aspect,
long value,
String... tags)
Records a value for the specified named distribution.
|
void |
recordEvent(Event event,
String... eventTags)
Records an event.
|
void |
recordExecutionTime(String aspect,
long timeInMs,
double sampleRate,
String... tags)
Records an execution time in milliseconds for the specified named operation.
|
void |
recordExecutionTime(String aspect,
long timeInMs,
String... tags)
Records an execution time in milliseconds for the specified named operation.
|
void |
recordGaugeValue(String aspect,
double value,
double sampleRate,
String... tags)
Records the latest fixed value for the specified named gauge.
|
void |
recordGaugeValue(String aspect,
double value,
String... tags)
Records the latest fixed value for the specified named gauge.
|
void |
recordGaugeValue(String aspect,
long value,
double sampleRate,
String... tags)
Records the latest fixed value for the specified named gauge.
|
void |
recordGaugeValue(String aspect,
long value,
String... tags)
Records the latest fixed value for the specified named gauge.
|
void |
recordHistogramValue(String aspect,
double value,
double sampleRate,
String... tags)
Records a value for the specified named histogram.
|
void |
recordHistogramValue(String aspect,
double value,
String... tags)
Records a value for the specified named histogram.
|
void |
recordHistogramValue(String aspect,
long value,
double sampleRate,
String... tags)
Records a value for the specified named histogram.
|
void |
recordHistogramValue(String aspect,
long value,
String... tags)
Records a value for the specified named histogram.
|
void |
recordServiceCheckRun(ServiceCheck sc)
Records a run status for the specified named service check.
|
void |
recordSetValue(String aspect,
String val,
String... tags)
Records a value for the specified set.
|
void |
serviceCheck(ServiceCheck sc)
Convenience method equivalent to
recordServiceCheckRun(ServiceCheck sc). |
void |
stop()
Cleanly shut down this StatsD client.
|
void |
time(String aspect,
long value,
double sampleRate,
String... tags)
Convenience method equivalent to
StatsDClient.recordExecutionTime(String, long, double, String[]). |
void |
time(String aspect,
long value,
String... tags)
Convenience method equivalent to
recordExecutionTime(String, long, String[]). |
public static final String DD_DOGSTATSD_PORT_ENV_VAR
public static final String DD_AGENT_HOST_ENV_VAR
public static final String DD_NAMED_PIPE_ENV_VAR
public static final String DD_ENTITY_ID_ENV_VAR
public static final int DEFAULT_UDP_MAX_PACKET_SIZE_BYTES
public static final int DEFAULT_UDS_MAX_PACKET_SIZE_BYTES
public static final int DEFAULT_QUEUE_SIZE
public static final int DEFAULT_POOL_SIZE
public static final int DEFAULT_PROCESSOR_WORKERS
public static final int DEFAULT_SENDER_WORKERS
public static final int DEFAULT_DOGSTATSD_PORT
public static final int SOCKET_TIMEOUT_MS
public static final int SOCKET_BUFFER_BYTES
public static final boolean DEFAULT_BLOCKING
public static final boolean DEFAULT_ENABLE_TELEMETRY
public static final boolean DEFAULT_ENABLE_AGGREGATION
public static final String CLIENT_TAG
public static final String CLIENT_VERSION_TAG
public static final String CLIENT_TRANSPORT_TAG
public static final Charset UTF_8
protected static final ThreadLocal<NumberFormat> NUMBER_FORMATTER
protected static final ThreadLocal<NumberFormat> SAMPLE_RATE_FORMATTER
protected final StatsDProcessor statsDProcessor
protected StatsDProcessor telemetryStatsDProcessor
protected final StatsDSender statsDSender
protected StatsDSender telemetryStatsDSender
protected final Telemetry telemetry
public NonBlockingStatsDClient(NonBlockingStatsDClientBuilder builder) throws StatsDClientException
builder - the resolved configuration builderStatsDClientExceptionNonBlockingStatsDClientBuilder.resolve()protected static String format(ThreadLocal<NumberFormat> formatter, Number value)
protected StatsDProcessor createProcessor(int queueSize, StatsDClientErrorHandler handler, int maxPacketSizeBytes, int bufferPoolSize, int workers, boolean blocking, int aggregationFlushInterval, int aggregationShards, ThreadFactory threadFactory) throws Exception
Exceptionprotected StatsDSender createSender(StatsDClientErrorHandler handler, WritableByteChannel clientChannel, BufferPool pool, BlockingQueue<ByteBuffer> buffers, int senderWorkers, ThreadFactory threadFactory) throws Exception
Exceptionpublic void stop()
In blocking mode, this will block until all messages are sent to the server.
stop in interface StatsDClientpublic void close()
StatsDClientclose in interface StatsDClientclose in interface Closeableclose in interface AutoCloseableStatsDClient.stop()public void count(String aspect, long delta, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
count in interface StatsDClientaspect - the name of the counter to adjustdelta - the amount to adjust the counter bytags - array of tags to be added to the datapublic void count(String aspect, long delta, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
count in interface StatsDClientaspect - the name of the counter to adjustdelta - the amount to adjust the counter bysampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void count(String aspect, double delta, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
count in interface StatsDClientaspect - the name of the counter to adjustdelta - the amount to adjust the counter bytags - array of tags to be added to the datapublic void count(String aspect, double delta, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
count in interface StatsDClientaspect - the name of the counter to adjustdelta - the amount to adjust the counter bysampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void incrementCounter(String aspect, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
incrementCounter in interface StatsDClientaspect - the name of the counter to incrementtags - array of tags to be added to the datapublic void incrementCounter(String aspect, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
incrementCounter in interface StatsDClientaspect - the name of the counter to incrementsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void increment(String aspect, String... tags)
incrementCounter(String, String[]).increment in interface StatsDClientaspect - the name of the counter to incrementtags - array of tags to be added to the datapublic void increment(String aspect, double sampleRate, String... tags)
StatsDClient.incrementCounter(String, double, String[]).increment in interface StatsDClientaspect - the name of the counter to incrementsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void decrementCounter(String aspect, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
decrementCounter in interface StatsDClientaspect - the name of the counter to decrementtags - array of tags to be added to the datapublic void decrementCounter(String aspect, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
decrementCounter in interface StatsDClientaspect - the name of the counter to decrementsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void decrement(String aspect, String... tags)
decrementCounter(String, String[]).decrement in interface StatsDClientaspect - the name of the counter to decrementtags - array of tags to be added to the datapublic void decrement(String aspect, double sampleRate, String... tags)
StatsDClient.decrementCounter(String, double, String[]).decrement in interface StatsDClientaspect - the name of the counter to decrementsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordGaugeValue(String aspect, double value, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordGaugeValue in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugetags - array of tags to be added to the datapublic void recordGaugeValue(String aspect, double value, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordGaugeValue in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugesampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordGaugeValue(String aspect, long value, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordGaugeValue in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugetags - array of tags to be added to the datapublic void recordGaugeValue(String aspect, long value, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordGaugeValue in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugesampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void gauge(String aspect, double value, String... tags)
recordGaugeValue(String, double, String[]).gauge in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugetags - array of tags to be added to the datapublic void gauge(String aspect, double value, double sampleRate, String... tags)
StatsDClient.recordGaugeValue(String, double, double, String[]).gauge in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugesampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void gauge(String aspect, long value, String... tags)
recordGaugeValue(String, long, String[]).gauge in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugetags - array of tags to be added to the datapublic void gauge(String aspect, long value, double sampleRate, String... tags)
StatsDClient.recordGaugeValue(String, long, double, String[]).gauge in interface StatsDClientaspect - the name of the gaugevalue - the new reading of the gaugesampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordExecutionTime(String aspect, long timeInMs, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordExecutionTime in interface StatsDClientaspect - the name of the timed operationtimeInMs - the time in millisecondstags - array of tags to be added to the datapublic void recordExecutionTime(String aspect, long timeInMs, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordExecutionTime in interface StatsDClientaspect - the name of the timed operationtimeInMs - the time in millisecondssampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void time(String aspect, long value, String... tags)
recordExecutionTime(String, long, String[]).time in interface StatsDClientaspect - the name of the timed operationvalue - the time in millisecondstags - array of tags to be added to the datapublic void time(String aspect, long value, double sampleRate, String... tags)
StatsDClient.recordExecutionTime(String, long, double, String[]).time in interface StatsDClientaspect - the name of the timed operationvalue - the time in millisecondssampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordHistogramValue(String aspect, double value, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordHistogramValue in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramtags - array of tags to be added to the datapublic void recordHistogramValue(String aspect, double value, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordHistogramValue in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordHistogramValue(String aspect, long value, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordHistogramValue in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramtags - array of tags to be added to the datapublic void recordHistogramValue(String aspect, long value, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordHistogramValue in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void histogram(String aspect, double value, String... tags)
recordHistogramValue(String, double, String[]).histogram in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramtags - array of tags to be added to the datapublic void histogram(String aspect, double value, double sampleRate, String... tags)
StatsDClient.recordHistogramValue(String, double, double, String[]).histogram in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void histogram(String aspect, long value, String... tags)
recordHistogramValue(String, long, String[]).histogram in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramtags - array of tags to be added to the datapublic void histogram(String aspect, long value, double sampleRate, String... tags)
StatsDClient.recordHistogramValue(String, long, double, String[]).histogram in interface StatsDClientaspect - the name of the histogramvalue - the value to be incorporated in the histogramsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordDistributionValue(String aspect, double value, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordDistributionValue in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributiontags - array of tags to be added to the datapublic void recordDistributionValue(String aspect, double value, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordDistributionValue in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributionsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordDistributionValue(String aspect, long value, String... tags)
This method is non-blocking and is guaranteed not to throw an exception.
recordDistributionValue in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributiontags - array of tags to be added to the datapublic void recordDistributionValue(String aspect, long value, double sampleRate, String... tags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordDistributionValue in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributionsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void distribution(String aspect, double value, String... tags)
recordDistributionValue(String, double, String[]).distribution in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributiontags - array of tags to be added to the datapublic void distribution(String aspect, double value, double sampleRate, String... tags)
StatsDClient.recordDistributionValue(String, double, double, String[]).distribution in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributionsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void distribution(String aspect, long value, String... tags)
recordDistributionValue(String, long, String[]).distribution in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributiontags - array of tags to be added to the datapublic void distribution(String aspect, long value, double sampleRate, String... tags)
StatsDClient.recordDistributionValue(String, long, double, String[]).distribution in interface StatsDClientaspect - the name of the distributionvalue - the value to be incorporated in the distributionsampleRate - percentage of time metric to be senttags - array of tags to be added to the datapublic void recordEvent(Event event, String... eventTags)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordEvent in interface StatsDClientevent - The event to recordeventTags - array of tags to be added to the datapublic void recordServiceCheckRun(ServiceCheck sc)
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordServiceCheckRun in interface StatsDClientsc - the service check objectpublic void serviceCheck(ServiceCheck sc)
recordServiceCheckRun(ServiceCheck sc).serviceCheck in interface StatsDClientsc - the service check objectpublic void recordSetValue(String aspect, String val, String... tags)
Sets are used to count the number of unique elements in a group. If you want to track the number of unique visitor to your site, sets are a great way to do that.
This method is a DataDog extension, and may not work with other servers.
This method is non-blocking and is guaranteed not to throw an exception.
recordSetValue in interface StatsDClientaspect - the name of the setval - the value to tracktags - array of tags to be added to the dataprotected boolean isInvalidSample(double sampleRate)
Copyright © 2022. All rights reserved.