Skip to content

Commit

Permalink
fixed empty message issue and changed the field names to http monitor…
Browse files Browse the repository at this point in the history
… specific names
  • Loading branch information
sivasamyk committed Sep 8, 2015
1 parent 313ae99 commit 3923315
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public URI getURL() {

@Override
public Version getVersion() {
return new Version(1, 0, 1);
return new Version(1, 0, 2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,28 @@ public void run() {
long time;
Map<String, Object> eventdata = Maps.newHashMap();
eventdata.put("version", "1.1");
eventdata.put("_url", config.getUrl());
eventdata.put("_http.monitor.url", config.getUrl());
eventdata.put("_label", config.getLabel());
try {
Response response = requestBuilder.execute().get();
long endTime = System.currentTimeMillis();
time = endTime - startTime;
eventdata.put("host", response.getUri().getHost());
eventdata.put("_status", response.getStatusCode());
eventdata.put("_statusLine", response.getStatusText());
eventdata.put("_http.monitor.status", response.getStatusCode());
eventdata.put("_http.monitor.statusLine", response.getStatusText());
String responseBodyStr = new String(response.getResponseBodyAsBytes());
eventdata.put("_size", responseBodyStr.length());
eventdata.put("_http.monitor.responseSize", responseBodyStr.length());
if (config.isLogResponseBody()) {
eventdata.put("full_message", responseBodyStr);
}
String shortMessage = responseBodyStr.length() > 50 ? responseBodyStr.substring(0, 50) :
responseBodyStr;
if (shortMessage.isEmpty()) {
shortMessage = "no_response";
}
eventdata.put("short_message", shortMessage);


if (config.getResponseHeadersToRecord() != null) {
for (String header : config.getResponseHeadersToRecord()) {
eventdata.put("_" + header, response.getHeader(header));
Expand All @@ -195,24 +200,24 @@ public void run() {
} catch (ExecutionException e) {
eventdata.put("host", new URL(config.getUrl()).getHost());
eventdata.put("short_message", "Request failed :" + e.getMessage());
eventdata.put("_size", 0);
eventdata.put("_http.monitor.responseSize", 0);
long endTime = System.currentTimeMillis();
time = endTime - startTime;
//In case of connection timeout we get an execution exception with root cause as timeoutexception
if (e.getCause() instanceof TimeoutException) {
LOGGER.debug("Timeout while executing request for URL " + config.getUrl(), e);
eventdata.put("_status", 998);
eventdata.put("_http.monitor.status", 998);
} else if (e.getCause() instanceof ConnectException) {
//In case of connect exception we get an execution exception with root cause as connectexception
LOGGER.debug("Exception while executing request for URL " + config.getUrl(), e);
eventdata.put("_status", 999);
eventdata.put("_http.monitor.status", 999);
} else {
//Any other exception..
LOGGER.debug("Exception while executing request for URL " + config.getUrl(), e);
eventdata.put("_status", 997);
eventdata.put("_http.monitor.status", 997);
}
}
eventdata.put("_responseTime", time);
eventdata.put("_http.monitor.responseTime", time);

//publish to graylog server
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
Expand Down

0 comments on commit 3923315

Please sign in to comment.