Skip to content

Commit dca908b

Browse files
Improve Akka.Cluster.Metrics collected values (#6203)
* Improve collected values * Update API Verify list * Fix metrics collection * Fix documentation * Update API Verify list * Update DefaultCollector.cs * Update DefaultCollector.cs Co-authored-by: Aaron Stannard <[email protected]>
1 parent 61df6fc commit dca908b

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ public NodeMetrics Sample()
5555
{
5656
using (var process = Process.GetCurrentProcess())
5757
{
58+
process.Refresh();
5859
var metrics = new List<NodeMetrics.Types.Metric>()
5960
{
6061
// Memory
61-
// Forcing garbage collection to keep metrics more resilent to occasional allocations
6262
NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryUsed, GC.GetTotalMemory(true)).Value,
63-
// VirtualMemorySize64 is not best idea here...
64-
NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryAvailable, process.VirtualMemorySize64).Value,
63+
64+
// total committed process memory = working set + paged
65+
NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryAvailable, process.WorkingSet64 + process.PagedMemorySize64).Value,
6566
// CPU Processors
6667
NodeMetrics.Types.Metric.Create(StandardMetrics.Processors, Environment.ProcessorCount).Value,
6768
};

src/contrib/cluster/Akka.Cluster.Metrics/StandardMetrics.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Akka.Cluster.Metrics
2121
public static class StandardMetrics
2222
{
2323
/// <summary>
24-
/// Total memory allocated to the currently running process (<see cref="GC.GetTotalMemory"/>)
24+
/// Total memory allocated to the currently running process (<see cref="Process.WorkingSet64"/>)
2525
/// </summary>
2626
public const string MemoryUsed = "MemoryUsed";
2727
/// <summary>
@@ -84,7 +84,7 @@ public sealed class Memory
8484
/// </summary>
8585
public long Timestamp { get; }
8686
/// <summary>
87-
/// The current process allocated memory (in bytes) (<see cref="GC.GetTotalMemory"/>)
87+
/// The current process allocated memory (in bytes) (<see cref="Process.WorkingSet64"/>)
8888
/// </summary>
8989
public double Used { get; }
9090
/// <summary>

src/core/Akka/Util/Extensions/DateTimeExtensions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ namespace Akka.Util.Extensions
1414
/// </summary>
1515
public static class DateTimeExtensions
1616
{
17+
private static readonly DateTime UnixOffset = new DateTime(1970, 1, 1);
18+
1719
/// <summary>
1820
/// Converts given date and time to UNIX Timestamp - number of milliseconds elapsed since 1 Jan 1970
1921
/// </summary>
2022
public static long ToTimestamp(this DateTime dateTime)
2123
{
22-
return (long)(dateTime - new DateTime(1970, 1, 1)).TotalMilliseconds;
24+
return (long)(dateTime - UnixOffset).TotalMilliseconds;
2325
}
2426
}
2527
}

0 commit comments

Comments
 (0)