< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
Update(...)0%110100%

File(s)

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

#LineLine coverage
 1namespace OzonOrdersWeb.WebServices.JobLogs;
 2
 3public 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
 29public sealed class DatabaseIoRateTracker
 30{
 031    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    {
 039        lock (_sync)
 40        {
 041            var elapsedSeconds = _capturedAtUtc.HasValue
 042                ? (capturedAtUtc - _capturedAtUtc.Value).TotalSeconds
 043                : 0;
 044            long? readRate = elapsedSeconds > 0 && readBytes >= _readBytes
 045                ? (long)Math.Round((readBytes - _readBytes) / elapsedSeconds)
 046                : null;
 047            long? writeRate = elapsedSeconds > 0 && writeBytes >= _writeBytes
 048                ? (long)Math.Round((writeBytes - _writeBytes) / elapsedSeconds)
 049                : null;
 50
 051            _capturedAtUtc = capturedAtUtc;
 052            _readBytes = readBytes;
 053            _writeBytes = writeBytes;
 054            return (readRate, writeRate);
 55        }
 056    }
 57}