Package io.dropwizard.metrics5.graphite
Class Graphite
- java.lang.Object
-
- io.dropwizard.metrics5.graphite.Graphite
-
- All Implemented Interfaces:
GraphiteSender,Closeable,AutoCloseable
public class Graphite extends Object implements GraphiteSender
A client to a Carbon server via TCP.
-
-
Constructor Summary
Constructors Constructor Description Graphite(String hostname, int port)Creates a new client which connects to the given address using the defaultSocketFactory.Graphite(String hostname, int port, SocketFactory socketFactory)Creates a new client which connects to the given address and socket factory.Graphite(String hostname, int port, SocketFactory socketFactory, Charset charset)Creates a new client which connects to the given address and socket factory using the given character set.Graphite(InetSocketAddress address)Creates a new client which connects to the given address using the defaultSocketFactory.Graphite(InetSocketAddress address, SocketFactory socketFactory)Creates a new client which connects to the given address and socket factory.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidconnect()Connects to the server.voidflush()Flushes buffer, if applicableintgetFailures()Returns the number of failed writes to the server.booleanisConnected()Returns true if ready to send dataprotected Stringsanitize(String s)voidsend(String name, String value, long timestamp)Sends the given measurement to the server.
-
-
-
Constructor Detail
-
Graphite
public Graphite(String hostname, int port)
Creates a new client which connects to the given address using the defaultSocketFactory.- Parameters:
hostname- The hostname of the Carbon serverport- The port of the Carbon server
-
Graphite
public Graphite(String hostname, int port, SocketFactory socketFactory)
Creates a new client which connects to the given address and socket factory.- Parameters:
hostname- The hostname of the Carbon serverport- The port of the Carbon serversocketFactory- the socket factory
-
Graphite
public Graphite(String hostname, int port, SocketFactory socketFactory, Charset charset)
Creates a new client which connects to the given address and socket factory using the given character set.- Parameters:
hostname- The hostname of the Carbon serverport- The port of the Carbon serversocketFactory- the socket factorycharset- the character set used by the server
-
Graphite
public Graphite(InetSocketAddress address)
Creates a new client which connects to the given address using the defaultSocketFactory.- 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 serversocketFactory- 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 serversocketFactory- the socket factorycharset- the character set used by the server
-
-
Method Detail
-
connect
public void connect() throws IllegalStateException, IOExceptionDescription copied from interface:GraphiteSenderConnects to the server.- Specified by:
connectin interfaceGraphiteSender- Throws:
IllegalStateException- if the client is already connectedIOException- if there is an error connecting
-
isConnected
public boolean isConnected()
Description copied from interface:GraphiteSenderReturns true if ready to send data- Specified by:
isConnectedin interfaceGraphiteSender
-
send
public void send(String name, String value, long timestamp) throws IOException
Description copied from interface:GraphiteSenderSends the given measurement to the server.- Specified by:
sendin interfaceGraphiteSender- Parameters:
name- the name of the metricvalue- the value of the metrictimestamp- the timestamp of the metric- Throws:
IOException- if there was an error sending the metric
-
getFailures
public int getFailures()
Description copied from interface:GraphiteSenderReturns the number of failed writes to the server.- Specified by:
getFailuresin interfaceGraphiteSender- Returns:
- the number of failed writes to the server
-
flush
public void flush() throws IOExceptionDescription copied from interface:GraphiteSenderFlushes buffer, if applicable- Specified by:
flushin interfaceGraphiteSender- Throws:
IOException- if there was an error during flushing metrics to the socket
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-