| | | 1 | | namespace OzonOrdersWeb.WebServices.JobLogs; |
| | | 2 | | |
| | | 3 | | public sealed class ServerDiagnosticsSnapshot |
| | | 4 | | { |
| | | 5 | | public DateTime CapturedAtUtc { get; init; } |
| | | 6 | | public string ServerStatus { get; init; } = "Недоступен"; |
| | | 7 | | public string? ServerError { get; init; } |
| | | 8 | | public int ProcessorCount { get; init; } |
| | | 9 | | public double ProcessCpuPercent { get; init; } |
| | | 10 | | public long ProcessMemoryBytes { get; init; } |
| | | 11 | | public long AvailableMemoryBytes { get; init; } |
| | | 12 | | public long DiskTotalBytes { get; init; } |
| | | 13 | | public long DiskFreeBytes { get; init; } |
| | | 14 | | public string DatabaseStatus { get; init; } = "Недоступна"; |
| | | 15 | | public string? DatabaseError { get; init; } |
| | | 16 | | public string? DatabaseVersion { get; init; } |
| | | 17 | | public long DatabaseSizeBytes { get; init; } |
| | | 18 | | public long DatabaseReadLatencyMs { get; init; } |
| | | 19 | | public long? DatabaseReadBytesPerSecond { get; init; } |
| | | 20 | | public long? DatabaseWriteBytesPerSecond { get; init; } |
| | | 21 | | public long DatabaseReadBytesTotal { get; init; } |
| | | 22 | | public long DatabaseWriteBytesTotal { get; init; } |
| | | 23 | | public long DatabaseConnections { get; init; } |
| | | 24 | | public long DatabaseRunningThreads { get; init; } |
| | | 25 | | public long DatabaseSlowQueries { get; init; } |
| | | 26 | | public long FailedJobsLast24Hours { get; init; } |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | public sealed class DatabaseIoRateTracker |
| | | 30 | | { |
| | 0 | 31 | | private readonly object _sync = new(); |
| | | 32 | | private DateTime? _capturedAtUtc; |
| | | 33 | | private long _readBytes; |
| | | 34 | | private long _writeBytes; |
| | | 35 | | |
| | | 36 | | public (long? ReadBytesPerSecond, long? WriteBytesPerSecond) Update( |
| | | 37 | | DateTime capturedAtUtc, long readBytes, long writeBytes) |
| | | 38 | | { |
| | 0 | 39 | | lock (_sync) |
| | | 40 | | { |
| | 0 | 41 | | var elapsedSeconds = _capturedAtUtc.HasValue |
| | 0 | 42 | | ? (capturedAtUtc - _capturedAtUtc.Value).TotalSeconds |
| | 0 | 43 | | : 0; |
| | 0 | 44 | | long? readRate = elapsedSeconds > 0 && readBytes >= _readBytes |
| | 0 | 45 | | ? (long)Math.Round((readBytes - _readBytes) / elapsedSeconds) |
| | 0 | 46 | | : null; |
| | 0 | 47 | | long? writeRate = elapsedSeconds > 0 && writeBytes >= _writeBytes |
| | 0 | 48 | | ? (long)Math.Round((writeBytes - _writeBytes) / elapsedSeconds) |
| | 0 | 49 | | : null; |
| | | 50 | | |
| | 0 | 51 | | _capturedAtUtc = capturedAtUtc; |
| | 0 | 52 | | _readBytes = readBytes; |
| | 0 | 53 | | _writeBytes = writeBytes; |
| | 0 | 54 | | return (readRate, writeRate); |
| | | 55 | | } |
| | 0 | 56 | | } |
| | | 57 | | } |