Class StatsdClientBuilder

java.lang.Object
com.itrsgroup.collection.instr.statsd.StatsdClientBuilder

public class StatsdClientBuilder extends Object
Builder for a statsd MetricsClient.
  • Constructor Details

    • StatsdClientBuilder

      public StatsdClientBuilder()
      Default constructor.
  • Method Details

    • channelType

      Configure the outbound channel type.

      Setting can be overridden at runtime via the STATSD_PROTOCOL environment variable. Valid values are: TCP | UDP | STDOUT.

      Parameters:
      type - channel type
      Returns:
      this
    • maxMessageSize

      public StatsdClientBuilder maxMessageSize(int size)
      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_SIZE environment variable.

      Parameters:
      size - max size
      Returns:
      this
      Throws:
      IllegalArgumentException - if the size is less than 128
    • samplingInterval

      public StatsdClientBuilder samplingInterval(long samplingInterval)
      Configure the default interval for periodic metric sampling (defaults to 10 seconds).

      Setting can be overridden at runtime by setting the STATSD_INTERVAL environment variable.

      Parameters:
      samplingInterval - interval in millis
      Returns:
      this
      Throws:
      IllegalArgumentException - if samplingInterval is less than one
    • queueSize

      public StatsdClientBuilder queueSize(int size)
      Configure the sending queue size (defaults to 8192).

      Setting can be overridden at runtime via the STATSD_QUEUE_SIZE environment variable.

      Parameters:
      size - size
      Returns:
      this
      Throws:
      IllegalArgumentException - if the size is not greater than zero
    • errorCallback

      public StatsdClientBuilder errorCallback(Consumer<Throwable> callback)
      Configure the error callback (defaults to no-op).
      Parameters:
      callback - callback
      Returns:
      this
      Throws:
      NullPointerException - if the callback is null
    • server

      public StatsdClientBuilder server(InetAddress server)
      Configure the destination server.

      Setting can be overridden at runtime via the STATSD_SERVER environment variable.

      Parameters:
      server - server address/hostname
      Returns:
      this
      Throws:
      NullPointerException - if the server is null
    • port

      public StatsdClientBuilder port(int port)
      Configure the destination port.

      Setting can be overridden at runtime via the STATSD_PORT environment variable.

      Parameters:
      port - port
      Returns:
      this
      Throws:
      IllegalArgumentException - if the port is not greater than zero and less than 65536
    • disablePlatformDimensions

      public StatsdClientBuilder disablePlatformDimensions()
      Configure whether platform dimensions are automatically added to each metric.

      Setting can be overridden at runtime via the STATSD_DISABLE_PLATFORM_DIMENSIONS environment variable.

      Returns:
      this
    • defaultDimensions

      public StatsdClientBuilder defaultDimensions(Dimension... dimensions)
      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

      public StatsdClientBuilder defaultDimension(String key, String value)
      Configure a default dimension.
      Parameters:
      key - key
      value - value
      Returns:
      this
      Throws:
      IllegalArgumentException - if the key or value is null or empty
    • defaultDimension

      public StatsdClientBuilder defaultDimension(Dimension dimension)
      Configure a default dimension.
      Parameters:
      dimension - dimension
      Returns:
      this
      Throws:
      NullPointerException - if the dimension is null
    • quietStartup

      public StatsdClientBuilder quietStartup(Duration 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

      public MetricsClient build()
      Build a client with the configured settings.

      If server(InetAddress) or port(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