feat(core): add host, alert, and metrics domain models
This commit is contained in:
1 parent
ed9ed5ce66
commit
7160b0bbdd
5 files changed
+131
No files matched your search
@@ -0,0 +1,23 @@
|
||||
namespace Vantage.Core.Models;
|
||||
|
||||
public enum ContainerState
|
||||
{
|
||||
Running,
|
||||
Exited,
|
||||
Paused,
|
||||
Restarting,
|
||||
Created,
|
||||
Dead,
|
||||
Other
|
||||
}
|
||||
|
||||
public sealed record DockerContainer
|
||||
{
|
||||
public string Id { get; init; } = "";
|
||||
public string Name { get; init; } = "";
|
||||
public string Image { get; init; } = "";
|
||||
public ContainerState State { get; init; } = ContainerState.Other;
|
||||
public string StatusText { get; init; } = "";
|
||||
|
||||
public bool IsRunning => State == ContainerState.Running;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
namespace Vantage.Core.Models;
|
||||
|
||||
public enum HealthKind
|
||||
{
|
||||
Http,
|
||||
Tcp
|
||||
}
|
||||
|
||||
public enum HealthStatus
|
||||
{
|
||||
Unknown,
|
||||
Up,
|
||||
Degraded,
|
||||
Down
|
||||
}
|
||||
|
||||
public sealed class HealthCheckConfig
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString("N");
|
||||
public string Name { get; set; } = "";
|
||||
public HealthKind Kind { get; set; } = HealthKind.Http;
|
||||
public string Target { get; set; } = "";
|
||||
public int TimeoutMs { get; set; } = 5000;
|
||||
public int ExpectedStatusMin { get; set; } = 200;
|
||||
public int ExpectedStatusMax { get; set; } = 399;
|
||||
}
|
||||
|
||||
public sealed record HealthCheckResult
|
||||
{
|
||||
public HealthStatus Status { get; init; } = HealthStatus.Unknown;
|
||||
public double? LatencyMs { get; init; }
|
||||
public string Message { get; init; } = "";
|
||||
public DateTimeOffset CheckedAt { get; init; } = DateTimeOffset.UtcNow;
|
||||
|
||||
public static HealthCheckResult Up(double latencyMs, string message) =>
|
||||
new() { Status = HealthStatus.Up, LatencyMs = latencyMs, Message = message };
|
||||
|
||||
public static HealthCheckResult Degraded(double latencyMs, string message) =>
|
||||
new() { Status = HealthStatus.Degraded, LatencyMs = latencyMs, Message = message };
|
||||
|
||||
public static HealthCheckResult Down(string message) =>
|
||||
new() { Status = HealthStatus.Down, Message = message };
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Vantage.Core.Models;
|
||||
|
||||
public enum SshAuthMethod
|
||||
{
|
||||
PrivateKey,
|
||||
Password,
|
||||
Agent
|
||||
}
|
||||
|
||||
public sealed class HostConfig
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString("N");
|
||||
public string Name { get; set; } = "";
|
||||
public string Address { get; set; } = "";
|
||||
public int Port { get; set; } = 22;
|
||||
public string Username { get; set; } = "";
|
||||
public SshAuthMethod AuthMethod { get; set; } = SshAuthMethod.PrivateKey;
|
||||
public string? PrivateKeyPath { get; set; }
|
||||
public string? PrivateKeyPassphrase { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public string DiskMount { get; set; } = "/";
|
||||
public string? MetricsEndpoint { get; set; }
|
||||
|
||||
public string ResolveMetricsEndpoint() =>
|
||||
string.IsNullOrWhiteSpace(MetricsEndpoint)
|
||||
? $"http://{Address}:9100/metrics"
|
||||
: MetricsEndpoint;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Vantage.Core.Models;
|
||||
|
||||
public sealed record HostMetrics
|
||||
{
|
||||
public double CpuUsagePercent { get; init; }
|
||||
public long MemoryUsedBytes { get; init; }
|
||||
public long MemoryTotalBytes { get; init; }
|
||||
public long DiskUsedBytes { get; init; }
|
||||
public long DiskTotalBytes { get; init; }
|
||||
public double Load1 { get; init; }
|
||||
public double Load5 { get; init; }
|
||||
public double Load15 { get; init; }
|
||||
public TimeSpan Uptime { get; init; }
|
||||
public DateTimeOffset CollectedAt { get; init; } = DateTimeOffset.UtcNow;
|
||||
|
||||
public double MemoryUsedPercent =>
|
||||
MemoryTotalBytes <= 0 ? 0 : Math.Round(100.0 * MemoryUsedBytes / MemoryTotalBytes, 1);
|
||||
|
||||
public double DiskUsedPercent =>
|
||||
DiskTotalBytes <= 0 ? 0 : Math.Round(100.0 * DiskUsedBytes / DiskTotalBytes, 1);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Vantage.Core.Alerts;
|
||||
using Vantage.Core.Logs;
|
||||
|
||||
namespace Vantage.Core.Models;
|
||||
|
||||
public sealed class VantageConfig
|
||||
{
|
||||
public List<HostConfig> Hosts { get; set; } = new();
|
||||
public List<HealthCheckConfig> HealthChecks { get; set; } = new();
|
||||
public List<AlertRule> AlertRules { get; set; } = new();
|
||||
public List<LogSource> LogSources { get; set; } = new();
|
||||
public int RefreshIntervalSeconds { get; set; } = 5;
|
||||
public int HistoryLength { get; set; } = 120;
|
||||
public int HistoryRetentionHours { get; set; } = 168;
|
||||
public string? AlertWebhookUrl { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user