private static void WriteHealthStatus(HttpListenerContext context, Func <HealthStatus> healthStatus)
        {
            var status = healthStatus();
            var json   = JsonHealthChecks.BuildJson(status);

            var httpStatus            = status.IsHealthy ? 200 : 500;
            var httpStatusDescription = status.IsHealthy ? "OK" : "Internal Server Error";

            WriteString(context, json, JsonHealthChecks.HealthChecksMimeType, httpStatus, httpStatusDescription);
        }
示例#2
0
        private static MetricsEndpointResponse GetHealthResponse(Func <HealthStatus> healthStatus, bool alwaysReturnOkStatusCode)
        {
            var status = healthStatus();
            var json   = JsonHealthChecks.BuildJson(status);

            var httpStatus            = status.IsHealthy || alwaysReturnOkStatusCode ? 200 : 500;
            var httpStatusDescription = status.IsHealthy || alwaysReturnOkStatusCode ? "OK" : "Internal Server Error";

            return(new MetricsEndpointResponse(json, JsonHealthChecks.HealthChecksMimeType, Metric.CurrentEncoding, httpStatus, httpStatusDescription));
        }
示例#3
0
        public Task Invoke(HttpContext context)
        {
            if (_options.HealthEnabled && _options.HealthEndpoint.HasValue && _options.HealthEndpoint == context.Request.Path)
            {
                var healthStatus       = _metricsContext.HealthStatus();
                var responseStatusCode = healthStatus.IsHealthy ? HttpStatusCode.OK : HttpStatusCode.InternalServerError;
                return(WriteResponse(context, JsonHealthChecks.BuildJson(healthStatus), "application/json", responseStatusCode));
            }

            return(_next(context));
        }
        private static Task GetHealthStatus(IDictionary <string, object> environment, Func <HealthStatus> healthStatus)
        {
            var responseStatusCode = HttpStatusCode.OK;
            var status             = healthStatus();
            var content            = JsonHealthChecks.BuildJson(status);

            if (!status.IsHealthy)
            {
                responseStatusCode = HttpStatusCode.InternalServerError;
            }
            return(WriteResponse(environment, content, "application/json", responseStatusCode));
        }
        private static Task WriteHealthStatus(HttpListenerContext context, Func <HealthStatus> healthStatus)
        {
            var status = healthStatus();
            var json   = JsonHealthChecks.BuildJson(status);

            Task task = WriteString(context, json, JsonHealthChecks.HealthChecksMimeType);

            task.Wait();
            context.Response.StatusCode        = status.IsHealty ? 200 : 500;
            context.Response.StatusDescription = status.IsHealty ? "OK" : "Internal Server Error";
            return(task);
        }
示例#6
0
        private Response GetHealthStatus()
        {
            var status  = Config.HealthStatus();
            var content = JsonHealthChecks.BuildJson(status);

            var response = Response.AsText(content, "application/json");

            if (!healthChecksAlwaysReturnHttpStatusOk)
            {
                response.StatusCode = status.IsHealthy ? HttpStatusCode.OK : HttpStatusCode.InternalServerError;
            }
            else
            {
                response.StatusCode = HttpStatusCode.OK;
            }
            return(response);
        }