Implement LmxOpcUa server — all 6 phases complete
Full OPC UA server on .NET Framework 4.8 (x86) exposing AVEVA System Platform Galaxy tags via MXAccess. Mirrors Galaxy object hierarchy as OPC UA address space, translating contained-name browse paths to tag-name runtime references. Components implemented: - Configuration: AppConfiguration with 4 sections, validator - Domain: ConnectionState, Quality, Vtq, MxDataTypeMapper, error codes - MxAccess: StaComThread, MxAccessClient (partial classes), MxProxyAdapter using strongly-typed ArchestrA.MxAccess COM interop - Galaxy Repository: SQL queries (hierarchy, attributes, change detection), ChangeDetectionService with auto-rebuild on deploy - OPC UA Server: LmxNodeManager (CustomNodeManager2), LmxOpcUaServer, OpcUaServerHost with programmatic config, SecurityPolicy None - Status Dashboard: HTTP server with HTML/JSON/health endpoints - Integration: Full 14-step startup, graceful shutdown, component wiring 175 tests (174 unit + 1 integration), all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
57
src/ZB.MOM.WW.LmxOpcUa.Host/Status/HealthCheckService.cs
Normal file
57
src/ZB.MOM.WW.LmxOpcUa.Host/Status/HealthCheckService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Metrics;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Host.Status
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines health status based on connection state and operation success rates. (DASH-003)
|
||||
/// </summary>
|
||||
public class HealthCheckService
|
||||
{
|
||||
public HealthInfo CheckHealth(ConnectionState connectionState, PerformanceMetrics? metrics)
|
||||
{
|
||||
// Rule 1: Not connected → Unhealthy
|
||||
if (connectionState != ConnectionState.Connected)
|
||||
{
|
||||
return new HealthInfo
|
||||
{
|
||||
Status = "Unhealthy",
|
||||
Message = $"MXAccess not connected (state: {connectionState})",
|
||||
Color = "red"
|
||||
};
|
||||
}
|
||||
|
||||
// Rule 2: Success rate < 50% with > 100 ops → Degraded
|
||||
if (metrics != null)
|
||||
{
|
||||
var stats = metrics.GetStatistics();
|
||||
foreach (var kvp in stats)
|
||||
{
|
||||
if (kvp.Value.TotalCount > 100 && kvp.Value.SuccessRate < 0.5)
|
||||
{
|
||||
return new HealthInfo
|
||||
{
|
||||
Status = "Degraded",
|
||||
Message = $"{kvp.Key} success rate is {kvp.Value.SuccessRate:P0} ({kvp.Value.TotalCount} ops)",
|
||||
Color = "yellow"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rule 3: All good
|
||||
return new HealthInfo
|
||||
{
|
||||
Status = "Healthy",
|
||||
Message = "All systems operational",
|
||||
Color = "green"
|
||||
};
|
||||
}
|
||||
|
||||
public bool IsHealthy(ConnectionState connectionState, PerformanceMetrics? metrics)
|
||||
{
|
||||
var health = CheckHealth(connectionState, metrics);
|
||||
return health.Status != "Unhealthy";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user