Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

for real though

  • Loading branch information...
commit 0b72d0bca1ff256b6829969781979066ae781fb8 1 parent fe183ae
@mikedanese mikedanese authored
View
81 src/main/java/com/raskol/tradebot/dto/HistogramDTO.java
@@ -1,4 +1,85 @@
package com.raskol.tradebot.dto;
+import org.joda.time.DateTime;
+
+import java.util.Date;
+
public class HistogramDTO {
+ private final String label;
+ private final DateTime time;
+ private final int count;
+ private final long min;
+ private final long max;
+ private final double mean;
+ private final double stdDev;
+ private final double median;
+ private final double _75thPercentile;
+ private final double _95thPercentile;
+ private final double _99thPercentile;
+ private final double _999thPercentile;
+
+ public HistogramDTO(String label, int count, long min, long max, double mean, double stdDev, double median,
+ double _75thPercentile, double _95thPercentile, double _99thPercentile, double _999thPercentile) {
+ this.label = label;
+ this.time = new DateTime();
+ this.count = count;
+ this.min = min;
+ this.max = max;
+ this.mean = mean;
+ this.stdDev = stdDev;
+ this.median = median;
+ this._75thPercentile = _75thPercentile;
+ this._95thPercentile = _95thPercentile;
+ this._99thPercentile = _99thPercentile;
+ this._999thPercentile = _999thPercentile;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public DateTime getTime() {
+ return time;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public long getMin() {
+ return min;
+ }
+
+ public long getMax() {
+ return max;
+ }
+
+ public double getMean() {
+ return mean;
+ }
+
+ public double getStdDev() {
+ return stdDev;
+ }
+
+ public double getMedian() {
+ return median;
+ }
+
+ public double get_75thPercentile() {
+ return _75thPercentile;
+ }
+
+ public double get_95thPercentile() {
+ return _95thPercentile;
+ }
+
+ public double get_99thPercentile() {
+ return _99thPercentile;
+ }
+
+ public double get_999thPercentile() {
+ return _999thPercentile;
+ }
+
}
View
9 src/main/java/com/raskol/tradebot/metrics/CompleteHistogram.java
@@ -5,6 +5,7 @@
import com.codahale.metrics.Sampling;
import com.codahale.metrics.Snapshot;
import com.google.common.base.Joiner;
+import com.raskol.tradebot.dto.HistogramDTO;
import java.util.ArrayList;
@@ -61,7 +62,15 @@ public String toString() {
sb.add(String.format(" 99%% <= %2.2f", snapshot.get99thPercentile()));
sb.add(String.format(" 99.9%% <= %2.2f", snapshot.get999thPercentile()));
+
return Joiner.on("</br>").join(sb);
}
+
+ public HistogramDTO toDTO() {
+ final Snapshot snapshot = reservoir.getSnapshot();
+ return new HistogramDTO(getLabel(), snapshot.getValues().length, snapshot.getMin(), snapshot.getMax(), snapshot.getMean(),
+ snapshot.getStdDev(), snapshot.getMedian(), snapshot.get75thPercentile(), snapshot.get95thPercentile(),
+ snapshot.get99thPercentile(), snapshot.get999thPercentile());
+ }
}
View
15 src/main/java/com/raskol/tradebot/resource/TickerResource.java
@@ -1,9 +1,8 @@
package com.raskol.tradebot.resource;
-import com.google.common.base.Joiner;
-import com.google.common.collect.FluentIterable;
import com.google.common.escape.Escaper;
import com.google.common.html.HtmlEscapers;
+import com.raskol.tradebot.dto.HistogramDTO;
import com.raskol.tradebot.metrics.CompleteHistogram;
import com.raskol.tradebot.service.TickerService;
import com.yammer.metrics.annotation.Timed;
@@ -11,6 +10,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import java.util.ArrayList;
import java.util.List;
@Path("/transaction")
@@ -23,9 +23,12 @@ public TickerResource(TickerService tickerService) {
}
@GET
- @Produces("text/html") @Timed
- public String getInfos() {
- return "<head><meta http-equiv=\"refresh\" content=\"60\"></head><div>" +
- Joiner.on("</div></br><div>").join(tickerService.getHistograms()) + "</div>";
+ @Produces("application/json") @Timed
+ public List<HistogramDTO> getInfos() {
+ final ArrayList<HistogramDTO> histograms = new ArrayList<HistogramDTO>();
+ for (CompleteHistogram histogram : tickerService.getHistograms()) {
+ histograms.add(histogram.toDTO());
+ }
+ return histograms;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.