diff --git a/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs b/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs index 8facf2fd985..976c54c2e25 100644 --- a/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs +++ b/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs @@ -55,13 +55,14 @@ public NodeMetrics Sample() { using (var process = Process.GetCurrentProcess()) { + process.Refresh(); var metrics = new List() { // Memory - // Forcing garbage collection to keep metrics more resilent to occasional allocations NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryUsed, GC.GetTotalMemory(true)).Value, - // VirtualMemorySize64 is not best idea here... - NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryAvailable, process.VirtualMemorySize64).Value, + + // total committed process memory = working set + paged + NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryAvailable, process.WorkingSet64 + process.PagedMemorySize64).Value, // CPU Processors NodeMetrics.Types.Metric.Create(StandardMetrics.Processors, Environment.ProcessorCount).Value, }; diff --git a/src/contrib/cluster/Akka.Cluster.Metrics/StandardMetrics.cs b/src/contrib/cluster/Akka.Cluster.Metrics/StandardMetrics.cs index 346f2e0e0b7..ed2f4a5917b 100644 --- a/src/contrib/cluster/Akka.Cluster.Metrics/StandardMetrics.cs +++ b/src/contrib/cluster/Akka.Cluster.Metrics/StandardMetrics.cs @@ -21,7 +21,7 @@ namespace Akka.Cluster.Metrics public static class StandardMetrics { /// - /// Total memory allocated to the currently running process () + /// Total memory allocated to the currently running process () /// public const string MemoryUsed = "MemoryUsed"; /// @@ -84,7 +84,7 @@ public sealed class Memory /// public long Timestamp { get; } /// - /// The current process allocated memory (in bytes) () + /// The current process allocated memory (in bytes) () /// public double Used { get; } /// diff --git a/src/core/Akka/Util/Extensions/DateTimeExtensions.cs b/src/core/Akka/Util/Extensions/DateTimeExtensions.cs index 0a9d2f83d9f..dd234bc8310 100644 --- a/src/core/Akka/Util/Extensions/DateTimeExtensions.cs +++ b/src/core/Akka/Util/Extensions/DateTimeExtensions.cs @@ -14,12 +14,14 @@ namespace Akka.Util.Extensions /// public static class DateTimeExtensions { + private static readonly DateTime UnixOffset = new DateTime(1970, 1, 1); + /// /// Converts given date and time to UNIX Timestamp - number of milliseconds elapsed since 1 Jan 1970 /// public static long ToTimestamp(this DateTime dateTime) { - return (long)(dateTime - new DateTime(1970, 1, 1)).TotalMilliseconds; + return (long)(dateTime - UnixOffset).TotalMilliseconds; } } }