aboutsummaryrefslogtreecommitdiff
path: root/collector/perf_linux.go
diff options
context:
space:
mode:
authorBen Ye <yb532204897@gmail.com>2019-12-31 11:19:37 -0500
committerBen Kochie <superq@gmail.com>2019-12-31 17:19:37 +0100
commit2477c5c67dff7e7655a9d466450235e9c9eac193 (patch)
tree198cb44d48f454df765984bc614e1b1972a646e8 /collector/perf_linux.go
parenta80b7d0bc5ee93e704bab22e7592ed8b7d65899e (diff)
downloadprometheus_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/perf_linux.go')
-rw-r--r--collector/perf_linux.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/collector/perf_linux.go b/collector/perf_linux.go
index 0ab7b84..0e8a3cc 100644
--- a/collector/perf_linux.go
+++ b/collector/perf_linux.go
@@ -17,7 +17,8 @@ import (
17 "fmt" 17 "fmt"
18 "runtime" 18 "runtime"
19 19
20 perf "github.com/hodgesds/perf-utils" 20 "github.com/go-kit/kit/log"
21 "github.com/hodgesds/perf-utils"
21 "github.com/prometheus/client_golang/prometheus" 22 "github.com/prometheus/client_golang/prometheus"
22) 23)
23 24
@@ -29,7 +30,7 @@ func init() {
29 registerCollector(perfSubsystem, defaultDisabled, NewPerfCollector) 30 registerCollector(perfSubsystem, defaultDisabled, NewPerfCollector)
30} 31}
31 32
32// perfCollector is a Collecter that uses the perf subsystem to collect 33// perfCollector is a Collector that uses the perf subsystem to collect
33// metrics. It uses perf_event_open an ioctls for profiling. Due to the fact 34// metrics. It uses perf_event_open an ioctls for profiling. Due to the fact
34// that the perf subsystem is highly dependent on kernel configuration and 35// that the perf subsystem is highly dependent on kernel configuration and
35// settings not all profiler values may be exposed on the target system at any 36// settings not all profiler values may be exposed on the target system at any
@@ -39,34 +40,36 @@ type perfCollector struct {
39 perfSwProfilers map[int]perf.SoftwareProfiler 40 perfSwProfilers map[int]perf.SoftwareProfiler
40 perfCacheProfilers map[int]perf.CacheProfiler 41 perfCacheProfilers map[int]perf.CacheProfiler
41 desc map[string]*prometheus.Desc 42 desc map[string]*prometheus.Desc
43 logger log.Logger
42} 44}
43 45
44// NewPerfCollector returns a new perf based collector, it creates a profiler 46// NewPerfCollector returns a new perf based collector, it creates a profiler
45// per CPU. 47// per CPU.
46func NewPerfCollector() (Collector, error) { 48func NewPerfCollector(logger log.Logger) (Collector, error) {
47 collector := &perfCollector{ 49 c := &perfCollector{
48 perfHwProfilers: map[int]perf.HardwareProfiler{}, 50 perfHwProfilers: map[int]perf.HardwareProfiler{},
49 perfSwProfilers: map[int]perf.SoftwareProfiler{}, 51 perfSwProfilers: map[int]perf.SoftwareProfiler{},
50 perfCacheProfilers: map[int]perf.CacheProfiler{}, 52 perfCacheProfilers: map[int]perf.CacheProfiler{},
53 logger: logger,
51 } 54 }
52 ncpus := runtime.NumCPU() 55 ncpus := runtime.NumCPU()
53 for i := 0; i < ncpus; i++ { 56 for i := 0; i < ncpus; i++ {
54 // Use -1 to profile all processes on the CPU, see: 57 // Use -1 to profile all processes on the CPU, see:
55 // man perf_event_open 58 // man perf_event_open
56 collector.perfHwProfilers[i] = perf.NewHardwareProfiler(-1, i) 59 c.perfHwProfilers[i] = perf.NewHardwareProfiler(-1, i)
57 if err := collector.perfHwProfilers[i].Start(); err != nil { 60 if err := c.perfHwProfilers[i].Start(); err != nil {
58 return collector, err 61 return c, err
59 } 62 }
60 collector.perfSwProfilers[i] = perf.NewSoftwareProfiler(-1, i) 63 c.perfSwProfilers[i] = perf.NewSoftwareProfiler(-1, i)
61 if err := collector.perfSwProfilers[i].Start(); err != nil { 64 if err := c.perfSwProfilers[i].Start(); err != nil {
62 return collector, err 65 return c, err
63 } 66 }
64 collector.perfCacheProfilers[i] = perf.NewCacheProfiler(-1, i) 67 c.perfCacheProfilers[i] = perf.NewCacheProfiler(-1, i)
65 if err := collector.perfCacheProfilers[i].Start(); err != nil { 68 if err := c.perfCacheProfilers[i].Start(); err != nil {
66 return collector, err 69 return c, err
67 } 70 }
68 } 71 }
69 collector.desc = map[string]*prometheus.Desc{ 72 c.desc = map[string]*prometheus.Desc{
70 "cpucycles_total": prometheus.NewDesc( 73 "cpucycles_total": prometheus.NewDesc(
71 prometheus.BuildFQName( 74 prometheus.BuildFQName(
72 namespace, 75 namespace,
@@ -309,7 +312,7 @@ func NewPerfCollector() (Collector, error) {
309 ), 312 ),
310 } 313 }
311 314
312 return collector, nil 315 return c, nil
313} 316}
314 317
315// Update implements the Collector interface and will collect metrics per CPU. 318// Update implements the Collector interface and will collect metrics per CPU.