This repository has been archived by the owner on Feb 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
ContainerTrackerStateMetrics.cs
48 lines (40 loc) · 1.8 KB
/
ContainerTrackerStateMetrics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Prometheus;
using System;
namespace DockerExporter
{
sealed class ContainerTrackerStateMetrics : IDisposable
{
public Gauge.Child RestartCount { get; private set; }
public Gauge.Child RunningState { get; private set; }
public Gauge.Child StartTime { get; private set; }
public ContainerTrackerStateMetrics(string displayName)
{
RestartCount = BaseRestartCount.WithLabels(displayName);
RunningState = BaseRunningState.WithLabels(displayName);
StartTime = BaseStartTime.WithLabels(displayName);
}
public void Dispose()
{
RestartCount.Remove();
RunningState.Remove();
StartTime.Remove();
}
public void Unpublish()
{
RestartCount.Unpublish();
RunningState.Unpublish();
StartTime.Unpublish();
}
private static readonly Gauge BaseRestartCount = Metrics
.CreateGauge("docker_container_restart_count", "Number of times the runtime has restarted this container without explicit user action, since the container was last started.", ConfigureGauge());
private static readonly Gauge BaseRunningState = Metrics
.CreateGauge("docker_container_running_state", "Whether the container is running (1), restarting (0.5) or stopped (0).", ConfigureGauge());
private static readonly Gauge BaseStartTime = Metrics
.CreateGauge("docker_container_start_time_seconds", "Timestamp indicating when the container was started. Does not get reset by automatic restarts.", ConfigureGauge());
private static GaugeConfiguration ConfigureGauge() => new GaugeConfiguration
{
LabelNames = new[] { "name" },
SuppressInitialValue = true
};
}
}