// GET: api/HealthCheck
        public string Get()
        {
            try
            {
                var client      = new RestClient(ESAPHealthURL + AppInfo);
                var request     = new RestRequest("", Method.GET);
                var queryResult = client.Execute(request);

                List <appinfo> Apps = JsonConvert.DeserializeObject <List <appinfo> >(queryResult.Content);

                foreach (appinfo app in Apps)
                {
                    filewriter.writelog(app.AppName + ": Checking Service");

                    DeleteObject deleteme = new DeleteObject();

                    deleteme.AppName = app.AppName;
                    deleteme.AppUrl  = app.AppURL;

                    HealthCheckModel appstatus = Post(deleteme);
                }
            }
            catch (Exception error)
            {
                return(error.Message);
            }

            return("DONE");
        }
        // POST: api/HealthCheck
        public HealthCheckModel Post([FromBody] DeleteObject deleteme)
        {
            string res = "";

            HealthCheckModel        hcm       = new HealthCheckModel();
            List <HealthCheckModel> returnval = new List <HealthCheckModel>();

            var client      = new RestClient(deleteme.AppUrl);
            var request     = new RestRequest("", Method.GET);
            var queryResult = client.Execute(request);

            hcm.AppName   = deleteme.AppName;
            hcm.AppUrl    = deleteme.AppUrl;
            hcm.TimeStamp = DateTime.Now;

            hcm.Status = queryResult.StatusCode.ToString();

            if (queryResult.StatusCode == 0)
            {
                hcm.Status = HttpStatusCode.ServiceUnavailable.ToString();
            }

            if (JSONHelper.IsValidJson(queryResult.Content))
            {
                hcm.Message = queryResult.Content;
            }

            ElasticSearch.LogHealthMetric(hcm);

            return(hcm);
        }
コード例 #3
0
 public HealthCheckRepository()
 {
     _healthCheckModel = new HealthCheckModel()
     {
         LivenessCheck  = true,
         ReadinessCheck = true
     };
 }
コード例 #4
0
        public ContentResult HealthCheck()
        {
            var model = new HealthCheckModel();

            return(new ContentResult
            {
                Content = JsonConvert.SerializeObject(model),
                ContentType = "application/json"
            });
        }
        // GET: api/HeartBeat
        public HealthCheckModel Get()
        {
            HealthCheckModel hcm = new HealthCheckModel();

            hcm.AppName   = "ElasticSearchFacade";
            hcm.AppUrl    = "http://dev.michaeldigiacomi.com/IC2016/ESAppHealth/Help";
            hcm.Status    = "200";
            hcm.Message   = "Application Online";
            hcm.TimeStamp = DateTime.Now;

            return(hcm);
        }
コード例 #6
0
        public static IEnumerable <BulkResponseItemBase> LogHealthMetric(HealthCheckModel hcm)
        {
            var node     = new Uri(ConfigurationManager.AppSettings["ElasticSearchURL"]);
            var settings = new ConnectionSettings(node).RequestTimeout(TimeSpan.FromSeconds(60));
            var client   = new ElasticClient(settings);

            List <HealthCheckModel> HeartBeats = new List <HealthCheckModel>();

            HeartBeats.Add(hcm);

            var result = client.IndexMany <HealthCheckModel>(HeartBeats, "healthcheck", null);

            return(result.ItemsWithErrors);
        }
コード例 #7
0
        public async Task <ActionResult> Post([FromBody] HealthCheckModel healthCheckModel)
        {
            _healthCheckRepository.Set(healthCheckModel);

            if (healthCheckModel.Shutdown)
            {
                await _webhookHandler.InvokeAsync(
                    WebhookEvents.Shutdown,
                    _healthCheckRepository.Get());

                // Exit this process with failure code
                Environment.Exit(123);
            }

            return(Ok(_healthCheckRepository.Get()));
        }
コード例 #8
0
        public IActionResult HealthCheck()
        {
            var process = Process.GetCurrentProcess();
            var result  = new HealthCheckModel()
            {
                OSDescription      = $"{RuntimeInformation.OSDescription} ({RuntimeInformation.OSArchitecture})",
                RuntimeVersion     = RuntimeInformation.FrameworkDescription,
                IsContainerized    = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") is object?true : false,
                CPUCores           = Environment.ProcessorCount,
                MemoryCurrentUsage = process.WorkingSet64,
                MemoryMaxAvailable = (long)process.MaxWorkingSet,
                CGroupMemoryUsage  = (RuntimeInformation.OSDescription.StartsWith("Linux") && Directory.Exists("/sys/fs/cgroup/memory")) ?
                                     System.IO.File.ReadAllLines("/sys/fs/cgroup/memory/memory.usage_in_bytes")[0] : string.Empty
            };

            return(new JsonResult(result));
        }
コード例 #9
0
        public HealthCheckModel HealthCheck()
        {
            var hcm = new HealthCheckModel()
            {
                Version    = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(InventoryController).Assembly.Location).ProductVersion,
                Running    = true,
                Components = new List <ComponentCheckModel>()
                {
                    new ComponentCheckModel()
                    {
                        ComponentName = "TEST",
                        Status        = ComponentStatus.Running,
                        Message       = ""
                    }
                }
            };

            return(hcm);
        }
コード例 #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Following lines can throw if configuration is not correctly set.
            // This correctly prevents container from starting in error scenario.
            // Might throw->
            var healthCheckModel = new HealthCheckModel()
            {
                LivenessCheck  = Configuration.GetValue <bool>("livenessCheck"),
                ReadinessCheck = Configuration.GetValue <bool>("readinessCheck")
            };

            IHealthCheckRepository healthCheckRepository = new HealthCheckRepository();
            IWebhookHandler        webhookHandler        = new WebhookHandler(Configuration["webhook"]);

            webhookHandler.InvokeAsync(WebhookEvents.AppStarted, healthCheckRepository.Get()).Wait();
            // <-Might throw

            services.AddSingleton(webhookHandler);
            services.AddSingleton(healthCheckRepository);

            services.AddSingleton <Microsoft.Extensions.Hosting.IHostedService, BackgroundReportingService>();
            services.AddMvc();
        }
コード例 #11
0
        // GET: api/HealthCheck
        public HealthCheckModel Get()
        {
            bool dbStatus = true;

            try
            {
                OAuthDbContext dbContext = new OAuthDbContext("MobileOAuth");
                dbContext.Database.Connection.Open();
                dbContext.Database.Connection.Close();
            }
            catch (SqlException)
            {
                dbStatus = false;
            }

            var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            HealthCheckModel healthCheckModel = new HealthCheckModel()
            {
                Version         = version.ToString(),
                ConnectDBStatus = dbStatus
            };

            return(healthCheckModel);
        }
コード例 #12
0
 public async Task InvokeAsync(string invokeEvent, HealthCheckModel healthCheckModel)
 {
     var json    = JsonConvert.SerializeObject(healthCheckModel);
     var content = new StringContent(json, Encoding.UTF8, JsonMediaTypeFormatter.DefaultMediaType.MediaType);
     await _client.PostAsync($"?invoke={invokeEvent}", content);
 }
コード例 #13
0
 public void Set(HealthCheckModel healthCheckModel)
 {
     _healthCheckModel = healthCheckModel;
 }