Skip to content

Commit

Permalink
Track memory bytes per container
Browse files Browse the repository at this point in the history
We have a problem where the gauge without labels is created and always
set to zero. I don't want this to be there but haven't figured out how
to get rid of it yet.

The answer might have to be that we change the prometheus library we're
using. This one has not had updates in a while.
  • Loading branch information
tanelso2 committed Dec 24, 2024
1 parent 1b40244 commit 7447f99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/tiny_container_manager/docker.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type
DockerStats* = object
CPUPerc*: float
Name*: string
MemBytes*: int
MemPerc*: float
PIDs*: int

Expand Down Expand Up @@ -173,6 +174,7 @@ proc getContainerStats*(name: string, oneShot = false): Option[DockerStats] =
return some(DockerStats(
CPUPerc: cpu_usage_percent,
Name: name,
MemBytes: used_memory,
MemPerc: memory_usage_percent,
PIDs: pids
))
Expand Down Expand Up @@ -220,6 +222,7 @@ proc observeDockerStats*() =
for s in stats:
metrics.containerCPUPerc.labels(s.Name).set(s.CPUPerc)
metrics.containerMemPerc.labels(s.Name).set(s.MemPerc)
metrics.containerMemBytes.labels(s.Name).set(s.MemBytes)
metrics.containerPIDs.labels(s.Name).set(s.PIDs)

proc main() =
Expand All @@ -230,7 +233,7 @@ proc main() =

when isMainModule:
#echo getContainers()
# logInfo $getContainerStats("nginx")
logInfo $getContainerStats("nginx")
# logInfo $(waitFor getDockerCLIStats())
logInfo $getDockerStats()
observeDockerStats()
Expand Down
16 changes: 12 additions & 4 deletions src/tiny_container_manager/metrics.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import
prometheus as prom
prometheus as prom,
nim_utils/logline

export prom

Expand Down Expand Up @@ -39,19 +40,26 @@ var nginxConfigsWritten* {.global.} = prom.newCounter(
var containerCPUPerc* {.global.} = prom.newGauge(
"tcm_container_cpu_perc",
"",
@["site"]
labelNames = @["site"]
)

var containerMemPerc* {.global.} = prom.newGauge(
"tcm_container_mem_perc",
"",
@["site"]
labelNames = @["site"]
)

var containerMemBytes* {.global.} = prom.newGauge(
"tcm_container_mem_bytes",
"",
labelNames = @["site"],
unit = Unit.Bytes
)

var containerPIDs* {.global.} = prom.newGauge(
"tcm_container_pids",
"",
@["site"]
labelNames = @["site"]
)

var letsEncryptBackupsDeleted* {.global.} = prom.newCounter(
Expand Down

0 comments on commit 7447f99

Please sign in to comment.