Skip to content

Improve Akka.Cluster.Metrics collected values #6203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ public NodeMetrics Sample()
{
using (var process = Process.GetCurrentProcess())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is wrong - shouldn't we just cache this value somewhere?

{
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be GC

// 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;
}
}
}