Class StatsdClient

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @NotThreadSafe
    public class StatsdClient
    extends java.lang.Object
    implements java.io.Closeable
    Client class for sending metrics to a StatsD server
    See Also:
    StatsD
    • Constructor Summary

      Constructors 
      Constructor Description
      StatsdClient​(java.lang.String host, int port)
      Constructs a client for the given host and port.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the connection to the StatsD server
      void connect()
      Creates a socket connection to the statsd server
      void sendCounter​(java.lang.String name, java.lang.String value)
      Sends the given measurement to the server as a counter
      void sendGauge​(java.lang.String name, java.lang.String value)
      Sends the given measurement to the server as a gauge
      boolean success()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StatsdClient

        public StatsdClient​(java.lang.String host,
                            int port)
        Constructs a client for the given host and port.
        Parameters:
        host - hostname of the statsd server.
        port - statsd port on the server
    • Method Detail

      • connect

        public void connect()
                     throws java.io.IOException
        Creates a socket connection to the statsd server
        Throws:
        java.lang.IllegalStateException - if the client is already connected
        java.io.IOException - if there is an error connecting
      • sendCounter

        public void sendCounter​(java.lang.String name,
                                java.lang.String value)
        Sends the given measurement to the server as a counter
        Parameters:
        name - metric name
        value - metric value
      • sendGauge

        public void sendGauge​(java.lang.String name,
                              java.lang.String value)
        Sends the given measurement to the server as a gauge
        Parameters:
        name - metric name
        value - metric value
      • close

        public void close()
        Close the connection to the StatsD server
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • success

        public boolean success()
        Returns:
        true if the last transmission was successful