Skip to content

Commit

Permalink
Improve Akka.Cluster.Metrics collected values (akkadotnet#6203)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Arkatufus and Aaronontheweb authored Oct 28, 2022
1 parent 61df6fc commit dca908b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ public NodeMetrics Sample()
{
using (var process = Process.GetCurrentProcess())
{
process.Refresh();
var metrics = new List<NodeMetrics.Types.Metric>()
{
// 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,
};
Expand Down
4 changes: 2 additions & 2 deletions src/contrib/cluster/Akka.Cluster.Metrics/StandardMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Akka.Cluster.Metrics
public static class StandardMetrics
{
/// <summary>
/// Total memory allocated to the currently running process (<see cref="GC.GetTotalMemory"/>)
/// Total memory allocated to the currently running process (<see cref="Process.WorkingSet64"/>)
/// </summary>
public const string MemoryUsed = "MemoryUsed";
/// <summary>
Expand Down Expand Up @@ -84,7 +84,7 @@ public sealed class Memory
/// </summary>
public long Timestamp { get; }
/// <summary>
/// The current process allocated memory (in bytes) (<see cref="GC.GetTotalMemory"/>)
/// The current process allocated memory (in bytes) (<see cref="Process.WorkingSet64"/>)
/// </summary>
public double Used { get; }
/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion src/core/Akka/Util/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ namespace Akka.Util.Extensions
/// </summary>
public static class DateTimeExtensions
{
private static readonly DateTime UnixOffset = new DateTime(1970, 1, 1);

/// <summary>
/// Converts given date and time to UNIX Timestamp - number of milliseconds elapsed since 1 Jan 1970
/// </summary>
public static long ToTimestamp(this DateTime dateTime)
{
return (long)(dateTime - new DateTime(1970, 1, 1)).TotalMilliseconds;
return (long)(dateTime - UnixOffset).TotalMilliseconds;
}
}
}

0 comments on commit dca908b

Please sign in to comment.