use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.
the class HealthCheckManagerImpl method getHealthCheckResponse.
@Override
public HttpResponse getHealthCheckResponse(ChannelHandlerContext ctx, @Nonnull FullHttpRequest request) throws URISyntaxException {
int port = ((InetSocketAddress) ctx.channel().localAddress()).getPort();
if (!enabledPorts.contains(port))
return null;
URI uri = new URI(request.uri());
if (!(this.path == null || this.path.equals(uri.getPath())))
return null;
// it is a health check URL, now we need to determine current status and respond accordingly
final boolean ok = isHealthy(port);
Metrics.newGauge(new TaggedMetricName("listeners", "healthcheck.status", "port", String.valueOf(port)), new Gauge<Integer>() {
@Override
public Integer value() {
return isHealthy(port) ? 1 : 0;
}
});
final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(ok ? passStatusCode : failStatusCode), Unpooled.copiedBuffer(ok ? passResponseBody : failResponseBody, CharsetUtil.UTF_8));
if (contentType != null) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
}
if (HttpUtil.isKeepAlive(request)) {
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
Metrics.newCounter(new TaggedMetricName("listeners", "healthcheck.httpstatus." + (ok ? passStatusCode : failStatusCode) + ".count", "port", String.valueOf(port))).inc();
return response;
}
Aggregations