Impiego health check in index page!

This commit is contained in:
Samuele Locatelli
2021-06-25 11:52:01 +02:00
parent 07efca5614
commit eeedfbc398
8 changed files with 100 additions and 13 deletions
+5 -5
View File
@@ -75,12 +75,12 @@ namespace GWMS.Data
// tento setup da config
try
{
string server = _configuration["DbConfig:Server"];
string nKey = _configuration["DbConfig:nKey"];
string sKey = _configuration["DbConfig:sKey"];
//string server = _configuration["DbConfig:Server"];
//string nKey = _configuration["DbConfig:nKey"];
//string sKey = _configuration["DbConfig:sKey"];
DbConfig.InitDb(server, nKey, sKey);
DbConfig.CheckUser(nKey, sKey);
//DbConfig.InitDb(server, nKey, sKey);
//DbConfig.CheckUser(nKey, sKey);
// uso conn string calcolata
connString = DbConfig.CONNECTION_STRING;
+73
View File
@@ -11,6 +11,79 @@ namespace GWMS.UI.Health
{
#region Public Methods
public static async Task<HealthCheckResult> DbPlantLogTable(string connStringDb)
{
using (var appDb = new GWMS.Data.GWMSContext())
{
string description = "Try check Table PlantLog";
List<GWMS.Data.DatabaseModels.PlantLogModel> recordList = new List<GWMS.Data.DatabaseModels.PlantLogModel>();
var healthCheckData = new Dictionary<string, object>();
try
{
// provo a controllare se ho tab utenti
recordList = await Task.FromResult(appDb.DbSetPlantLog.ToList()).ConfigureAwait(false);
if (recordList.Count > 0)
{
description = $"Check PlantLog table, found {recordList.Count} records";
return HealthCheckResult.Healthy(description, healthCheckData);
}
}
catch
{ }
return HealthCheckResult.Unhealthy(description + $" {connStringDb}", null, healthCheckData);
}
}
public static async Task<HealthCheckResult> DbUserApp(string connStringDb)
{
using (var appDb = new GWMS.Data.GWMSContext())
{
string description = "Try check Table AppUser";
List<GWMS.Data.DatabaseModels.UserModel> userList = new List<GWMS.Data.DatabaseModels.UserModel>();
var healthCheckData = new Dictionary<string, object>();
try
{
// provo a controllare se ho tab utenti
userList = appDb.DbSetUser.ToList();
//userList = await Task.FromResult(appDb.DbSetUser.ToList()).ConfigureAwait(false);
if (userList.Count > 0)
{
description = $"Check AppUser table, found {userList.Count} records";
return HealthCheckResult.Healthy(description, healthCheckData);
}
}
catch
{ }
return HealthCheckResult.Unhealthy(description + $" {connStringDb}", null, healthCheckData);
}
}
public static async Task<HealthCheckResult> DbUserRoot(string connStringDb)
{
using (var adminDb = new GWMS.Data.AdminContext())
{
string description = "Try check MySql User table";
List<GWMS.Data.DatabaseModels.UserPriv> userList = new List<GWMS.Data.DatabaseModels.UserPriv>();
var healthCheckData = new Dictionary<string, object>();
try
{
// provo a controllare se ho tab utenti
userList = await Task.FromResult(adminDb.UserList.ToList()).ConfigureAwait(false);
if (userList.Count > 0)
{
description = $"Check MySql User table, found {userList.Count} records";
return HealthCheckResult.Healthy(description, healthCheckData);
}
}
catch
{ }
return HealthCheckResult.Unhealthy(description + $" {connStringDb}", null, healthCheckData);
}
}
public static async Task<HealthCheckResult> PingCheck(string hostName)
{
using (var thePing = new Ping())
+5 -1
View File
@@ -1,5 +1,6 @@
@page "/"
@using GWMS.Data
@using GWMS.UI.Data
@using GWMS.UI.Components
@@ -54,6 +55,9 @@
AppMService.ShowSearch = false;
AppMService.PageName = "Home";
AppMService.PageIcon = "fas fa-home pr-2";
DataOk = await DataService.HasPlantLog();
var resultUser = await Health.Checks.DbUserApp(DbConfig.CONNECTION_STRING);
var resultLog = await Health.Checks.DbPlantLogTable(DbConfig.CONNECTION_STRING);
DataOk = (resultUser.Status == HealthStatus.Healthy && resultLog.Status == HealthStatus.Healthy);
//DataOk = await DataService.HasPlantLog();
}
}
+13 -4
View File
@@ -106,12 +106,15 @@ namespace GWMS.UI
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// init DB
// init info x DB
string dbServerAddr = Configuration["DbConfig:Server"];
string nKey = Configuration["DbConfig:nKey"];
string sKey = Configuration["DbConfig:sKey"];
DbConfig.InitDb(dbServerAddr, nKey, sKey);
// inizializzo il DB e creo (se necessario) l'utente
DbConfig.CheckUser(nKey, sKey);
// altri parametri per check vari
string connStringDB = DbConfig.CONNECTION_STRING;
string connStringRedis = Configuration.GetConnectionString("Redis");
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
@@ -126,7 +129,11 @@ namespace GWMS.UI
.AddAsyncCheck($"QrCode PING ({qrCodeAddr})", () => Health.Checks.PingCheck(qrCodeAddr))
.AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded) // 512 MB max allocated memory
.AddRedis(Configuration.GetConnectionString("Redis"), "Redis", failureStatus: HealthStatus.Degraded)
.AddUrlGroup(new Uri(Configuration["ZCodeUrl"]), name: $"QrCode Gen ({Configuration["ZCodeUrl"]})", failureStatus: HealthStatus.Degraded);
.AddUrlGroup(new Uri(Configuration["ZCodeUrl"]), name: $"QrCode Gen ({Configuration["ZCodeUrl"]})", failureStatus: HealthStatus.Degraded)
.AddAsyncCheck($"MySql Root User", () => Health.Checks.DbUserRoot(DbConfig.ADMIN_CONNECTION_STRING))
.AddAsyncCheck($"MySql App Users", () => Health.Checks.DbUserApp(DbConfig.CONNECTION_STRING))
.AddAsyncCheck($"MySql PlantLog", () => Health.Checks.DbPlantLogTable(DbConfig.CONNECTION_STRING))
;
//.AddDiskStorageHealthCheck(s => s.AddDrive("C:\\", 1024)) // 1024 MB (1 GB) free minimum
//.AddProcessHealthCheck("ProcessName", p => p.Length > 0) // check if process is running
//.AddWindowsServiceHealthCheck("someservice", s => s.Status == ServiceControllerStatus.Running);
@@ -135,7 +142,9 @@ namespace GWMS.UI
.AddHealthChecksUI(s =>
{
s.AddHealthCheckEndpoint("GWMS_Services", "health");
s.SetEvaluationTimeInSeconds(5);
s.SetEvaluationTimeInSeconds(3);
//s.SetEvaluationTimeInSeconds(30);
s.SetMinimumSecondsBetweenFailureNotifications(60);
s.SetApiMaxActiveRequests(5);
s.SetHeaderText("GWMS Health Check Status");
})
+1
View File
@@ -5,6 +5,7 @@
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.Extensions.Diagnostics.HealthChecks
@using Microsoft.JSInterop
@using GWMS.UI
@using GWMS.UI.Shared
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 1.0.2106.2510</h4>
<h4>Versione: 1.0.2106.2511</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
1.0.2106.2510
1.0.2106.2511
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2106.2510</version>
<version>1.0.2106.2511</version>
<url>http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/GWMS.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>