-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Johnson
committed
Apr 10, 2015
1 parent
2807dd6
commit ad81cae
Showing
10 changed files
with
239 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/etsy/statsd/profiler/reporter/InfluxDBReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.etsy.statsd.profiler.reporter; | ||
|
||
import com.etsy.statsd.profiler.Arguments; | ||
import org.influxdb.InfluxDB; | ||
import org.influxdb.InfluxDBFactory; | ||
import org.influxdb.dto.Serie; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Reporter that sends data to InfluxDB | ||
* | ||
* @author Andrew Johnson | ||
*/ | ||
public class InfluxDBReporter extends Reporter<InfluxDB> { | ||
public static final String VALUE_COLUMN = "value"; | ||
public static final String USERNAME_ARG = "username"; | ||
public static final String PASSWORD_ARG = "password"; | ||
public static final String DATABASE_ARG = "database"; | ||
|
||
private String prefix; | ||
private String username; | ||
private String password; | ||
private String database; | ||
|
||
public InfluxDBReporter(String server, int port, String prefix, Arguments arguments) { | ||
super(server, port, prefix, arguments); | ||
this.prefix = prefix; | ||
} | ||
|
||
/** | ||
* Record a gauge value in InfluxDB | ||
* | ||
* @param key The key for the gauge | ||
* @param value The value of the gauge | ||
*/ | ||
@Override | ||
public void recordGaugeValue(String key, long value) { | ||
Serie s = new Serie.Builder(String.format("%s.%s", prefix, key)) | ||
.columns(VALUE_COLUMN) | ||
.values(value) | ||
.build(); | ||
client.write(database, TimeUnit.MILLISECONDS, s); | ||
} | ||
|
||
/** | ||
* | ||
* @param server The server to which to report data | ||
* @param port The port on which the server is running | ||
* @param prefix The prefix for metrics | ||
* @return An InfluxDB client | ||
*/ | ||
@Override | ||
protected InfluxDB createClient(String server, int port, String prefix) { | ||
return InfluxDBFactory.connect(String.format("http://%s:%d", server, port), username, password); | ||
} | ||
|
||
/** | ||
* Handle remaining arguments | ||
* | ||
* @param arguments The arguments given to the profiler agent | ||
*/ | ||
@Override | ||
protected void handleArguments(Arguments arguments) { | ||
username = arguments.remainingArgs.get(USERNAME_ARG); | ||
password = arguments.remainingArgs.get(PASSWORD_ARG); | ||
database = arguments.remainingArgs.get(DATABASE_ARG); | ||
} | ||
} |
35 changes: 33 additions & 2 deletions
35
src/main/java/com/etsy/statsd/profiler/reporter/Reporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,47 @@ | ||
package com.etsy.statsd.profiler.reporter; | ||
|
||
import com.etsy.statsd.profiler.Arguments; | ||
|
||
/** | ||
* Interface for reporters | ||
* | ||
* @author Andrew Johnson | ||
*/ | ||
public interface Reporter { | ||
public abstract class Reporter<T> { | ||
public static final Class<?>[] CONSTRUCTOR_PARAM_TYPES =new Class<?>[]{String.class, int.class, String.class, Arguments.class}; | ||
|
||
/** | ||
* The underlying implementation for this reporter | ||
*/ | ||
protected T client; | ||
|
||
public Reporter(String server, int port, String prefix, Arguments arguments) { | ||
handleArguments(arguments); | ||
client = createClient(server, port, prefix); | ||
} | ||
|
||
/** | ||
* Record a gauge value | ||
* | ||
* @param key The name of the gauge | ||
* @param value The value of the gauge | ||
*/ | ||
void recordGaugeValue(String key, long value); | ||
public abstract void recordGaugeValue(String key, long value); | ||
|
||
/** | ||
* Construct the underlying client implementation for this reporter | ||
* | ||
* @param server The server to which to report data | ||
* @param port The port on which the server is running | ||
* @param prefix The prefix for metrics | ||
* @return An instance of T, the client implementation | ||
*/ | ||
protected abstract T createClient(String server, int port, String prefix); | ||
|
||
/** | ||
* Handle any additional arguments necessary for this reporter | ||
* | ||
* @param arguments The arguments given to the profiler agent | ||
*/ | ||
protected abstract void handleArguments(Arguments arguments); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.