You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationParserCgroupV1.cs
+1-1
Original file line number
Diff line number
Diff line change
@@ -145,7 +145,7 @@ public long GetHostCpuUsageInNanoseconds()
145
145
$"'{_procStat}' should contain whitespace separated values according to POSIX. We've failed trying to get {i}th value. File content: '{newstring(stat)}'.");
Copy file name to clipboardexpand all lines: src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationParserCgroupV2.cs
+1-1
Original file line number
Diff line number
Diff line change
@@ -163,7 +163,7 @@ public long GetHostCpuUsageInNanoseconds()
163
163
$"'{_procStat}' should contain whitespace separated values according to POSIX. We've failed trying to get {i}th value. File content: '{newstring(stat)}'.");
#pragma warning restore CA2000// Dispose objects before losing scope
68
70
71
+
_=meter.CreateObservableCounter(name:ResourceUtilizationInstruments.ContainerCpuTime,observeValues:GetCpuTime,unit:"s",description:"CPU time used by the container.");
Copy file name to clipboardexpand all lines: src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsContainerSnapshotProvider.cs
+12
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
usingSystem;
5
+
usingSystem.Collections.Generic;
5
6
usingSystem.Diagnostics.CodeAnalysis;
6
7
usingSystem.Diagnostics.Metrics;
7
8
usingSystem.Threading;
@@ -17,6 +18,7 @@ internal sealed class WindowsContainerSnapshotProvider : ISnapshotProvider
#pragma warning restore CA2000// Dispose objects before losing scope
115
117
116
118
// Container based metrics:
119
+
_=meter.CreateObservableCounter(name:ResourceUtilizationInstruments.ContainerCpuTime,observeValues:GetCpuTime,unit:"s",description:"CPU time used by the container.");
Copy file name to clipboardexpand all lines: test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs
+8-2
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ public void Provider_Registers_Instruments()
75
75
listener.Start();
76
76
listener.RecordObservableInstruments();
77
77
78
-
Assert.Equal(5,samples.Count);
78
+
Assert.Equal(7,samples.Count);
79
79
80
80
Assert.Contains(samples, x =>x.instrument.Name==ResourceUtilizationInstruments.ContainerCpuLimitUtilization);
Copy file name to clipboardexpand all lines: test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsContainerSnapshotProviderTests.cs
+60
Original file line number
Diff line number
Diff line change
@@ -191,6 +191,66 @@ public void GetSnapshot_With_JobMemoryLimit_Set_To_Zero_ProducesCorrectSnapshot(
191
191
Assert.True(data.MemoryUsageInBytes>0);
192
192
}
193
193
194
+
[Fact]
195
+
publicvoidSnapshotProvider_EmitsCpuTimeMetric()
196
+
{
197
+
// Simulating 10% CPU usage (2 CPUs, 2000 ticks initially, 4000 ticks after 1 ms):
0 commit comments