prometheus-net

Форк
0
/
ChildLifetimeInfo.cs 
40 строк · 1.5 Кб
1
using System.Diagnostics;
2

3
namespace 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>
11
internal sealed class ChildLifetimeInfo
12
{
13
    /// <summary>
14
    /// Number of active leases. Nonzero value here indicates the lifetime extends forever.
15
    /// </summary>
16
    public 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>
22
    public 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>
28
    public bool Ended;
29

30
    public override string ToString()
31
    {
32
        var leaseCount = Volatile.Read(ref LeaseCount);
33
        var keepaliveTimestamp = Volatile.Read(ref KeepaliveTimestamp);
34
        var ended = Volatile.Read(ref Ended);
35

36
        var age = PlatformCompatibilityHelpers.StopwatchGetElapsedTime(keepaliveTimestamp, Stopwatch.GetTimestamp());
37

38
        return $"LeaseCount: {leaseCount}, KeepaliveTimestamp: {keepaliveTimestamp}, Ended: {ended}, Age: {age.TotalSeconds:F3} seconds";
39
    }
40
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.