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.Closeable
A client to a Carbon server.
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.InetSocketAddress
address
private java.nio.charset.Charset
charset
private int
failures
private java.net.Socket
socket
private javax.net.SocketFactory
socketFactory
private static java.nio.charset.Charset
UTF_8
private static java.util.regex.Pattern
WHITESPACE
private java.io.Writer
writer
-
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 void
close()
void
connect()
Connects to the server.int
getFailures()
Returns the number of failed writes to the server.protected java.lang.String
sanitize(java.lang.String s)
void
send(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.IOException
Connects 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.IOException
Sends 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
sanitize
protected java.lang.String sanitize(java.lang.String s)
-
-