Skip to content

Commit 50ff09e

Browse files
committed
fix: linux load samples
1 parent ee113bf commit 50ff09e

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎LiveControlGateway/GatewayLoadSampler.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public byte Measure()
8282
_containerCpu = _containerMemory = _processCpu = _processMemory = null;
8383
_listener.RecordObservableInstruments();
8484

85-
var connections = ToPercent(100d * _hubLifetimeManager.HubCount / _options.MaxHubConnections);
85+
var connections = ToPercent((double)_hubLifetimeManager.HubCount / _options.MaxHubConnections);
8686
var cpu = ToPercent(_containerCpu ?? _processCpu ?? 0);
8787
var memory = ToPercent(_containerMemory ?? _processMemory ?? 0);
8888

@@ -91,7 +91,7 @@ public byte Measure()
9191
return load;
9292
}
9393

94-
private static byte ToPercent(double percent) => (byte)Math.Clamp(Math.Round(percent), 0, 100);
94+
private static byte ToPercent(double fraction) => (byte)Math.Clamp(Math.Round(fraction * 100), 0, 100);
9595

9696
/// <inheritdoc />
9797
public void Dispose() => _listener.Dispose();

‎LiveControlGateway/Program.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.Metrics;
2+
using Microsoft.Extensions.Diagnostics.ResourceMonitoring;
23
using Microsoft.Extensions.Options;
34
using OpenShock.Common;
45
using OpenShock.Common.Extensions;
@@ -46,6 +47,14 @@
4647
builder.Services.AddSingleton<GatewayMetrics>();
4748
builder.Services.AddSingleton<HubLifetimeManager>();
4849
builder.Services.AddResourceMonitoring();
50+
// The defaults differ per OS ([0, 1] on Linux, [0, 100] on Windows), so pin both to [0, 1].
51+
#pragma warning disable EXTEXP0008
52+
builder.Services.Configure<ResourceMonitoringOptions>(options =>
53+
{
54+
options.UseZeroToOneRangeForLinuxMetrics = true;
55+
options.UseZeroToOneRangeForMetrics = true;
56+
});
57+
#pragma warning restore EXTEXP0008
4958
builder.Services.AddSingleton<GatewayLoadSampler>();
5059
builder.Services.AddSingleton<ApiTokenUpdateSubscriber>();
5160

0 commit comments

Comments
 (0)