Skip to content

Commit

Permalink
Cleanup cgroups collector (prometheus#2414)
Browse files Browse the repository at this point in the history
* Correctly name collector file.
* Fix cgroup summary type as gauge.
* Use a boolean metric rather than a label for enabled.

Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
SuperQ authored and oblitorum committed Apr 9, 2024
1 parent e5c59e1 commit eb93e76
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ from debugfs. And example usage of this would be
Name | Description | OS
---------|-------------|----
buddyinfo | Exposes statistics of memory fragments as reported by /proc/buddyinfo. | Linux
cgroups | A summary of the number of active and enabled cgroups | Linux
devstat | Exposes device statistics | Dragonfly, FreeBSD
drbd | Exposes Distributed Replicated Block Device statistics (to version 8.4) | Linux
ethtool | Exposes network interface information and network driver statistics equivalent to `ethtool`, `ethtool -S`, and `ethtool -i`. | Linux
Expand Down
18 changes: 13 additions & 5 deletions collector/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@ package collector

import (
"fmt"
"strconv"

"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)

const cgroupsCollectorSubsystem = "cgroups"

type cgroupSummaryCollector struct {
fs procfs.FS
cgroups *prometheus.Desc
enabled *prometheus.Desc
logger log.Logger
}

func init() {
registerCollector("cgroupSummary", defaultEnabled, NewCgroupSummaryCollector)
registerCollector(cgroupsCollectorSubsystem, defaultDisabled, NewCgroupSummaryCollector)
}

// NewCgroupSummaryCollector returns a new Collector exposing a summary of cgroups.
Expand All @@ -44,9 +46,14 @@ func NewCgroupSummaryCollector(logger log.Logger) (Collector, error) {
return &cgroupSummaryCollector{
fs: fs,
cgroups: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "cgroups_total"),
prometheus.BuildFQName(namespace, cgroupsCollectorSubsystem, "cgroups"),
"Current cgroup number of the subsystem.",
[]string{"subsys_name"}, nil,
),
enabled: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cgroupsCollectorSubsystem, "enabled"),
"Current cgroup number of the subsystem.",
[]string{"subsys_name", "enabled"}, nil,
[]string{"subsys_name"}, nil,
),
logger: logger,
}, nil
Expand All @@ -59,7 +66,8 @@ func (c *cgroupSummaryCollector) Update(ch chan<- prometheus.Metric) error {
return err
}
for _, cs := range cgroupSummarys {
ch <- prometheus.MustNewConstMetric(c.cgroups, prometheus.CounterValue, float64(cs.Cgroups), cs.SubsysName, strconv.Itoa(cs.Enabled))
ch <- prometheus.MustNewConstMetric(c.cgroups, prometheus.GaugeValue, float64(cs.Cgroups), cs.SubsysName)
ch <- prometheus.MustNewConstMetric(c.enabled, prometheus.GaugeValue, float64(cs.Enabled), cs.SubsysName)
}
return nil
}
44 changes: 29 additions & 15 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -374,20 +374,34 @@ node_buddyinfo_blocks{node="0",size="8",zone="Normal"} 0
node_buddyinfo_blocks{node="0",size="9",zone="DMA"} 1
node_buddyinfo_blocks{node="0",size="9",zone="DMA32"} 0
node_buddyinfo_blocks{node="0",size="9",zone="Normal"} 0
# HELP node_cgroups_total Current cgroup number of the subsystem.
# TYPE node_cgroups_total counter
node_cgroups_total{enabled="1",subsys_name="blkio"} 170
node_cgroups_total{enabled="1",subsys_name="cpu"} 172
node_cgroups_total{enabled="1",subsys_name="cpuacct"} 172
node_cgroups_total{enabled="1",subsys_name="cpuset"} 47
node_cgroups_total{enabled="1",subsys_name="devices"} 170
node_cgroups_total{enabled="1",subsys_name="freezer"} 47
node_cgroups_total{enabled="1",subsys_name="hugetlb"} 47
node_cgroups_total{enabled="1",subsys_name="memory"} 234
node_cgroups_total{enabled="1",subsys_name="net_cls"} 47
node_cgroups_total{enabled="1",subsys_name="perf_event"} 47
node_cgroups_total{enabled="1",subsys_name="pids"} 170
node_cgroups_total{enabled="1",subsys_name="rdma"} 1
# HELP node_cgroups_cgroups Current cgroup number of the subsystem.
# TYPE node_cgroups_cgroups gauge
node_cgroups_cgroups{subsys_name="blkio"} 170
node_cgroups_cgroups{subsys_name="cpu"} 172
node_cgroups_cgroups{subsys_name="cpuacct"} 172
node_cgroups_cgroups{subsys_name="cpuset"} 47
node_cgroups_cgroups{subsys_name="devices"} 170
node_cgroups_cgroups{subsys_name="freezer"} 47
node_cgroups_cgroups{subsys_name="hugetlb"} 47
node_cgroups_cgroups{subsys_name="memory"} 234
node_cgroups_cgroups{subsys_name="net_cls"} 47
node_cgroups_cgroups{subsys_name="perf_event"} 47
node_cgroups_cgroups{subsys_name="pids"} 170
node_cgroups_cgroups{subsys_name="rdma"} 1
# HELP node_cgroups_enabled Current cgroup number of the subsystem.
# TYPE node_cgroups_enabled gauge
node_cgroups_enabled{subsys_name="blkio"} 1
node_cgroups_enabled{subsys_name="cpu"} 1
node_cgroups_enabled{subsys_name="cpuacct"} 1
node_cgroups_enabled{subsys_name="cpuset"} 1
node_cgroups_enabled{subsys_name="devices"} 1
node_cgroups_enabled{subsys_name="freezer"} 1
node_cgroups_enabled{subsys_name="hugetlb"} 1
node_cgroups_enabled{subsys_name="memory"} 1
node_cgroups_enabled{subsys_name="net_cls"} 1
node_cgroups_enabled{subsys_name="perf_event"} 1
node_cgroups_enabled{subsys_name="pids"} 1
node_cgroups_enabled{subsys_name="rdma"} 1
# HELP node_context_switches_total Total number of context switches.
# TYPE node_context_switches_total counter
node_context_switches_total 3.8014093e+07
Expand Down Expand Up @@ -3314,7 +3328,7 @@ node_scrape_collector_success{collector="bcache"} 1
node_scrape_collector_success{collector="bonding"} 1
node_scrape_collector_success{collector="btrfs"} 1
node_scrape_collector_success{collector="buddyinfo"} 1
node_scrape_collector_success{collector="cgroupSummary"} 1
node_scrape_collector_success{collector="cgroups"} 1
node_scrape_collector_success{collector="conntrack"} 1
node_scrape_collector_success{collector="cpu"} 1
node_scrape_collector_success{collector="cpufreq"} 1
Expand Down
1 change: 1 addition & 0 deletions end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enabled_collectors=$(cat << COLLECTORS
btrfs
buddyinfo
conntrack
cgroups
cpu
cpufreq
diskstats
Expand Down

0 comments on commit eb93e76

Please sign in to comment.