Skip to content

Commit

Permalink
add the container_info{image="..."} metric
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed Dec 22, 2022
1 parent b8797df commit 7a7cf46
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ContainerMetadata struct {
labels map[string]string
volumes map[string]string
logPath string
image string
logDecoder logparser.Decoder
hostListens map[string][]netaddr.IPPort
}
Expand Down Expand Up @@ -186,6 +187,10 @@ func (c *Container) Collect(ch chan<- prometheus.Metric) {
c.lock.RLock()
defer c.lock.RUnlock()

if c.metadata.image != "" {
ch <- gauge(metrics.ContainerInfo, 1, c.metadata.image)
}

ch <- counter(metrics.Restarts, float64(c.restarts))

if cpu, err := c.cgroup.CpuStat(); err == nil {
Expand Down
1 change: 1 addition & 0 deletions containers/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func ContainerdInspect(containerID string) (*ContainerMetadata, error) {

res := &ContainerMetadata{
labels: c.Labels,
image: c.Image,
volumes: map[string]string{},
}

Expand Down
1 change: 1 addition & 0 deletions containers/dockerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func DockerdInspect(containerID string) (*ContainerMetadata, error) {
res := &ContainerMetadata{
name: strings.TrimPrefix(c.Name, "/"),
labels: c.Config.Labels,
image: c.Image,
volumes: map[string]string{},
hostListens: map[string][]netaddr.IPPort{},
}
Expand Down
5 changes: 4 additions & 1 deletion containers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

var metrics = struct {
Restarts *prometheus.Desc
ContainerInfo *prometheus.Desc
Restarts *prometheus.Desc

CPULimit *prometheus.Desc
CPUUsage *prometheus.Desc
Expand Down Expand Up @@ -45,6 +46,8 @@ var metrics = struct {
JvmSafepointTime *prometheus.Desc
JvmSafepointSyncTime *prometheus.Desc
}{
ContainerInfo: metric("container_info", "Meta information about the container", "image"),

Restarts: metric("container_restarts_total", "Number of times the container was restarted"),

CPULimit: metric("container_resources_cpu_limit_cores", "CPU limit of the container"),
Expand Down

0 comments on commit 7a7cf46

Please sign in to comment.