Skip to content

Commit

Permalink
Fix cpu freq failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Oct 4, 2023
1 parent a372120 commit 3f53cb4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error
}

// NewNodeCollector creates a new NodeCollector.
func NewNodeCollector(config *NodeCollectorConfig, enabledCollectors map[string]bool, logger log.Logger, filters ...string) (*NodeCollector, error) {
func NewNodeCollector(config *NodeCollectorConfig, logger log.Logger, filters ...string) (*NodeCollector, error) {
f := make(map[string]bool)
for _, filter := range filters {
enabled, exist := enabledCollectors[filter]
enabled, exist := config.Collectors[filter]
if !exist {
return nil, fmt.Errorf("missing collector: %s", filter)
}
Expand All @@ -140,7 +140,7 @@ func NewNodeCollector(config *NodeCollectorConfig, enabledCollectors map[string]
}
collectors := make(map[string]Collector)

for key, enabled := range enabledCollectors {
for key, enabled := range config.Collectors {
if !enabled || (len(f) > 0 && !f[key]) {
continue
}
Expand Down
2 changes: 2 additions & 0 deletions collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type NodeCollectorConfig struct {
TextFile TextFileConfig
VmStat VmStatConfig
Wifi WifiConfig

Collectors map[string]bool
}

type WifiConfig struct {
Expand Down
17 changes: 10 additions & 7 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
cpu.CacheSize)
}

for _, cpu := range info {
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
prometheus.GaugeValue,
cpu.CPUMHz*1e6,
cpu.PhysicalID,
cpu.CoreID,
strconv.Itoa(int(cpu.Processor)))
// This should only run if CPUFREQ is NOT enabled.
if found, enabled := c.config.Collectors["cpufreq"]; found && !enabled {
for _, cpu := range info {
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
prometheus.GaugeValue,
cpu.CPUMHz*1e6,
cpu.PhysicalID,
cpu.CoreID,
strconv.Itoa(int(cpu.Processor)))
}
}

if len(info) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions collector/devstat_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ type devstatCollector struct {
}

func init() {
registerCollector("devstat", defaultDisabled,NewDevstatCollector)
registerCollector("devstat", defaultDisabled, NewDevstatCollector)
}

// NewDevstatCollector returns a new Collector exposing Device stats.
func NewDevstatCollector(config *NodeCollectorConfiglogger log.Logger) (Collector, error) {
func NewDevstatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &devstatCollector{
bytesDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
Expand Down
4 changes: 2 additions & 2 deletions node_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// (in which case it will log all the collectors enabled via command-line
// flags).
func (h *handler) innerHandler(filters ...string) (http.Handler, error) {
nc, err := collector.NewNodeCollector(h.collectorConfig, collector.GetFlagDefaults(), h.logger, filters...)
nc, err := collector.NewNodeCollector(h.collectorConfig, h.logger, filters...)
if err != nil {
return nil, fmt.Errorf("couldn't create collector: %s", err)
}
Expand Down Expand Up @@ -188,7 +188,7 @@ func main() {
}
runtime.GOMAXPROCS(*maxProcs)
level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))

collectorConfig.Collectors = collector.GetFlagDefaults()
http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, collectorConfig, logger))
if *metricsPath != "/" {
landingConfig := web.LandingConfig{
Expand Down

0 comments on commit 3f53cb4

Please sign in to comment.