Package org.microproxy.stats
Class StatsdSink
java.lang.Object
org.microproxy.stats.StatsdSink
- All Implemented Interfaces:
AutoCloseable
Pushes a registry's metrics to a statsd server over UDP, every flush interval (5 seconds by
default, as Envoy), from a virtual thread: counters as the increase since the last flush (
|c), gauges as their value (|g), by their flat names after the registry's prefix (envoy.cluster.direct.upstream_rq_total:3|c).
Histograms keep bucket counts rather than each value, so a histogram that recorded n
values since the last flush is sent as one timer, their mean, sampled at 1/n (
envoy.http.ingress.downstream_rq_time:12.5|ms|@0.25): statsd counts it n times, which
keeps the count and the mean (not the spread).
With DogStatsD tags, names are the tag-extracted ones and
the tags follow (envoy.cluster.upstream_rq_xx:3|c|#envoy_cluster_name:direct,
envoy_response_code_class:2). Lines are packed into datagrams of at most StatsdSink.Builder.maxPacketSize bytes. Sending is best effort: a failed send is logged and the next flush
goes on.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic StatsdSink.Builderbuilder(StatsRegistry registry, String hostAndPort) Starts a sink ofregistry's metrics to the statsd server athost:port.static StatsdSink.Builderbuilder(StatsRegistry registry, InetSocketAddress target) Starts a sink ofregistry's metrics to the statsd server attarget.voidclose()Stops flushing, after a last flush, and closes the socket.intflush()Sends what changed since the last flush now.start()Starts flushing every interval, on a virtual thread, untilclose().toString()
-
Method Details
-
builder
Starts a sink ofregistry's metrics to the statsd server athost:port.- Parameters:
registry- the metricshostAndPort- the server, such as127.0.0.1:8125- Returns:
- a builder
- Throws:
IllegalArgumentException- ifhostAndPorthas no valid port
-
builder
Starts a sink ofregistry's metrics to the statsd server attarget.- Parameters:
registry- the metricstarget- the server's address- Returns:
- a builder
-
start
Starts flushing every interval, on a virtual thread, untilclose().- Returns:
- this sink
- Throws:
IllegalStateException- if it was started or closed before
-
flush
public int flush()Sends what changed since the last flush now.- Returns:
- how many datagrams were sent
-
close
public void close()Stops flushing, after a last flush, and closes the socket.- Specified by:
closein interfaceAutoCloseable
-
toString
-