@@ -25,7 +25,9 @@ import (
25
25
)
26
26
27
27
func (cc * cpuCollector ) recordLoad () {
28
- if cc .mRunnableTaskCount == nil {
28
+ // don't collect the load metrics if the configs are not present.
29
+ if cc .mRunnableTaskCount == nil &&
30
+ cc .mCpuLoad15m == nil && cc .mCpuLoad1m == nil && cc .mCpuLoad5m == nil {
29
31
return
30
32
}
31
33
@@ -35,49 +37,77 @@ func (cc *cpuCollector) recordLoad() {
35
37
return
36
38
}
37
39
38
- cc .mRunnableTaskCount .Record (map [string ]string {}, loadAvg .Load1 )
39
-
40
- cc .mCpuLoad1m .Record (map [string ]string {}, loadAvg .Load1 )
41
- cc .mCpuLoad5m .Record (map [string ]string {}, loadAvg .Load5 )
42
- cc .mCpuLoad15m .Record (map [string ]string {}, loadAvg .Load15 )
40
+ if cc .mRunnableTaskCount != nil {
41
+ cc .mRunnableTaskCount .Record (map [string ]string {}, loadAvg .Load1 )
42
+ }
43
+ if cc .mCpuLoad1m != nil {
44
+ cc .mCpuLoad1m .Record (map [string ]string {}, loadAvg .Load1 )
45
+ }
46
+ if cc .mCpuLoad5m != nil {
47
+ cc .mCpuLoad5m .Record (map [string ]string {}, loadAvg .Load5 )
48
+ }
49
+ if cc .mCpuLoad15m != nil {
50
+ cc .mCpuLoad15m .Record (map [string ]string {}, loadAvg .Load15 )
51
+ }
43
52
}
44
53
45
54
func (cc * cpuCollector ) recordSystemStats () {
55
+
56
+ // don't collect the load metrics if the configs are not present.
57
+ if cc .mSystemCPUStat == nil && cc .mSystemInterruptsTotal == nil &&
58
+ cc .mSystemProcessesTotal == nil && cc .mSystemProcsBlocked == nil &&
59
+ cc .mSystemProcsRunning == nil {
60
+ return
61
+ }
62
+
46
63
fs , err := procfs .NewFS ("/proc" )
47
64
stats , err := fs .Stat ()
48
65
if err != nil {
49
66
glog .Errorf ("Failed to retrieve cpu/process stats: %v" , err )
50
67
return
51
68
}
52
69
53
- cc .mSystemProcessesTotal .Record (map [string ]string {}, int64 (stats .ProcessCreated ))
54
- cc .mSystemProcsRunning .Record (map [string ]string {}, int64 (stats .ProcessesRunning ))
55
- cc .mSystemProcsBlocked .Record (map [string ]string {}, int64 (stats .ProcessesBlocked ))
56
- cc .mSystemInterruptsTotal .Record (map [string ]string {}, int64 (stats .IRQTotal ))
57
-
58
- for i , c := range stats .CPU {
59
- tags := map [string ]string {}
60
- tags [cpuLabel ] = fmt .Sprintf ("cpu%d" , i )
61
-
62
- tags [stageLabel ] = "user"
63
- cc .mSystemCPUStat .Record (tags , c .User )
64
- tags [stageLabel ] = "nice"
65
- cc .mSystemCPUStat .Record (tags , c .Nice )
66
- tags [stageLabel ] = "system"
67
- cc .mSystemCPUStat .Record (tags , c .System )
68
- tags [stageLabel ] = "idle"
69
- cc .mSystemCPUStat .Record (tags , c .Idle )
70
- tags [stageLabel ] = "iowait"
71
- cc .mSystemCPUStat .Record (tags , c .Iowait )
72
- tags [stageLabel ] = "iRQ"
73
- cc .mSystemCPUStat .Record (tags , c .IRQ )
74
- tags [stageLabel ] = "softIRQ"
75
- cc .mSystemCPUStat .Record (tags , c .SoftIRQ )
76
- tags [stageLabel ] = "steal"
77
- cc .mSystemCPUStat .Record (tags , c .Steal )
78
- tags [stageLabel ] = "guest"
79
- cc .mSystemCPUStat .Record (tags , c .Guest )
80
- tags [stageLabel ] = "guestNice"
81
- cc .mSystemCPUStat .Record (tags , c .GuestNice )
70
+ if cc .mSystemProcessesTotal != nil {
71
+ cc .mSystemProcessesTotal .Record (map [string ]string {}, int64 (stats .ProcessCreated ))
72
+ }
73
+
74
+ if cc .mSystemProcsRunning != nil {
75
+ cc .mSystemProcsRunning .Record (map [string ]string {}, int64 (stats .ProcessesRunning ))
76
+ }
77
+
78
+ if cc .mSystemProcsBlocked != nil {
79
+ cc .mSystemProcsBlocked .Record (map [string ]string {}, int64 (stats .ProcessesBlocked ))
80
+ }
81
+
82
+ if cc .mSystemInterruptsTotal != nil {
83
+ cc .mSystemInterruptsTotal .Record (map [string ]string {}, int64 (stats .IRQTotal ))
84
+ }
85
+
86
+ if cc .mSystemCPUStat != nil {
87
+ for i , c := range stats .CPU {
88
+ tags := map [string ]string {}
89
+ tags [cpuLabel ] = fmt .Sprintf ("cpu%d" , i )
90
+
91
+ tags [stageLabel ] = "user"
92
+ cc .mSystemCPUStat .Record (tags , c .User )
93
+ tags [stageLabel ] = "nice"
94
+ cc .mSystemCPUStat .Record (tags , c .Nice )
95
+ tags [stageLabel ] = "system"
96
+ cc .mSystemCPUStat .Record (tags , c .System )
97
+ tags [stageLabel ] = "idle"
98
+ cc .mSystemCPUStat .Record (tags , c .Idle )
99
+ tags [stageLabel ] = "iowait"
100
+ cc .mSystemCPUStat .Record (tags , c .Iowait )
101
+ tags [stageLabel ] = "iRQ"
102
+ cc .mSystemCPUStat .Record (tags , c .IRQ )
103
+ tags [stageLabel ] = "softIRQ"
104
+ cc .mSystemCPUStat .Record (tags , c .SoftIRQ )
105
+ tags [stageLabel ] = "steal"
106
+ cc .mSystemCPUStat .Record (tags , c .Steal )
107
+ tags [stageLabel ] = "guest"
108
+ cc .mSystemCPUStat .Record (tags , c .Guest )
109
+ tags [stageLabel ] = "guestNice"
110
+ cc .mSystemCPUStat .Record (tags , c .GuestNice )
111
+ }
82
112
}
83
113
}
0 commit comments