prometheus-net
40 строк · 1.5 Кб
1using System.Diagnostics;
2
3namespace Prometheus;
4
5/// <summary>
6/// Describes a lifetime of a lifetime-managed metric instance.
7/// </summary>
8/// <remarks>
9/// Contents modified via atomic operations, not guarded by locks.
10/// </remarks>
11internal sealed class ChildLifetimeInfo
12{
13/// <summary>
14/// Number of active leases. Nonzero value here indicates the lifetime extends forever.
15/// </summary>
16public int LeaseCount;
17
18/// <summary>
19/// When the last lifetime related activity was performed. Expiration timer starts counting from here.
20/// This is refreshed whenever a lease is released (a kept lease is a forever-keepalive, so we only care about releasing).
21/// </summary>
22public long KeepaliveTimestamp;
23
24/// <summary>
25/// The lifetime has been ended, potentially while a lease was active. The next time a lease ends,
26/// it will have to re-register the lifetime instead of just extending the existing one.
27/// </summary>
28public bool Ended;
29
30public override string ToString()
31{
32var leaseCount = Volatile.Read(ref LeaseCount);
33var keepaliveTimestamp = Volatile.Read(ref KeepaliveTimestamp);
34var ended = Volatile.Read(ref Ended);
35
36var age = PlatformCompatibilityHelpers.StopwatchGetElapsedTime(keepaliveTimestamp, Stopwatch.GetTimestamp());
37
38return $"LeaseCount: {leaseCount}, KeepaliveTimestamp: {keepaliveTimestamp}, Ended: {ended}, Age: {age.TotalSeconds:F3} seconds";
39}
40}