I want track the health state of an application that exposes it's health over mocriprofile heatlhcheck api. So I have multible states in one healthcheck.
I can't find in heartbeat a monitor that can handle this. So I end up with a custom solution.
I look at the exported fields of heartbeat and try to create a hearbeat entry with that json fields
jsonMap.put("@timestamp", zonedDateTime.toString());
jsonMap.put("@metadata.beat", "heartbeat");
jsonMap.put("@metadata.type", "doc");
jsonMap.put("@metadata.version", "6.7.0");
jsonMap.put("event.dataset", "uptime");
jsonMap.put("beat.name", "heartbeat");
jsonMap.put("beat.hostname", "heartbeat");
jsonMap.put("beat.version", "6.7.0");
jsonMap.put("host.name", "heartbeat");
jsonMap.put("tcp.port", 9090);
jsonMap.put("monitor.id", check.getName());
jsonMap.put("monitor.status", check.getState().name().toLowerCase());
jsonMap.put("monitor.name", "http");
jsonMap.put("monitor.type", "http");
jsonMap.put("monitor.scheme", "http");
jsonMap.put("monitor.ip", "172.17.8.101");
jsonMap.put("http.url", "http://172.17.8.1:9990/health");
jsonMap.put("tcp.rtt.connect.us",50);
jsonMap.put("http.rtt.response_header.us",50);
jsonMap.put("http.rtt.validate.us",50);
jsonMap.put("http.rtt.content.us",50);
jsonMap.put("http.rtt.write_request.us",50);
jsonMap.put("http.rtt.total.us",5000);
if (check.getState() == Entry.State.UP) {
jsonMap.put("http.response.status_code", 200);
} else {
if (check.getData() != null) {
jsonMap.put("error.type", "validate");
jsonMap.put("error.message", check.getData().getErrorMessage());
}
jsonMap.put("http.response.status_code", _outcome.getStatusCode().value());
}
With that approach I can see my entries in monitor status but have the follwing problems:
- Status is invalid
- Type and IP not shown