diff options
author | Ben Ye <yb532204897@gmail.com> | 2019-12-31 11:19:37 -0500 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2019-12-31 17:19:37 +0100 |
commit | 2477c5c67dff7e7655a9d466450235e9c9eac193 (patch) | |
tree | 198cb44d48f454df765984bc614e1b1972a646e8 /collector/cpu_freebsd.go | |
parent | a80b7d0bc5ee93e704bab22e7592ed8b7d65899e (diff) | |
download | prometheus_node_collector-2477c5c67dff7e7655a9d466450235e9c9eac193.tar.bz2 prometheus_node_collector-2477c5c67dff7e7655a9d466450235e9c9eac193.tar.xz prometheus_node_collector-2477c5c67dff7e7655a9d466450235e9c9eac193.zip |
switch to go-kit/log (#1575)
Signed-off-by: yeya24 <yb532204897@gmail.com>
Diffstat (limited to 'collector/cpu_freebsd.go')
-rw-r--r-- | collector/cpu_freebsd.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index dc3d6a1..41573e4 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go | |||
@@ -21,8 +21,9 @@ import ( | |||
21 | "strconv" | 21 | "strconv" |
22 | "unsafe" | 22 | "unsafe" |
23 | 23 | ||
24 | "github.com/go-kit/kit/log" | ||
25 | "github.com/go-kit/kit/log/level" | ||
24 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
25 | "github.com/prometheus/common/log" | ||
26 | "golang.org/x/sys/unix" | 27 | "golang.org/x/sys/unix" |
27 | ) | 28 | ) |
28 | 29 | ||
@@ -81,8 +82,9 @@ func getCPUTimes() ([]cputime, error) { | |||
81 | } | 82 | } |
82 | 83 | ||
83 | type statCollector struct { | 84 | type statCollector struct { |
84 | cpu typedDesc | 85 | cpu typedDesc |
85 | temp typedDesc | 86 | temp typedDesc |
87 | logger log.Logger | ||
86 | } | 88 | } |
87 | 89 | ||
88 | func init() { | 90 | func init() { |
@@ -90,7 +92,7 @@ func init() { | |||
90 | } | 92 | } |
91 | 93 | ||
92 | // NewStatCollector returns a new Collector exposing CPU stats. | 94 | // NewStatCollector returns a new Collector exposing CPU stats. |
93 | func NewStatCollector() (Collector, error) { | 95 | func NewStatCollector(logger log.Logger) (Collector, error) { |
94 | return &statCollector{ | 96 | return &statCollector{ |
95 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, | 97 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, |
96 | temp: typedDesc{prometheus.NewDesc( | 98 | temp: typedDesc{prometheus.NewDesc( |
@@ -98,6 +100,7 @@ func NewStatCollector() (Collector, error) { | |||
98 | "CPU temperature", | 100 | "CPU temperature", |
99 | []string{"cpu"}, nil, | 101 | []string{"cpu"}, nil, |
100 | ), prometheus.GaugeValue}, | 102 | ), prometheus.GaugeValue}, |
103 | logger: logger, | ||
101 | }, nil | 104 | }, nil |
102 | } | 105 | } |
103 | 106 | ||
@@ -130,11 +133,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { | |||
130 | if err != nil { | 133 | if err != nil { |
131 | if err == unix.ENOENT { | 134 | if err == unix.ENOENT { |
132 | // No temperature information for this CPU | 135 | // No temperature information for this CPU |
133 | log.Debugf("no temperature information for CPU %d", cpu) | 136 | level.Debug(c.logger).Log("msg", "no temperature information for CPU", "cpu", cpu) |
134 | } else { | 137 | } else { |
135 | // Unexpected error | 138 | // Unexpected error |
136 | ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu) | 139 | ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu) |
137 | log.Errorf("failed to query CPU temperature for CPU %d: %s", cpu, err) | 140 | level.Error(c.logger).Log("msg", "failed to query CPU temperature for CPU", "cpu", cpu, "err", err) |
138 | } | 141 | } |
139 | continue | 142 | continue |
140 | } | 143 | } |