Files
ThreadPilot/Services/IServiceHealthMonitor.cs
T

96 lines
3.1 KiB
C#

/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ThreadPilot.Services
{
/// <summary>
/// Service health status enumeration
/// </summary>
public enum ServiceHealthStatus
{
Healthy,
Degraded,
Unhealthy,
Critical
}
/// <summary>
/// Service health check result
/// </summary>
public class ServiceHealthResult
{
public string ServiceName { get; set; } = string.Empty;
public ServiceHealthStatus Status { get; set; }
public string Description { get; set; } = string.Empty;
public TimeSpan ResponseTime { get; set; }
public DateTime CheckTime { get; set; }
public Exception? Exception { get; set; }
public Dictionary<string, object> Data { get; set; } = new();
}
/// <summary>
/// Interface for monitoring service health and lifecycle
/// </summary>
public interface IServiceHealthMonitor
{
/// <summary>
/// Register a service for health monitoring
/// </summary>
void RegisterService(string serviceName, Func<Task<ServiceHealthResult>> healthCheck);
/// <summary>
/// Unregister a service from health monitoring
/// </summary>
void UnregisterService(string serviceName);
/// <summary>
/// Perform health check on a specific service
/// </summary>
Task<ServiceHealthResult> CheckServiceHealthAsync(string serviceName);
/// <summary>
/// Perform health check on all registered services
/// </summary>
Task<Dictionary<string, ServiceHealthResult>> CheckAllServicesHealthAsync();
/// <summary>
/// Get the current health status of all services
/// </summary>
Dictionary<string, ServiceHealthResult> GetCurrentHealthStatus();
/// <summary>
/// Event raised when a service health status changes
/// </summary>
event EventHandler<ServiceHealthChangedEventArgs>? ServiceHealthChanged;
}
/// <summary>
/// Event arguments for service health changes
/// </summary>
public class ServiceHealthChangedEventArgs : EventArgs
{
public string ServiceName { get; set; } = string.Empty;
public ServiceHealthStatus PreviousStatus { get; set; }
public ServiceHealthStatus CurrentStatus { get; set; }
public ServiceHealthResult HealthResult { get; set; } = new();
}
}