@@ -19,15 +19,11 @@ package systemstatsmonitor
19
19
import (
20
20
"github.com/golang/glog"
21
21
"github.com/prometheus/procfs"
22
- "github.com/shirou/gopsutil/host"
23
22
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
24
- "k8s.io/node-problem-detector/pkg/util"
25
23
"k8s.io/node-problem-detector/pkg/util/metrics"
26
24
)
27
25
28
26
type netCollector struct {
29
- tags map [string ]string
30
-
31
27
mNetDevRxBytes * metrics.Int64Metric
32
28
mNetDevRxPackets * metrics.Int64Metric
33
29
mNetDevRxErrors * metrics.Int64Metric
@@ -49,27 +45,17 @@ type netCollector struct {
49
45
}
50
46
51
47
func NewNetCollectorOrDie (netConfig * ssmtypes.NetStatsConfig ) * netCollector {
52
- nc := netCollector {tags : map [string ]string {}, config : netConfig }
53
-
54
- kernelVersion , err := host .KernelVersion ()
55
- if err != nil {
56
- glog .Fatalf ("Failed to retrieve kernel version: %v" , err )
57
- }
58
- nc .tags [kernelVersionLabel ] = kernelVersion
48
+ nc := netCollector {config : netConfig }
59
49
60
- osVersion , err := util .GetOSVersion ()
61
- if err != nil {
62
- glog .Fatalf ("Failed to retrieve OS version: %v" , err )
63
- }
64
- nc .tags [osVersionLabel ] = osVersion
50
+ var err error
65
51
66
52
nc .mNetDevRxBytes , err = metrics .NewInt64Metric (
67
53
metrics .NetDevRxBytes ,
68
54
netConfig .MetricsConfigs [string (metrics .NetDevRxBytes )].DisplayName ,
69
55
"Cumulative count of bytes received." ,
70
56
"Byte" ,
71
57
metrics .Sum ,
72
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
58
+ []string {interfaceNameLabel })
73
59
if err != nil {
74
60
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxBytes , err )
75
61
}
@@ -80,7 +66,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
80
66
"Cumulative count of packets received." ,
81
67
"1" ,
82
68
metrics .Sum ,
83
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
69
+ []string {interfaceNameLabel })
84
70
if err != nil {
85
71
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxPackets , err )
86
72
}
@@ -91,7 +77,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
91
77
"Cumulative count of receive errors encountered." ,
92
78
"1" ,
93
79
metrics .Sum ,
94
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
80
+ []string {interfaceNameLabel })
95
81
if err != nil {
96
82
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxErrors , err )
97
83
}
@@ -102,7 +88,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
102
88
"Cumulative count of packets dropped while receiving." ,
103
89
"1" ,
104
90
metrics .Sum ,
105
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
91
+ []string {interfaceNameLabel })
106
92
if err != nil {
107
93
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxDropped , err )
108
94
}
@@ -113,7 +99,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
113
99
"Cumulative count of FIFO buffer errors." ,
114
100
"1" ,
115
101
metrics .Sum ,
116
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
102
+ []string {interfaceNameLabel })
117
103
if err != nil {
118
104
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxFifo , err )
119
105
}
@@ -124,7 +110,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
124
110
"Cumulative count of packet framing errors." ,
125
111
"1" ,
126
112
metrics .Sum ,
127
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
113
+ []string {interfaceNameLabel })
128
114
if err != nil {
129
115
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxFrame , err )
130
116
}
@@ -135,7 +121,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
135
121
"Cumulative count of compressed packets received by the device driver." ,
136
122
"1" ,
137
123
metrics .Sum ,
138
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
124
+ []string {interfaceNameLabel })
139
125
if err != nil {
140
126
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxCompressed , err )
141
127
}
@@ -146,7 +132,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
146
132
"Cumulative count of multicast frames received by the device driver." ,
147
133
"1" ,
148
134
metrics .Sum ,
149
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
135
+ []string {interfaceNameLabel })
150
136
if err != nil {
151
137
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevRxMulticast , err )
152
138
}
@@ -157,7 +143,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
157
143
"Cumulative count of bytes transmitted." ,
158
144
"Byte" ,
159
145
metrics .Sum ,
160
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
146
+ []string {interfaceNameLabel })
161
147
if err != nil {
162
148
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxBytes , err )
163
149
}
@@ -168,7 +154,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
168
154
"Cumulative count of packets transmitted." ,
169
155
"1" ,
170
156
metrics .Sum ,
171
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
157
+ []string {interfaceNameLabel })
172
158
if err != nil {
173
159
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxPackets , err )
174
160
}
@@ -179,7 +165,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
179
165
"Cumulative count of transmit errors encountered." ,
180
166
"1" ,
181
167
metrics .Sum ,
182
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
168
+ []string {interfaceNameLabel })
183
169
if err != nil {
184
170
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxErrors , err )
185
171
}
@@ -190,7 +176,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
190
176
"Cumulative count of packets dropped while transmitting." ,
191
177
"1" ,
192
178
metrics .Sum ,
193
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
179
+ []string {interfaceNameLabel })
194
180
if err != nil {
195
181
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxDropped , err )
196
182
}
@@ -201,7 +187,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
201
187
"Cumulative count of FIFO buffer errors." ,
202
188
"1" ,
203
189
metrics .Sum ,
204
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
190
+ []string {interfaceNameLabel })
205
191
if err != nil {
206
192
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxFifo , err )
207
193
}
@@ -212,7 +198,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
212
198
"Cumulative count of collisions detected on the interface." ,
213
199
"1" ,
214
200
metrics .Sum ,
215
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
201
+ []string {interfaceNameLabel })
216
202
if err != nil {
217
203
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxCollisions , err )
218
204
}
@@ -223,7 +209,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
223
209
"Cumulative count of carrier losses detected by the device driver." ,
224
210
"1" ,
225
211
metrics .Sum ,
226
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
212
+ []string {interfaceNameLabel })
227
213
if err != nil {
228
214
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxCarrier , err )
229
215
}
@@ -234,7 +220,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
234
220
"Cumulative count of compressed packets transmitted by the device driver." ,
235
221
"1" ,
236
222
metrics .Sum ,
237
- []string {osVersionLabel , kernelVersionLabel , interfaceNameLabel })
223
+ []string {interfaceNameLabel })
238
224
if err != nil {
239
225
glog .Fatalf ("Error initializing metric for %q: %v" , metrics .NetDevTxCompressed , err )
240
226
}
@@ -300,24 +286,25 @@ func (nc *netCollector) recordNetDev() {
300
286
}
301
287
302
288
for iface , ifaceStats := range stats {
303
- nc .tags [interfaceNameLabel ] = iface
304
-
305
- nc .mNetDevRxBytes .Record (nc .tags , int64 (ifaceStats .RxBytes ))
306
- nc .mNetDevRxPackets .Record (nc .tags , int64 (ifaceStats .RxPackets ))
307
- nc .mNetDevRxErrors .Record (nc .tags , int64 (ifaceStats .RxErrors ))
308
- nc .mNetDevRxDropped .Record (nc .tags , int64 (ifaceStats .RxDropped ))
309
- nc .mNetDevRxFifo .Record (nc .tags , int64 (ifaceStats .RxFIFO ))
310
- nc .mNetDevRxFrame .Record (nc .tags , int64 (ifaceStats .RxFrame ))
311
- nc .mNetDevRxCompressed .Record (nc .tags , int64 (ifaceStats .RxCompressed ))
312
- nc .mNetDevRxMulticast .Record (nc .tags , int64 (ifaceStats .RxMulticast ))
313
- nc .mNetDevTxBytes .Record (nc .tags , int64 (ifaceStats .TxBytes ))
314
- nc .mNetDevTxPackets .Record (nc .tags , int64 (ifaceStats .TxPackets ))
315
- nc .mNetDevTxErrors .Record (nc .tags , int64 (ifaceStats .TxErrors ))
316
- nc .mNetDevTxDropped .Record (nc .tags , int64 (ifaceStats .TxDropped ))
317
- nc .mNetDevTxFifo .Record (nc .tags , int64 (ifaceStats .TxFIFO ))
318
- nc .mNetDevTxCollisions .Record (nc .tags , int64 (ifaceStats .TxCollisions ))
319
- nc .mNetDevTxCarrier .Record (nc .tags , int64 (ifaceStats .TxCarrier ))
320
- nc .mNetDevTxCompressed .Record (nc .tags , int64 (ifaceStats .TxCompressed ))
289
+ tags := map [string ]string {}
290
+ tags [interfaceNameLabel ] = iface
291
+
292
+ nc .mNetDevRxBytes .Record (tags , int64 (ifaceStats .RxBytes ))
293
+ nc .mNetDevRxPackets .Record (tags , int64 (ifaceStats .RxPackets ))
294
+ nc .mNetDevRxErrors .Record (tags , int64 (ifaceStats .RxErrors ))
295
+ nc .mNetDevRxDropped .Record (tags , int64 (ifaceStats .RxDropped ))
296
+ nc .mNetDevRxFifo .Record (tags , int64 (ifaceStats .RxFIFO ))
297
+ nc .mNetDevRxFrame .Record (tags , int64 (ifaceStats .RxFrame ))
298
+ nc .mNetDevRxCompressed .Record (tags , int64 (ifaceStats .RxCompressed ))
299
+ nc .mNetDevRxMulticast .Record (tags , int64 (ifaceStats .RxMulticast ))
300
+ nc .mNetDevTxBytes .Record (tags , int64 (ifaceStats .TxBytes ))
301
+ nc .mNetDevTxPackets .Record (tags , int64 (ifaceStats .TxPackets ))
302
+ nc .mNetDevTxErrors .Record (tags , int64 (ifaceStats .TxErrors ))
303
+ nc .mNetDevTxDropped .Record (tags , int64 (ifaceStats .TxDropped ))
304
+ nc .mNetDevTxFifo .Record (tags , int64 (ifaceStats .TxFIFO ))
305
+ nc .mNetDevTxCollisions .Record (tags , int64 (ifaceStats .TxCollisions ))
306
+ nc .mNetDevTxCarrier .Record (tags , int64 (ifaceStats .TxCarrier ))
307
+ nc .mNetDevTxCompressed .Record (tags , int64 (ifaceStats .TxCompressed ))
321
308
}
322
309
}
323
310
0 commit comments