Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose cpu frequency governor metrics #2569

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions collector/cpufreq_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import (
var (
cpuFreqHertzDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_hertz"),
"Current cpu thread frequency in hertz.",
"Current CPU thread frequency in hertz.",
[]string{"cpu"}, nil,
)
cpuFreqMinDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_min_hertz"),
"Minimum cpu thread frequency in hertz.",
"Minimum CPU thread frequency in hertz.",
[]string{"cpu"}, nil,
)
cpuFreqMaxDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_max_hertz"),
"Maximum cpu thread frequency in hertz.",
"Maximum CPU thread frequency in hertz.",
[]string{"cpu"}, nil,
)
cpuFreqScalingFreqDesc = prometheus.NewDesc(
Expand All @@ -51,4 +51,9 @@ var (
"Maximum scaled CPU thread frequency in hertz.",
[]string{"cpu"}, nil,
)
cpuFreqScalingGovernorDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "scaling_governor"),
"Current enabled CPU frequency governor.",
[]string{"cpu", "governor"}, nil,
)
)
18 changes: 17 additions & 1 deletion collector/cpufreq_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package collector

import (
"fmt"

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

type cpuFreqCollector struct {
Expand Down Expand Up @@ -104,6 +104,22 @@ func (c *cpuFreqCollector) Update(ch chan<- prometheus.Metric) error {
stats.Name,
)
}
if stats.Governor != "" {
availableGovernors := strings.Split(stats.AvailableGovernors, " ")
for _, g := range availableGovernors {
state := 0
if g == stats.Governor {
state = 1
}
ch <- prometheus.MustNewConstMetric(
cpuFreqScalingGovernorDesc,
prometheus.GaugeValue,
float64(state),
stats.Name,
g,
)
}
}
}
return nil
}
10 changes: 10 additions & 0 deletions collector/fixtures/e2e-64k-page-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ node_cpu_scaling_frequency_min_hertz{cpu="0"} 8e+08
node_cpu_scaling_frequency_min_hertz{cpu="1"} 8e+08
node_cpu_scaling_frequency_min_hertz{cpu="2"} 1e+06
node_cpu_scaling_frequency_min_hertz{cpu="3"} 1e+06
# HELP node_cpu_scaling_governor Current enabled CPU frequency governor.
# TYPE node_cpu_scaling_governor gauge
node_cpu_scaling_governor{cpu="0",governor="performance"} 0
node_cpu_scaling_governor{cpu="0",governor="powersave"} 1
node_cpu_scaling_governor{cpu="1",governor="performance"} 0
node_cpu_scaling_governor{cpu="1",governor="powersave"} 1
node_cpu_scaling_governor{cpu="2",governor="performance"} 0
node_cpu_scaling_governor{cpu="2",governor="powersave"} 1
node_cpu_scaling_governor{cpu="3",governor="performance"} 0
node_cpu_scaling_governor{cpu="3",governor="powersave"} 1
# HELP node_cpu_seconds_total Seconds the CPUs spent in each mode.
# TYPE node_cpu_seconds_total counter
node_cpu_seconds_total{cpu="0",mode="idle"} 10870.69
Expand Down
10 changes: 10 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ node_cpu_scaling_frequency_min_hertz{cpu="0"} 8e+08
node_cpu_scaling_frequency_min_hertz{cpu="1"} 8e+08
node_cpu_scaling_frequency_min_hertz{cpu="2"} 1e+06
node_cpu_scaling_frequency_min_hertz{cpu="3"} 1e+06
# HELP node_cpu_scaling_governor Current enabled CPU frequency governor.
# TYPE node_cpu_scaling_governor gauge
node_cpu_scaling_governor{cpu="0",governor="performance"} 0
node_cpu_scaling_governor{cpu="0",governor="powersave"} 1
node_cpu_scaling_governor{cpu="1",governor="performance"} 0
node_cpu_scaling_governor{cpu="1",governor="powersave"} 1
node_cpu_scaling_governor{cpu="2",governor="performance"} 0
node_cpu_scaling_governor{cpu="2",governor="powersave"} 1
node_cpu_scaling_governor{cpu="3",governor="performance"} 0
node_cpu_scaling_governor{cpu="3",governor="powersave"} 1
# HELP node_cpu_seconds_total Seconds the CPUs spent in each mode.
# TYPE node_cpu_seconds_total counter
node_cpu_seconds_total{cpu="0",mode="idle"} 10870.69
Expand Down