// 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); }
public HealthCheckRepository() { _healthCheckModel = new HealthCheckModel() { LivenessCheck = true, ReadinessCheck = true }; }
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); }
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); }
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())); }
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)); }
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); }
// 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(); }
// 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); }
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); }
public void Set(HealthCheckModel healthCheckModel) { _healthCheckModel = healthCheckModel; }