Skip to content

Commit

Permalink
added timed out stats
Browse files Browse the repository at this point in the history
  • Loading branch information
EinsamHauer committed Aug 19, 2015
1 parent 90713de commit 92d128d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public FullHttpResponse call() throws EvaluationException, LogarithmicScaleNotAl
}, readerConfiguration.getRequestTimeout(), TimeUnit.SECONDS, true);
} catch (UncheckedTimeoutException e) {
logger.debug("Request timed out: " + parameters);
statsService.incTimedOutRequests(parameters.getTenant());
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE);
} catch (Exception e) {
logger.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.joda.time.DateTimeZone;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -18,7 +17,6 @@
* @author Andrei Ivanov
*/
public class StatsService {
private static final String SCHEDULER_NAME = "distheneReaderStatsFlusher";

private Logger logger = Logger.getLogger(StatsService.class);

Expand Down Expand Up @@ -72,6 +70,10 @@ public void incThrottleTime(String tenant, double value) {
getStatsRecord(tenant).incThrottled(value);
}

public void incTimedOutRequests(String tenant) {
getStatsRecord(tenant).incTimedOutRequests();
}


private synchronized void flush() {
Map<String, StatsRecord> statsToFlush = new HashMap<>();
Expand All @@ -93,6 +95,7 @@ private synchronized void flush() {
long totalRenderPointsRead = 0;
long totalPathsRequests = 0;
double totalThrottled = 0;
long totalTimedOutRequests = 0;

for (Map.Entry<String, StatsRecord> entry : statsToFlush.entrySet()) {
String tenant = entry.getKey();
Expand All @@ -103,19 +106,22 @@ private synchronized void flush() {
totalRenderPointsRead += statsRecord.getRenderPointsRead();
totalPathsRequests += statsRecord.getPathsRequests();
totalThrottled += statsRecord.getThrottled();
totalTimedOutRequests += statsRecord.getTimedOutRequests();

dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.tenants." + tenant + ".render_requests " + statsRecord.getRenderRequests() + " " + timestamp + " " + statsConfiguration.getTenant() + "\n");
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.tenants." + tenant + ".render_paths_read " + statsRecord.getRenderPathsRead() + " " + timestamp + " " + statsConfiguration.getTenant() + "\n");
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.tenants." + tenant + ".render_points_read " + statsRecord.getRenderPointsRead() + " " + timestamp + " " + statsConfiguration.getTenant() + "\n");
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.tenants." + tenant + ".paths_requests " + statsRecord.getPathsRequests() + " " + timestamp + " " + statsConfiguration.getTenant() + "\n");
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.tenants." + tenant + ".throttled " + statsRecord.getThrottled() + " " + timestamp + " " + statsConfiguration.getTenant() + "\n");
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.tenants." + tenant + ".timed_out_requests " + statsRecord.getTimedOutRequests() + " " + timestamp + " " + statsConfiguration.getTenant() + "\n");
}

dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.render_requests " + totalRenderRequests + " " + timestamp + " " + statsConfiguration.getTenant());
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.render_paths_read " + totalRenderPathsRead + " " + timestamp + " " + statsConfiguration.getTenant());
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.render_points_read " + totalRenderPointsRead + " " + timestamp + " " + statsConfiguration.getTenant());
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.paths_requests " + totalPathsRequests + " " + timestamp + " " + statsConfiguration.getTenant());
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.throttled " + totalThrottled + " " + timestamp + " " + statsConfiguration.getTenant());
dos.writeBytes(statsConfiguration.getHostname() + ".disthene-reader.timed_out_requests " + totalTimedOutRequests + " " + timestamp + " " + statsConfiguration.getTenant());

dos.flush();
connection.close();
Expand All @@ -134,26 +140,26 @@ private class StatsRecord {
private AtomicLong renderPointsRead = new AtomicLong(0);
private AtomicLong pathsRequests = new AtomicLong(0);
private AtomicDouble throttled = new AtomicDouble(0);
private AtomicLong timedOutRequests = new AtomicLong(0);

public StatsRecord() {
}



public StatsRecord(long renderRequests, long renderPathsRead, long renderPointsRead, long pathsRequests, double throttled) {
public StatsRecord(long renderRequests, long renderPathsRead, long renderPointsRead, long pathsRequests, double throttled, long timedOut) {
this.renderRequests = new AtomicLong(renderRequests);
this.renderPathsRead = new AtomicLong(renderPathsRead);
this.renderPointsRead = new AtomicLong(renderPointsRead);
this.pathsRequests = new AtomicLong(pathsRequests);
this.throttled = new AtomicDouble(throttled);
this.timedOutRequests = new AtomicLong(timedOut);
}

/**
* Resets the stats to zeroes and returns a snapshot of the record
* @return snapshot of the record
*/
public StatsRecord reset() {
return new StatsRecord(renderRequests.getAndSet(0), renderPathsRead.getAndSet(0), renderPointsRead.getAndSet(0), pathsRequests.getAndSet(0), throttled.getAndSet(0));
return new StatsRecord(renderRequests.getAndSet(0), renderPathsRead.getAndSet(0), renderPointsRead.getAndSet(0), pathsRequests.getAndSet(0), throttled.getAndSet(0), timedOutRequests.getAndSet(0));
}

public void incRenderRequests() {
Expand All @@ -176,6 +182,10 @@ public void incThrottled(double value) {
throttled.addAndGet(value);
}

public void incTimedOutRequests() {
timedOutRequests.addAndGet(1);
}

public long getRenderRequests() {
return renderRequests.get();
}
Expand All @@ -195,6 +205,11 @@ public long getPathsRequests() {
public double getThrottled() {
return throttled.get();
}

public long getTimedOutRequests() {
return timedOutRequests.get();
}

}

}

0 comments on commit 92d128d

Please sign in to comment.