mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-03-05 21:00:12 -08:00
Fix cpu freq failure.
This commit is contained in:
parent
a372120527
commit
3f53cb406d
|
@ -126,10 +126,10 @@ func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNodeCollector creates a new NodeCollector.
|
// 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)
|
f := make(map[string]bool)
|
||||||
for _, filter := range filters {
|
for _, filter := range filters {
|
||||||
enabled, exist := enabledCollectors[filter]
|
enabled, exist := config.Collectors[filter]
|
||||||
if !exist {
|
if !exist {
|
||||||
return nil, fmt.Errorf("missing collector: %s", filter)
|
return nil, fmt.Errorf("missing collector: %s", filter)
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ func NewNodeCollector(config *NodeCollectorConfig, enabledCollectors map[string]
|
||||||
}
|
}
|
||||||
collectors := make(map[string]Collector)
|
collectors := make(map[string]Collector)
|
||||||
|
|
||||||
for key, enabled := range enabledCollectors {
|
for key, enabled := range config.Collectors {
|
||||||
if !enabled || (len(f) > 0 && !f[key]) {
|
if !enabled || (len(f) > 0 && !f[key]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,8 @@ type NodeCollectorConfig struct {
|
||||||
TextFile TextFileConfig
|
TextFile TextFileConfig
|
||||||
VmStat VmStatConfig
|
VmStat VmStatConfig
|
||||||
Wifi WifiConfig
|
Wifi WifiConfig
|
||||||
|
|
||||||
|
Collectors map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type WifiConfig struct {
|
type WifiConfig struct {
|
||||||
|
|
|
@ -201,6 +201,8 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
|
||||||
cpu.CacheSize)
|
cpu.CacheSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should only run if CPUFREQ is NOT enabled.
|
||||||
|
if found, enabled := c.config.Collectors["cpufreq"]; found && !enabled {
|
||||||
for _, cpu := range info {
|
for _, cpu := range info {
|
||||||
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
|
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
|
@ -209,6 +211,7 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
|
||||||
cpu.CoreID,
|
cpu.CoreID,
|
||||||
strconv.Itoa(int(cpu.Processor)))
|
strconv.Itoa(int(cpu.Processor)))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(info) != 0 {
|
if len(info) != 0 {
|
||||||
cpu := info[0]
|
cpu := info[0]
|
||||||
|
|
|
@ -102,11 +102,11 @@ type devstatCollector struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("devstat", defaultDisabled,NewDevstatCollector)
|
registerCollector("devstat", defaultDisabled, NewDevstatCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDevstatCollector returns a new Collector exposing Device stats.
|
// 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{
|
return &devstatCollector{
|
||||||
bytesDesc: prometheus.NewDesc(
|
bytesDesc: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
|
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
|
||||||
|
|
|
@ -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
|
// (in which case it will log all the collectors enabled via command-line
|
||||||
// flags).
|
// flags).
|
||||||
func (h *handler) innerHandler(filters ...string) (http.Handler, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create collector: %s", err)
|
return nil, fmt.Errorf("couldn't create collector: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ func main() {
|
||||||
}
|
}
|
||||||
runtime.GOMAXPROCS(*maxProcs)
|
runtime.GOMAXPROCS(*maxProcs)
|
||||||
level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))
|
level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))
|
||||||
|
collectorConfig.Collectors = collector.GetFlagDefaults()
|
||||||
http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, collectorConfig, logger))
|
http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, collectorConfig, logger))
|
||||||
if *metricsPath != "/" {
|
if *metricsPath != "/" {
|
||||||
landingConfig := web.LandingConfig{
|
landingConfig := web.LandingConfig{
|
||||||
|
|
Loading…
Reference in a new issue