Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for overloading StatsD implementation #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class StatsD implements Closeable {
* @param host the hostname of the StatsD server.
* @param port the port of the StatsD server. This is typically 8125.
*/
StatsD(final String host, final int port) {
public StatsD(final String host, final int port) {
this(new InetSocketAddress(host, port), new DatagramSocketFactory());
}

Expand All @@ -60,7 +60,7 @@ public class StatsD implements Closeable {
* @param address the address of the Carbon server
* @param socketFactory the socket factory
*/
StatsD(final InetSocketAddress address, final DatagramSocketFactory socketFactory) {
public StatsD(final InetSocketAddress address, final DatagramSocketFactory socketFactory) {
this.address = address;
this.socketFactory = socketFactory;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public void connect() throws IOException {
*/
public void send(final String name, final String value) {
try {
String formatted = String.format("%s:%s|g", sanitize(name), sanitize(value));
String formatted = formatPacketContent(sanitize(name), sanitize(value));
byte[] bytes = formatted.getBytes(UTF_8);
socket.send(socketFactory.createPacket(bytes, bytes.length, address));
failures = 0;
Expand All @@ -108,6 +108,16 @@ public void send(final String name, final String value) {
}
}

/**
*
* @param name the name of the metric
* @param value the value of the metric
* @return formatted data packet content
*/
public String formatPacketContent(String name, String value) {
return String.format("%s:%s|g", name, value);
}

/**
* Returns the number of failed writes to the server.
*
Expand Down