Class Graphite

java.lang.Object
com.codahale.metrics.graphite.Graphite
All Implemented Interfaces:
Closeable, AutoCloseable

public class Graphite extends Object implements Closeable
A client to a Carbon server.
  • Field Details

    • WHITESPACE

      private static final Pattern WHITESPACE
    • UTF_8

      private static final Charset UTF_8
    • address

      private final InetSocketAddress address
    • socketFactory

      private final SocketFactory socketFactory
    • charset

      private final Charset charset
    • socket

      private Socket socket
    • writer

      private Writer writer
    • failures

      private int failures
  • Constructor Details

    • Graphite

      public Graphite(InetSocketAddress address)
      Creates a new client which connects to the given address using the default SocketFactory.
      Parameters:
      address - the address of the Carbon server
    • Graphite

      public Graphite(InetSocketAddress address, SocketFactory socketFactory)
      Creates a new client which connects to the given address and socket factory.
      Parameters:
      address - the address of the Carbon server
      socketFactory - the socket factory
    • Graphite

      public Graphite(InetSocketAddress address, SocketFactory socketFactory, Charset charset)
      Creates a new client which connects to the given address and socket factory using the given character set.
      Parameters:
      address - the address of the Carbon server
      socketFactory - the socket factory
      charset - the character set used by the server
  • Method Details

    • connect

      public void connect() throws IllegalStateException, IOException
      Connects to the server.
      Throws:
      IllegalStateException - if the client is already connected
      IOException - if there is an error connecting
    • send

      public void send(String name, String value, long timestamp) throws IOException
      Sends the given measurement to the server.
      Parameters:
      name - the name of the metric
      value - the value of the metric
      timestamp - the timestamp of the metric
      Throws:
      IOException - if there was an error sending the metric
    • getFailures

      public int getFailures()
      Returns the number of failed writes to the server.
      Returns:
      the number of failed writes to the server
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • sanitize

      protected String sanitize(String s)