Package com.codahale.metrics.graphite
Class Graphite
- java.lang.Object
-
- com.codahale.metrics.graphite.Graphite
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class Graphite extends java.lang.Object implements java.io.CloseableA client to a Carbon server.
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.InetSocketAddressaddressprivate java.nio.charset.Charsetcharsetprivate intfailuresprivate java.net.Socketsocketprivate javax.net.SocketFactorysocketFactoryprivate static java.nio.charset.CharsetUTF_8private static java.util.regex.PatternWHITESPACEprivate java.io.Writerwriter
-
Constructor Summary
Constructors Constructor Description Graphite(java.net.InetSocketAddress address)Creates a new client which connects to the given address using the defaultSocketFactory.Graphite(java.net.InetSocketAddress address, javax.net.SocketFactory socketFactory)Creates a new client which connects to the given address and socket factory.Graphite(java.net.InetSocketAddress address, javax.net.SocketFactory socketFactory, java.nio.charset.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.intgetFailures()Returns the number of failed writes to the server.protected java.lang.Stringsanitize(java.lang.String s)voidsend(java.lang.String name, java.lang.String value, long timestamp)Sends the given measurement to the server.
-
-
-
Field Detail
-
WHITESPACE
private static final java.util.regex.Pattern WHITESPACE
-
UTF_8
private static final java.nio.charset.Charset UTF_8
-
address
private final java.net.InetSocketAddress address
-
socketFactory
private final javax.net.SocketFactory socketFactory
-
charset
private final java.nio.charset.Charset charset
-
socket
private java.net.Socket socket
-
writer
private java.io.Writer writer
-
failures
private int failures
-
-
Constructor Detail
-
Graphite
public Graphite(java.net.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(java.net.InetSocketAddress address, javax.net.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(java.net.InetSocketAddress address, javax.net.SocketFactory socketFactory, java.nio.charset.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 java.lang.IllegalStateException, java.io.IOExceptionConnects to the server.- Throws:
java.lang.IllegalStateException- if the client is already connectedjava.io.IOException- if there is an error connecting
-
send
public void send(java.lang.String name, java.lang.String value, long timestamp) throws java.io.IOExceptionSends the given measurement to the server.- Parameters:
name- the name of the metricvalue- the value of the metrictimestamp- the timestamp of the metric- Throws:
java.io.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 java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
sanitize
protected java.lang.String sanitize(java.lang.String s)
-
-