Skip to content

Commit 17d4736

Browse files
committed
feat: add current pids metrics
1 parent de7c3e6 commit 17d4736

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

internal/collector/collector.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func (c *DockerCollector) collectContainerMetrics(ctx context.Context, container
110110
c.memoryMetrics(ch, name, stats)
111111
c.networkMetrics(ch, name, stats)
112112
c.blockIOMetrics(ch, name, stats)
113+
c.pidsMetrics(ch, name, stats)
113114
}
114115

115116
func (c *DockerCollector) cpuMetrics(ch chan<- prometheus.Metric, name string, stats *types.StatsJSON) {
@@ -240,6 +241,14 @@ func (c *DockerCollector) blockIOMetrics(ch chan<- prometheus.Metric, name strin
240241
)
241242
}
242243

244+
func (c *DockerCollector) pidsMetrics(ch chan<- prometheus.Metric, name string, stats *types.StatsJSON) {
245+
ch <- prometheus.MustNewConstMetric(pidsCurrent,
246+
prometheus.GaugeValue,
247+
float64(stats.PidsStats.Current),
248+
name,
249+
)
250+
}
251+
243252
// containerStats gets the stats of a single containers.
244253
func (c *DockerCollector) containerStats(ctx context.Context, containerID string) (*types.StatsJSON, error) {
245254
r, err := c.client.ContainerStats(ctx, containerID, false)

internal/collector/collector_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func TestCollectMetrics(t *testing.T) {
9090
# HELP docker_container_network_tx_packets Network sent packets total
9191
# TYPE docker_container_network_tx_packets gauge
9292
docker_container_network_tx_packets{name="testName",network="eth0"} 864
93+
# HELP docker_container_pids_current Current number of pids
94+
# TYPE docker_container_pids_current gauge
95+
docker_container_pids_current{name="testName"} 12
9396
# HELP docker_container_state State of the container
9497
# TYPE docker_container_state gauge
9598
docker_container_state{name="testName",state="running"} 1
@@ -165,6 +168,9 @@ func buildStatsResponse() types.StatsJSON {
165168
SystemUsage: 1223,
166169
OnlineCPUs: 4,
167170
},
171+
PidsStats: types.PidsStats{
172+
Current: 12,
173+
},
168174
},
169175
Networks: map[string]types.NetworkStats{
170176
"eth0": {

internal/collector/metrics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,15 @@ var (
137137
[]string{"name"},
138138
nil,
139139
)
140+
141+
/*
142+
PIDs Metrics
143+
*/
144+
145+
pidsCurrent = prometheus.NewDesc(
146+
"docker_container_pids_current",
147+
"Current number of pids",
148+
[]string{"name"},
149+
nil,
150+
)
140151
)

0 commit comments

Comments
 (0)