Skip to content

Instantly share code, notes, and snippets.

@TurtleShip
Last active December 19, 2015 10:09
Show Gist options
  • Save TurtleShip/5938126 to your computer and use it in GitHub Desktop.
Save TurtleShip/5938126 to your computer and use it in GitHub Desktop.
Example usage of ServerCollector
/**
* Assume that there is a core service running at http://core-service-node1.com:8080
* Then metrics data will be available at http://core-service-node1.com:8081?metrics
* ServerDataCollector can pull metrics data at a regular interval, and monitor real-time.
* it can also save the monitored values */
public class PoundieService {
public static void main(String[] args) throws URISyntaxException, InterruptedException {
/**
* Define a load and run it. Vikram's code goes here.
*/
/**
* Let's assume that we want to monitor metrics of two different core services
* that the load is hitting
* http://core-feedie-node1.com:8081/metrics
* http://core-tokie-node1.com:8081/metrics
*/
// instantiate collector
ServerDataCollector feedie_collector = new ServerDataCollector("http://core-feedie-node1.com:8081/metrics");
ServerDataCollector tokie_collector = new ServerDataCollector("http://core-tokie-node1.com:8081/metrics");
// set how frequently you want to update your metrics data in seconds
feedie_collector.setRateInSec(1L);
tokie_collector.setRateInSec(1L);
/** Turn on CSV Report. You can filter out some resources if you want.
* If you don't specify filter, it will dump all data in csv format except
* jvm, partie, logback, and jetty related data
* You need to pass in which directory you want to save the data
* All server data will be saved under directory ./server_data/
* */
feedie_collector.turnCSVReporterOn("feedie"); // will be saved under ./server_data/feedie/
tokie_collector.turnCSVReporterOn("tokie"); // will be saved under ./server_data/tokie/
/**
* Turn console reporter on. You need to pass in list of resources you want to monitor.
* It will print NOTHING by default.
* I made it this way because printing every on the console will be useless.
* You want to see only the ones you want to monitor on your console
* */
LinkedList<String> feedie_wishList = new LinkedList<>(Array.asList("com.yammer.feedie.resources.someResource"));
LinkedList<String> tokie_wishList = new LinkedList<>(Array.asList("com.yammer.auth.resources.someResource",
"com.yammer.tokie.resources.anotherResource"));
feedie_collector.turnConsoleReporterOn(feedie_wishList);
tokie_collector.turnConsoleReporterOn(tokie_wishList);
/**
* You also might want to push your data to graphite server so that you can monitor it in a grpah format
* real-time. Graphite also supports mulitple other functions. Check out https://graphite.readthedocs.org/en/0.9.10/
* Format is
* collector.turnGraphiteReporterOn(graphite_host, port, prefixForMetrics)
* prefixForMetrics is optional but highly recommended. This makes it eaiser for you to distinguish
* where you collected your metrics data from.
*/
feedie_collector.turnGraphiteReporterOn("http://graphite-server.com", 2003, "fromFeedie");
tokie_collector.turnGraphiteReporterOn("http://graphite-server.com", 2003, "fromTokie");
// After you defined how you want to collect and monitor, start reporting.
feedie_collector.report();
tokie_coolector.report();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment