Class AppConfig
- Namespace
- AppHealthMonitor
- Assembly
- AppHealthMonitor.dll
Represents the configuration for a single application to be monitored. This structure mirrors the expected JSON configuration in appsettings.json.
public class AppConfig
- Inheritance
-
AppConfig
- Inherited Members
Properties
ApplicationExePath
Gets or sets the full path to the executable. Supports both Windows and Unix-style paths.
public string ApplicationExePath { get; set; }
Property Value
CheckIntervalSeconds
Gets or sets how often to perform health checks in seconds.
public int CheckIntervalSeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 5.
CircuitBreakerFailureThreshold
Gets or sets the consecutive failures required to trip the circuit breaker.
public int CircuitBreakerFailureThreshold { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
CpuThresholdPercent
Gets or sets the CPU usage threshold percentage for restart (0 for no limit). Note: CPU usage is calculated using ProcessorCount, which returns logical cores (including hyperthreaded cores on Intel/AMD CPUs).
public int CpuThresholdPercent { get; set; }
Property Value
ForceKillTimeoutSeconds
Gets or sets the timeout in seconds to wait for a force-killed process to exit.
public int ForceKillTimeoutSeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
GracefulShutdownTimeoutSeconds
Gets or sets the timeout for graceful shutdown in seconds.
public int GracefulShutdownTimeoutSeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
HealthCheckHost
Gets or sets the host address used for port health checks. Change to match the interface your application binds to. Defaults to "127.0.0.1" if not specified.
public string HealthCheckHost { get; set; }
Property Value
InitialHealthCheckDelaySeconds
Gets or sets the delay in seconds before the first full health check after launch. Allows the application time to fully initialize before being evaluated.
public int InitialHealthCheckDelaySeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
InitialRestartDelaySeconds
Gets or sets the initial delay for backoff restart in seconds.
public int InitialRestartDelaySeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
LaunchArguments
Gets or sets the optional command-line arguments for launching the application.
public string LaunchArguments { get; set; }
Property Value
LaunchDelaySeconds
Gets or sets the delay in seconds to wait after launching this application's monitor before launching the next one. Applied to the current application's config, not the next one. For example, setting this to 10 on App A means "wait 10s after A before launching B". Set to 0 for no delay. Not applied to the last application in the list.
public int LaunchDelaySeconds { get; set; }
Property Value
MaxRestartAttempts
Gets or sets the maximum attempts for backoff restart before giving up.
public int MaxRestartAttempts { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
MaxRestartDelaySeconds
Gets or sets the maximum delay for backoff restart in seconds.
public int MaxRestartDelaySeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
MemoryThresholdMB
Gets or sets the memory usage threshold for restart in megabytes (0 for no limit).
public int MemoryThresholdMB { get; set; }
Property Value
MonitoredPort
Gets or sets the port to monitor. Set to 0 for process-only monitoring.
public int MonitoredPort { get; set; }
Property Value
Name
Gets or sets the friendly name for the application.
public string Name { get; set; }
Property Value
PortCheckTimeoutMs
Gets or sets the timeout in milliseconds for TCP and UDP port health checks.
public int PortCheckTimeoutMs { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
PortTypes
Gets or sets the types of ports to monitor (e.g., TCP, UDP, WebSocket). An empty list indicates process-only monitoring with no port checks.
public List<PortType> PortTypes { get; set; }
Property Value
PostLaunchSettleDelaySeconds
Gets or sets the delay in seconds to wait after launching or restarting the application before resuming health checks. Allows the process to settle.
public int PostLaunchSettleDelaySeconds { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
ResourceCheckFailureThreshold
Gets or sets the number of consecutive CPU/memory check failures tolerated before triggering a restart. Prevents transient access errors (e.g., brief /proc access denial) from causing unnecessary restarts. Set to 1 for immediate restart on the first failure.
public int ResourceCheckFailureThreshold { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
WebSocketCheckTimeoutMs
Gets or sets the timeout in milliseconds for WebSocket port health checks. WebSocket connections typically require more time due to the upgrade handshake.
public int WebSocketCheckTimeoutMs { get; set; }
Property Value
Remarks
Minimum enforced value: 1.
Methods
TryApplyDefaultsAndValidate(out string)
Applies sensible defaults and validates the configuration in a single step. Ensures the configuration is ready for use without requiring separate calls.
public bool TryApplyDefaultsAndValidate(out string error)
Parameters
errorstringWhen validation fails, contains the error description.
Returns
- bool
True if the configuration is valid after applying defaults; otherwise, false.