Class StatsdClientBuilder
MetricsClient.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a client with the configured settings.Configure the outbound channel type.defaultDimension(Dimension dimension) Configure a default dimension.defaultDimension(String key, String value) Configure a default dimension.defaultDimensions(Dimension... dimensions) Configure the default dimensions.Configure whether platform dimensions are automatically added to each metric.errorCallback(Consumer<Throwable> callback) Configure the error callback (defaults to no-op).maxMessageSize(int size) Configure the maximum message size (defaults to 1432 for UDP and 4096 for TCP).port(int port) Configure the destination port.queueSize(int size) Configure the sending queue size (defaults to 8192).quietStartup(Duration quietStartup) Configure the quiet startup period.samplingInterval(long samplingInterval) Configure the default interval for periodic metric sampling (defaults to 10 seconds).server(InetAddress server) Configure the destination server.
-
Constructor Details
-
StatsdClientBuilder
public StatsdClientBuilder()Default constructor.
-
-
Method Details
-
channelType
Configure the outbound channel type.Setting can be overridden at runtime via the
STATSD_PROTOCOLenvironment variable. Valid values are:TCP | UDP | STDOUT.- Parameters:
type- channel type- Returns:
- this
-
maxMessageSize
Configure the maximum message size (defaults to 1432 for UDP and 4096 for TCP).Setting can be overridden at runtime via the
STATSD_MAX_MESSAGE_SIZEenvironment variable.- Parameters:
size- max size- Returns:
- this
- Throws:
IllegalArgumentException- if the size is less than 128
-
samplingInterval
Configure the default interval for periodic metric sampling (defaults to 10 seconds).Setting can be overridden at runtime by setting the
STATSD_INTERVALenvironment variable.- Parameters:
samplingInterval- interval in millis- Returns:
- this
- Throws:
IllegalArgumentException- if samplingInterval is less than one
-
queueSize
Configure the sending queue size (defaults to 8192).Setting can be overridden at runtime via the
STATSD_QUEUE_SIZEenvironment variable.- Parameters:
size- size- Returns:
- this
- Throws:
IllegalArgumentException- if the size is not greater than zero
-
errorCallback
Configure the error callback (defaults to no-op).- Parameters:
callback- callback- Returns:
- this
- Throws:
NullPointerException- if the callback is null
-
server
Configure the destination server.Setting can be overridden at runtime via the
STATSD_SERVERenvironment variable.- Parameters:
server- server address/hostname- Returns:
- this
- Throws:
NullPointerException- if the server is null
-
port
Configure the destination port.Setting can be overridden at runtime via the
STATSD_PORTenvironment variable.- Parameters:
port- port- Returns:
- this
- Throws:
IllegalArgumentException- if the port is not greater than zero and less than 65536
-
disablePlatformDimensions
Configure whether platform dimensions are automatically added to each metric.Setting can be overridden at runtime via the
STATSD_DISABLE_PLATFORM_DIMENSIONSenvironment variable.- Returns:
- this
-
defaultDimensions
Configure the default dimensions.Use this method to set all the dimensions at once (it will overwrite any existing configured dimensions).
- Parameters:
dimensions- dimensions- Returns:
- this
- Throws:
NullPointerException- if the dimensions are null
-
defaultDimension
Configure a default dimension.- Parameters:
key- keyvalue- value- Returns:
- this
- Throws:
IllegalArgumentException- if the key or value is null or empty
-
defaultDimension
Configure a default dimension.- Parameters:
dimension- dimension- Returns:
- this
- Throws:
NullPointerException- if the dimension is null
-
quietStartup
Configure the quiet startup period.- Parameters:
quietStartup- period after startup during which errors are suppressed- Returns:
- this
- Throws:
NullPointerException- if the arg is null
-
build
Build a client with the configured settings.If
server(InetAddress)orport(int)were not configured, the server and port settings will be resolved first by checking if STATSD_SERVER and STATSD_PORT environment variables are present, otherwise defaulting to localhost:8125.If
errorCallback(Consumer)is not configured, a no-op error handler will be used, i.e. errors will be silently ignored.- Returns:
- client
- Throws:
IllegalArgumentException- if the STATSD_SERVER environment variable is not a valid IP address or resolvable hostname, or if the STATSD_PORT environment variable is not a valid port
-