public static HealthCheckBuilder AddAzureFileStorageCheck(HealthCheckBuilder builder, CloudStorageAccount storageAccount, string shareName = null) { builder.AddCheck($"AzureFileStorageCheck {storageAccount.FileStorageUri} {shareName}", async() => { bool result; try { var fileClient = storageAccount.CreateCloudFileClient(); var properties = await fileClient.GetServicePropertiesAsync(); if (!String.IsNullOrWhiteSpace(shareName)) { var share = fileClient.GetShareReference(shareName); result = await share.ExistsAsync(); } result = true; } catch (Exception) { result = false; } return(result ? HealthCheckResult.Healthy($"AzureFileStorage {storageAccount.BlobStorageUri} is available") : HealthCheckResult.Unhealthy($"AzureFileStorage {storageAccount.BlobStorageUri} is unavailable")); }); return(builder); }
//TODO: Move this into a seperate project. Avoid DB dependencies in the main lib. //TODO: It is probably better if this is more generic, not SQL specific. public static HealthCheckBuilder AddSqlCheck(this HealthCheckBuilder builder, string connectionString) { builder.AddCheck($"SQL Check:", async() => { try { //TODO: There is probably a much better way to do this. using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT 1"; var result = (int)await command.ExecuteScalarAsync(); if (result == 1) { return(HealthCheckResult.Healthy($"AddSqlCheck: {connectionString}")); } return(HealthCheckResult.Unhealthy($"AddSqlCheck: {connectionString}")); } } } catch { return(HealthCheckResult.Unhealthy($"AddSqlCheck: {connectionString}")); } }); return(builder); }
public static HealthCheckBuilder AddAzureFileStorageCheck(this HealthCheckBuilder builder, string accountName, string accountKey, string shareName = null) { var credentials = new StorageCredentials(accountName, accountKey); var storageAccount = new CloudStorageAccount(credentials, true); return(AddAzureFileStorageCheck(builder, storageAccount, shareName)); }
public static HealthCheckBuilder AddUrlCheck(this HealthCheckBuilder builder, string url) { builder.AddCheck($"UrlCheck ({url})", async() => { var httpClient = new HttpClient(); var response = await httpClient.GetAsync(url); return(response.StatusCode == HttpStatusCode.OK); }); return(builder); }
public static HealthCheckBuilder AddUrlCheck(this HealthCheckBuilder builder, string url, Func <HttpResponseMessage, bool> checkFunc) { builder.AddCheck($"UrlCheck ({url})", async() => { var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("cache-control", "no-cache"); var response = await httpClient.GetAsync(url); return(checkFunc(response)); }); return(builder); }
public static HealthCheckBuilder AddWorkingSetCheck(this HealthCheckBuilder builder, long maxSize) { builder.AddCheck($"WorkingSet64 ({maxSize})", () => { if (Process.GetCurrentProcess().WorkingSet64 <= maxSize) { return(HealthCheckResult.Healthy($"AddWorkingSetCheck, maxSize: {maxSize}")); } return(HealthCheckResult.Unhealthy($"AddWorkingSetCheck, maxSize: {maxSize}")); }); return(builder); }
public static HealthCheckBuilder AddVirtualMemorySizeCheck(this HealthCheckBuilder builder, long maxSize) { builder.AddCheck($"VirtualMemorySize ({maxSize})", () => { if (Process.GetCurrentProcess().VirtualMemorySize64 <= maxSize) { return(HealthCheckResult.Healthy($"AddVirtualMemorySizeCheck, maxSize: {maxSize}")); } return(HealthCheckResult.Unhealthy($"AddVirtualMemorySizeCheck, maxSize: {maxSize}")); }); return(builder); }
public static HealthCheckBuilder AddPrivateMemorySizeCheck(this HealthCheckBuilder builder, long maxSize) { builder.AddCheck($"PrivateMemorySize64 ({maxSize})", () => { if (Process.GetCurrentProcess().PrivateMemorySize64 <= maxSize) { return(true); } return(false); }); return(builder); }
public static HealthCheckBuilder AddWorkingSetCheck(this HealthCheckBuilder builder, long maxSize) { builder.AddCheck($"WorkingSet64 ({maxSize})", () => { if (Process.GetCurrentProcess().WorkingSet64 <= maxSize) { return(true); } return(false); }); return(builder); }
public static HealthCheckBuilder AddUrlCheck(this HealthCheckBuilder builder, string url) { builder.AddCheck($"UrlCheck ({url})", async() => { var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("cache-control", "no-cache"); var response = await httpClient.GetAsync(url); if (response.StatusCode == HttpStatusCode.OK) { return(HealthCheckResult.Healthy($"UrlCheck: {url}")); } ; return(HealthCheckResult.Unhealthy($"UrlCheck: {url}")); }); return(builder); }
public static HealthCheckBuilder AddUrlChecks(this HealthCheckBuilder builder, IEnumerable <string> urlItems, string group) { var urls = urlItems.ToList(); builder.AddCheck($"UrlChecks ({group})", async() => { var successfulChecks = 0; var description = new StringBuilder(); var httpClient = new HttpClient(); foreach (var url in urlItems) { try { httpClient.DefaultRequestHeaders.Add("cache-control", "no-cache"); var response = await httpClient.GetAsync(url); if (response.StatusCode == HttpStatusCode.OK) { successfulChecks++; description.Append($"UrlCheck SUCCESS ({url}) "); } else { description.Append($"UrlCheck FAILED ({url}) "); } } catch { description.Append($"UrlCheck FAILED ({url}) "); } } if (successfulChecks == urls.Count) { return(HealthCheckResult.Healthy(description.ToString())); } else if (successfulChecks > 0) { return(HealthCheckResult.Warning(description.ToString())); } return(HealthCheckResult.Unhealthy(description.ToString())); }); return(builder); }
public HealthCheckService(HealthCheckBuilder builder, ILogger <HealthCheckService> logger) { _checks = builder.Checks; _logger = logger; }