< Summary

Information
Class: OzonOrdersWeb.WebServices.JobLogs.ServerDiagnosticsSnapshot
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/JobLogs/ServerDiagnosticsModels.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 57
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/JobLogs/ServerDiagnosticsModels.cs

#LineLine coverage
 1namespace OzonOrdersWeb.WebServices.JobLogs;
 2
 3public sealed class ServerDiagnosticsSnapshot
 4{
 05    public DateTime CapturedAtUtc { get; init; }
 06    public string ServerStatus { get; init; } = "Недоступен";
 07    public string? ServerError { get; init; }
 08    public int ProcessorCount { get; init; }
 09    public double ProcessCpuPercent { get; init; }
 010    public long ProcessMemoryBytes { get; init; }
 011    public long AvailableMemoryBytes { get; init; }
 012    public long DiskTotalBytes { get; init; }
 013    public long DiskFreeBytes { get; init; }
 014    public string DatabaseStatus { get; init; } = "Недоступна";
 015    public string? DatabaseError { get; init; }
 016    public string? DatabaseVersion { get; init; }
 017    public long DatabaseSizeBytes { get; init; }
 018    public long DatabaseReadLatencyMs { get; init; }
 019    public long? DatabaseReadBytesPerSecond { get; init; }
 020    public long? DatabaseWriteBytesPerSecond { get; init; }
 021    public long DatabaseReadBytesTotal { get; init; }
 022    public long DatabaseWriteBytesTotal { get; init; }
 023    public long DatabaseConnections { get; init; }
 024    public long DatabaseRunningThreads { get; init; }
 025    public long DatabaseSlowQueries { get; init; }
 026    public long FailedJobsLast24Hours { get; init; }
 27}
 28
 29public sealed class DatabaseIoRateTracker
 30{
 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    {
 39        lock (_sync)
 40        {
 41            var elapsedSeconds = _capturedAtUtc.HasValue
 42                ? (capturedAtUtc - _capturedAtUtc.Value).TotalSeconds
 43                : 0;
 44            long? readRate = elapsedSeconds > 0 && readBytes >= _readBytes
 45                ? (long)Math.Round((readBytes - _readBytes) / elapsedSeconds)
 46                : null;
 47            long? writeRate = elapsedSeconds > 0 && writeBytes >= _writeBytes
 48                ? (long)Math.Round((writeBytes - _writeBytes) / elapsedSeconds)
 49                : null;
 50
 51            _capturedAtUtc = capturedAtUtc;
 52            _readBytes = readBytes;
 53            _writeBytes = writeBytes;
 54            return (readRate, writeRate);
 55        }
 56    }
 57}