Skip to content

Commit 3f53cb4

Browse files
committed
Fix cpu freq failure.
1 parent a372120 commit 3f53cb4

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

collector/collector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error
126126
}
127127

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

143-
for key, enabled := range enabledCollectors {
143+
for key, enabled := range config.Collectors {
144144
if !enabled || (len(f) > 0 && !f[key]) {
145145
continue
146146
}

collector/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type NodeCollectorConfig struct {
4242
TextFile TextFileConfig
4343
VmStat VmStatConfig
4444
Wifi WifiConfig
45+
46+
Collectors map[string]bool
4547
}
4648

4749
type WifiConfig struct {

collector/cpu_linux.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,16 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
201201
cpu.CacheSize)
202202
}
203203

204-
for _, cpu := range info {
205-
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
206-
prometheus.GaugeValue,
207-
cpu.CPUMHz*1e6,
208-
cpu.PhysicalID,
209-
cpu.CoreID,
210-
strconv.Itoa(int(cpu.Processor)))
204+
// This should only run if CPUFREQ is NOT enabled.
205+
if found, enabled := c.config.Collectors["cpufreq"]; found && !enabled {
206+
for _, cpu := range info {
207+
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
208+
prometheus.GaugeValue,
209+
cpu.CPUMHz*1e6,
210+
cpu.PhysicalID,
211+
cpu.CoreID,
212+
strconv.Itoa(int(cpu.Processor)))
213+
}
211214
}
212215

213216
if len(info) != 0 {

collector/devstat_dragonfly.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ type devstatCollector struct {
102102
}
103103

104104
func init() {
105-
registerCollector("devstat", defaultDisabled,NewDevstatCollector)
105+
registerCollector("devstat", defaultDisabled, NewDevstatCollector)
106106
}
107107

108108
// NewDevstatCollector returns a new Collector exposing Device stats.
109-
func NewDevstatCollector(config *NodeCollectorConfiglogger log.Logger) (Collector, error) {
109+
func NewDevstatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
110110
return &devstatCollector{
111111
bytesDesc: prometheus.NewDesc(
112112
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),

node_exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
102102
// (in which case it will log all the collectors enabled via command-line
103103
// flags).
104104
func (h *handler) innerHandler(filters ...string) (http.Handler, error) {
105-
nc, err := collector.NewNodeCollector(h.collectorConfig, collector.GetFlagDefaults(), h.logger, filters...)
105+
nc, err := collector.NewNodeCollector(h.collectorConfig, h.logger, filters...)
106106
if err != nil {
107107
return nil, fmt.Errorf("couldn't create collector: %s", err)
108108
}
@@ -188,7 +188,7 @@ func main() {
188188
}
189189
runtime.GOMAXPROCS(*maxProcs)
190190
level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))
191-
191+
collectorConfig.Collectors = collector.GetFlagDefaults()
192192
http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, collectorConfig, logger))
193193
if *metricsPath != "/" {
194194
landingConfig := web.LandingConfig{

0 commit comments

Comments
 (0)