Custom heartbeat shipper

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("", "heartbeat");
            jsonMap.put("beat.hostname", "heartbeat");
            jsonMap.put("beat.version", "6.7.0");

            jsonMap.put("", "heartbeat");
            jsonMap.put("tcp.port", 9090);

            jsonMap.put("", check.getName());
            jsonMap.put("monitor.status", check.getState().name().toLowerCase());
            jsonMap.put("", "http");
            jsonMap.put("monitor.type", "http");
            jsonMap.put("monitor.scheme", "http");
            jsonMap.put("monitor.ip", "");
            jsonMap.put("http.url", "");

            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:

  1. Status is invalid
  2. Type and IP not shown

So I find the solution myself. My mistake was to use the jsonmap in wrong way.

It works like a charm if I use XContentBuilder builder = XContentFactory.jsonBuilder();

Thank you for updating us with the solution


This topic was automatically closed 24 days after the last reply. New replies are no longer allowed.