Completato check conteggio record DB
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>WebDoorCreator - Egalware</i>
|
||||
<h4>Version: 0.9.2404.2316</h4>
|
||||
<h4>Version: 0.9.2404.2317</h4>
|
||||
<br /> Release note:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.9.2404.2316
|
||||
0.9.2404.2317
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>0.9.2404.2316</version>
|
||||
<version>0.9.2404.2317</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -1,106 +1,76 @@
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using NLog;
|
||||
using System.Net.NetworkInformation;
|
||||
using WebDoorCreator.Data;
|
||||
using WebDoorCreator.UI.Components.Users;
|
||||
|
||||
namespace WebDoorCreator.UI.Health
|
||||
{
|
||||
public class Checks
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static async Task<HealthCheckResult> DbIdentity(string dbName)
|
||||
public static async Task<HealthCheckResult> ConfigCount(IConfiguration _config)
|
||||
{
|
||||
string description = "Try check Table IdentityUsers";
|
||||
string description = "Try check Config table";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
#if false
|
||||
using (var appDb = new UserIdentityDbContext())
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_config))
|
||||
{
|
||||
List<TableCount> recordList = new List<TableCount>();
|
||||
try
|
||||
var dbCount = localDbCtx
|
||||
.DbSetConfig
|
||||
.Count();
|
||||
if (dbCount > 0)
|
||||
{
|
||||
string sqlQuery = $"SELECT 'AspNetUsers' AS TableName, COUNT(*) AS Count FROM information_schema.tables WHERE table_schema = '{dbName}' AND table_name = 'AspNetUsers' LIMIT 1;";
|
||||
var table = await Task.FromResult(appDb.DbSetCounts.FromSqlRaw(sqlQuery).ToList());
|
||||
|
||||
// provo a controllare se ho tab utenti
|
||||
if (table != null && table.Count > 0)
|
||||
{
|
||||
// controllo valore
|
||||
if (table[0].Count > 0)
|
||||
{
|
||||
description = $"Check IdentityUsers table, found!";
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore in esecuzione DbIdentity");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return HealthCheckResult.Degraded(description + $" {dbName}", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> DbPlantTable(string dbName)
|
||||
{
|
||||
string description = "Try check Table PlantLog";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
#if false
|
||||
using (var appDb = new GWMSContext())
|
||||
{
|
||||
List<GWMS.Data.DatabaseModels.PlantDetailModel> recordList = new List<GWMS.Data.DatabaseModels.PlantDetailModel>();
|
||||
try
|
||||
{
|
||||
// provo a controllare se ho tab utenti
|
||||
recordList = await Task.FromResult(appDb.DbSetPlant.ToList()).ConfigureAwait(false);
|
||||
if (recordList.Count > 0)
|
||||
{
|
||||
description = $"Check PlantDetail table, found {recordList.Count} records";
|
||||
description = $"Check Config table, found {dbCount} records";
|
||||
healthCheckData.Add("Count", dbCount);
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore in esecuzione PlantDetail Table");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return HealthCheckResult.Degraded(description + $" {dbName}", null, healthCheckData);
|
||||
|
||||
await Task.Delay(1);
|
||||
return HealthCheckResult.Unhealthy(description + $" NO RECORD found", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> DbUserRoot(string dbName)
|
||||
public static async Task<HealthCheckResult> DoorsCount(IConfiguration _config)
|
||||
{
|
||||
string description = "Try check MySql User table";
|
||||
string description = "Try check DOOR table";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
#if false
|
||||
using (var adminDb = new AdminContext())
|
||||
{
|
||||
List<GWMS.Data.DatabaseModels.UserPriv> userList = new List<GWMS.Data.DatabaseModels.UserPriv>();
|
||||
try
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_config))
|
||||
{
|
||||
// provo a controllare se ho tab utenti
|
||||
userList = await Task.FromResult(adminDb.UserList.ToList()).ConfigureAwait(false);
|
||||
if (userList.Count > 0)
|
||||
var dbCount = localDbCtx
|
||||
.DbSetDoor
|
||||
.Count();
|
||||
if (dbCount > 0)
|
||||
{
|
||||
description = $"Check MySql User table, found {userList.Count} records";
|
||||
description = $"Check DOOR table, found {dbCount} records";
|
||||
healthCheckData.Add("Count", dbCount);
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore in esecuzione DbUserRoot");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return HealthCheckResult.Unhealthy(description + $" {dbName}", null, healthCheckData);
|
||||
await Task.Delay(1);
|
||||
return HealthCheckResult.Unhealthy(description + $" NO RECORD found", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> OrdersCount(IConfiguration _config)
|
||||
{
|
||||
string description = "Try check ORDER table";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_config))
|
||||
{
|
||||
var dbCount = localDbCtx
|
||||
.DbSetOrders
|
||||
.Count();
|
||||
if (dbCount > 0)
|
||||
{
|
||||
description = $"Check ORDER table, found {dbCount} records";
|
||||
healthCheckData.Add("Count", dbCount);
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(1);
|
||||
return HealthCheckResult.Unhealthy(description + $" NO RECORD found", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> PingCheck(string hostName)
|
||||
@@ -117,11 +87,16 @@ namespace WebDoorCreator.UI.Health
|
||||
description += $" - {pingResult.RoundtripTime}ms";
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
|
||||
}
|
||||
return HealthCheckResult.Unhealthy(description + $" {hostName}", null, healthCheckData);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
Microsoft.Extensions.Configuration.ConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
// AspNetCore Identity setup
|
||||
var connectionString = builder.Configuration.GetConnectionString("Identity.DB");
|
||||
var connectionString = configuration.GetConnectionString("Identity.DB");
|
||||
|
||||
// REDIS setup
|
||||
string connStringRedis = configuration.GetConnectionString("Redis");
|
||||
@@ -62,14 +62,15 @@ if (connectionString.Contains("Server"))
|
||||
}
|
||||
// healthchecks
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddSqlServer(connectionString, healthQuery: "SELECT 1;", name: "sql", failureStatus: HealthStatus.Degraded, tags: new string[] { "DB", "MsSql" })
|
||||
.AddSqlServer(connectionString, healthQuery: "SELECT 1;", name: "SqlServer", failureStatus: HealthStatus.Degraded, tags: new string[] { "DB", "MsSql" })
|
||||
.AddAsyncCheck($"DB PING ({dbServerAddr})", () => WebDoorCreator.UI.Health.Checks.PingCheck(dbServerAddr))
|
||||
.AddAsyncCheck($"Redis PING ({redisSrvAddr})", () => WebDoorCreator.UI.Health.Checks.PingCheck(redisSrvAddr))
|
||||
//.AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded) // 512 MB max allocated memory
|
||||
// 512 MB max allocated memory
|
||||
.AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded)
|
||||
.AddRedis(connStringRedis, "Redis", failureStatus: HealthStatus.Degraded)
|
||||
//.AddAsyncCheck($"MsSql Root User", () => WebDoorCreator.UI.Health.Checks.DbUserRoot("MsSql"))
|
||||
//.AddAsyncCheck($"MsSql Identity", () => WebDoorCreator.UI.Health.Checks.DbIdentity(DbConfig.DATABASE_NAME))
|
||||
//.AddAsyncCheck($"MsSql PlantLog", () => WebDoorCreator.UI.Health.Checks.DbPlantTable(DbConfig.DATABASE_NAME))
|
||||
.AddAsyncCheck($"Config Table", () => WebDoorCreator.UI.Health.Checks.ConfigCount(configuration))
|
||||
.AddAsyncCheck($"Orders Table", () => WebDoorCreator.UI.Health.Checks.OrdersCount(configuration))
|
||||
.AddAsyncCheck($"Doors Table", () => WebDoorCreator.UI.Health.Checks.DoorsCount(configuration))
|
||||
;
|
||||
|
||||
builder.Services
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.9.2404.2316</Version>
|
||||
<Version>0.9.2404.2317</Version>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
@@ -39,6 +39,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Redis" Version="6.0.4" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.System" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="6.0.5" />
|
||||
|
||||
Reference in New Issue
Block a user