Exemple #1
0
        /// <summary>
        /// Runs through all registered HealthCheck instances and reports the results.
        /// Returns a `200 OK` if all succeeded, or a `500 Internal Server Error` if any failed.
        /// </summary>
        public ActionResult HealthCheck(string username, string password)
        {
            if (!IsAuthorized(username, password))
            {
                return(new HttpStatusCodeResult(401));
            }

            var health = HealthChecks.RunHealthChecks();

            ControllerContext.HttpContext.Response.StatusCode = health.Values.Count(v => v.IsHealthy) != health.Values.Count ? 500 : 200;

            Dictionary <MetricName, IMetric> healthAsMetrics = health.ToDictionary(
                kv => new MetricName("HealthCheck", kv.Key),
                kv => kv.Value as IMetric
                );

            var result = new ContentResult
            {
                Content         = Serializer.Serialize(healthAsMetrics),
                ContentType     = "application/json",
                ContentEncoding = Encoding.UTF8
            };

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Runs through all registered HealthCheck instances and reports the results.
        /// Returns a `200 OK` if all succeeded, or a `500 Internal Server Error` if any failed.
        /// </summary>
        public ActionResult HealthCheck(string username, string password)
        {
            if (!IsAuthorized(username, password))
            {
                return(new HttpStatusCodeResult(401));
            }

            var health = HealthChecks.RunHealthChecks();

            ControllerContext.HttpContext.Response.StatusCode = health.Values.Count(v => v.IsHealthy) != health.Values.Count ? 500 : 200;

            var result = new ContentResult
            {
                Content         = Serializer.Serialize(health),
                ContentType     = "application/json",
                ContentEncoding = Encoding.UTF8
            };

            return(result);
        }