@@ -0,0 +1,2746 @@
+package com.github.mustard.metrics.munin;%0A%0Aimport com.codahale.metrics.health.HealthCheck;%0Aimport com.codahale.metrics.health.HealthCheckRegistry;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0Aimport java.util.Map;%0Aimport java.util.SortedMap;%0Aimport java.util.concurrent.ExecutorService;%0A%0Apublic class MuninHealthCheckServlet extends HttpServlet %7B%0A%0A    private final transient HealthCheckRegistry registry;%0A    private final transient ExecutorService executorService;%0A%0A    public MuninHealthCheckServlet(HealthCheckRegistry registry) %7B%0A        this.registry = registry;%0A        this.executorService = null;%0A    %7D%0A%0A    public MuninHealthCheckServlet(HealthCheckRegistry registry, ExecutorService executorService) %7B%0A        this.registry = registry;%0A        this.executorService = executorService;%0A    %7D%0A%0A    @Override%0A    protected void doGet(HttpServletRequest req,%0A                         HttpServletResponse resp) throws ServletException, IOException %7B%0A%0A        resp.setContentType(%22text/plain%22);%0A        resp.setHeader(%22Cache-Control%22, %22must-revalidate,no-cache,no-store%22);%0A%0A        if (registry.getNames().isEmpty()) %7B%0A            resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);%0A        %7D else %7B%0A            if (req.getParameter(%22config%22) != null) %7B%0A                writeConfigBody(resp.getWriter(), registry);%0A            %7D else %7B%0A                writeFetchBody(resp.getWriter(), runHealthChecks());%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A    private void writeFetchBody(PrintWriter writer, SortedMap%3CString, HealthCheck.Result%3E results) %7B%0A        for (Map.Entry%3CString, HealthCheck.Result%3E check : results.entrySet()) %7B%0A            String sanitisedCheckName = sanitiseCheckName(check.getKey());%0A            writer.println(sanitisedCheckName + %22.value %22 + check.getValue().isHealthy());%0A        %7D%0A    %7D%0A%0A    private void writeConfigBody(PrintWriter writer, HealthCheckRegistry registry) %7B%0A        writer.println(%22graph_title Health Checks%22);%0A        writer.println(%22graph_vlabel Success%22);%0A        for (String checkName : registry.getNames()) %7B%0A            String sanitisedCheckName = sanitiseCheckName(checkName);%0A            writer.println(sanitisedCheckName + %22.label %22 + sanitisedCheckName);%0A        %7D%0A    %7D%0A%0A    private SortedMap%3CString, HealthCheck.Result%3E runHealthChecks() %7B%0A        if (executorService == null) %7B%0A            return registry.runHealthChecks();%0A        %7D%0A        return registry.runHealthChecks(executorService);%0A    %7D%0A%0A    private String sanitiseCheckName(String checkName) %7B%0A        return checkName.replaceAll(%22 %22, %22_%22);%0A    %7D%0A%0A%7D%0A

Add health check servlet