Make diagnostics JSON trim safe
This commit is contained in:
parent
160a5c683d
commit
c252701623
1 changed files with 48 additions and 46 deletions
|
|
@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ServerMonitorManager.Core;
|
||||
|
||||
|
|
@ -36,12 +37,6 @@ public sealed record DiagnosticMetricInput(
|
|||
|
||||
public static class DiagnosticsExportService
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
};
|
||||
|
||||
public static string CreateJson(
|
||||
IEnumerable<DiagnosticServerInput> servers,
|
||||
IEnumerable<DiagnosticNodeInput> nodes,
|
||||
|
|
@ -87,7 +82,7 @@ public static class DiagnosticsExportService
|
|||
nodeSnapshots,
|
||||
linkSnapshots,
|
||||
metricSnapshots);
|
||||
return JsonSerializer.Serialize(snapshot, JsonOptions);
|
||||
return JsonSerializer.Serialize(snapshot, DiagnosticsJsonContext.Default.DiagnosticSnapshot);
|
||||
}
|
||||
|
||||
private static string Fingerprint(string value)
|
||||
|
|
@ -107,7 +102,9 @@ public static class DiagnosticsExportService
|
|||
_ => "unknown"
|
||||
};
|
||||
|
||||
private sealed record DiagnosticSnapshot(
|
||||
}
|
||||
|
||||
internal sealed record DiagnosticSnapshot(
|
||||
int FormatVersion,
|
||||
DateTimeOffset GeneratedAt,
|
||||
string AppVersion,
|
||||
|
|
@ -119,19 +116,19 @@ public static class DiagnosticsExportService
|
|||
IReadOnlyList<DiagnosticLink> Links,
|
||||
IReadOnlyList<DiagnosticMetric> Metrics);
|
||||
|
||||
private sealed record DiagnosticServer(
|
||||
internal sealed record DiagnosticServer(
|
||||
string EndpointFingerprint,
|
||||
bool IsHub,
|
||||
bool IsOnline,
|
||||
bool HasWarning,
|
||||
double CpuPercent);
|
||||
|
||||
private sealed record DiagnosticNode(
|
||||
internal sealed record DiagnosticNode(
|
||||
string NodeFingerprint,
|
||||
string State,
|
||||
int HandshakeAgeSeconds);
|
||||
|
||||
private sealed record DiagnosticLink(
|
||||
internal sealed record DiagnosticLink(
|
||||
string SourceFingerprint,
|
||||
string TargetFingerprint,
|
||||
string Protocol,
|
||||
|
|
@ -140,10 +137,15 @@ public static class DiagnosticsExportService
|
|||
long Version,
|
||||
long ExpiresUnix);
|
||||
|
||||
private sealed record DiagnosticMetric(
|
||||
internal sealed record DiagnosticMetric(
|
||||
string ServerFingerprint,
|
||||
DateTimeOffset Timestamp,
|
||||
double CpuPercent,
|
||||
double MemoryPercent,
|
||||
double DiskPercent);
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower,
|
||||
WriteIndented = true)]
|
||||
[JsonSerializable(typeof(DiagnosticSnapshot))]
|
||||
internal sealed partial class DiagnosticsJsonContext : JsonSerializerContext;
|
||||
|
|
|
|||
Loading…
Reference in a new issue