Skip to content

Commit f3968f1

Browse files
authored
Merge pull request #522 from karan/del_labels
Remove os_version and kernel_version labels
2 parents 5c1cabf + c2aceee commit f3968f1

File tree

3 files changed

+49
-83
lines changed

3 files changed

+49
-83
lines changed

pkg/systemstatsmonitor/cpu_collector.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222
"github.com/golang/glog"
2323
"github.com/prometheus/procfs"
2424
"github.com/shirou/gopsutil/cpu"
25-
"github.com/shirou/gopsutil/host"
2625
"github.com/shirou/gopsutil/load"
2726

2827
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
29-
"k8s.io/node-problem-detector/pkg/util"
3028
"k8s.io/node-problem-detector/pkg/util/metrics"
3129
)
3230

@@ -41,8 +39,6 @@ import (
4139
const clockTick float64 = 100.0
4240

4341
type cpuCollector struct {
44-
tags map[string]string
45-
4642
mRunnableTaskCount *metrics.Float64Metric
4743
mUsageTime *metrics.Float64Metric
4844
mCpuLoad1m *metrics.Float64Metric
@@ -60,20 +56,9 @@ type cpuCollector struct {
6056
}
6157

6258
func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
63-
cc := cpuCollector{tags: map[string]string{}, config: cpuConfig}
64-
65-
kernelVersion, err := host.KernelVersion()
66-
if err != nil {
67-
glog.Fatalf("Failed to retrieve kernel version: %v", err)
68-
}
69-
cc.tags[kernelVersionLabel] = kernelVersion
70-
71-
osVersion, err := util.GetOSVersion()
72-
if err != nil {
73-
glog.Fatalf("Failed to retrieve OS version: %v", err)
74-
}
75-
cc.tags[osVersionLabel] = osVersion
59+
cc := cpuCollector{config: cpuConfig}
7660

61+
var err error
7762
cc.mRunnableTaskCount, err = metrics.NewFloat64Metric(
7863
metrics.CPURunnableTaskCountID,
7964
cpuConfig.MetricsConfigs[string(metrics.CPURunnableTaskCountID)].DisplayName,
@@ -135,7 +120,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
135120
"Number of forks since boot.",
136121
"1",
137122
metrics.Sum,
138-
[]string{osVersionLabel, kernelVersionLabel})
123+
[]string{})
139124
if err != nil {
140125
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcessesTotal, err)
141126
}
@@ -146,7 +131,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
146131
"Number of processes currently running.",
147132
"1",
148133
metrics.LastValue,
149-
[]string{osVersionLabel, kernelVersionLabel})
134+
[]string{})
150135
if err != nil {
151136
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsRunning, err)
152137
}
@@ -157,7 +142,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
157142
"Number of processes currently blocked.",
158143
"1",
159144
metrics.LastValue,
160-
[]string{osVersionLabel, kernelVersionLabel})
145+
[]string{})
161146
if err != nil {
162147
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsBlocked, err)
163148
}
@@ -168,7 +153,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
168153
"Total number of interrupts serviced (cumulative).",
169154
"1",
170155
metrics.Sum,
171-
[]string{osVersionLabel, kernelVersionLabel})
156+
[]string{})
172157
if err != nil {
173158
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemInterruptsTotal, err)
174159
}
@@ -179,7 +164,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
179164
"Cumulative time each cpu spent in various stages.",
180165
"ns",
181166
metrics.Sum,
182-
[]string{osVersionLabel, kernelVersionLabel, cpuLabel, stageLabel})
167+
[]string{cpuLabel, stageLabel})
183168
if err != nil {
184169
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemCPUStat, err)
185170
}
@@ -259,13 +244,13 @@ func (cc *cpuCollector) recordSystemStats() {
259244
return
260245
}
261246

262-
cc.mSystemProcessesTotal.Record(cc.tags, int64(stats.ProcessCreated))
263-
cc.mSystemProcsRunning.Record(cc.tags, int64(stats.ProcessesRunning))
264-
cc.mSystemProcsBlocked.Record(cc.tags, int64(stats.ProcessesBlocked))
265-
cc.mSystemInterruptsTotal.Record(cc.tags, int64(stats.IRQTotal))
247+
cc.mSystemProcessesTotal.Record(map[string]string{}, int64(stats.ProcessCreated))
248+
cc.mSystemProcsRunning.Record(map[string]string{}, int64(stats.ProcessesRunning))
249+
cc.mSystemProcsBlocked.Record(map[string]string{}, int64(stats.ProcessesBlocked))
250+
cc.mSystemInterruptsTotal.Record(map[string]string{}, int64(stats.IRQTotal))
266251

267252
for i, c := range stats.CPU {
268-
tags := cc.tags
253+
tags := map[string]string{}
269254
tags[cpuLabel] = fmt.Sprintf("cpu%d", i)
270255

271256
tags[stageLabel] = "user"

pkg/systemstatsmonitor/labels.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ const featureLabel = "os_feature"
3737
// valueLabel labels the value for the features of the guest os system if required
3838
const valueLabel = "value"
3939

40-
// osVersionLabel labels the OS
41-
const osVersionLabel = "os_version"
42-
43-
// osVersionLabel labels the kernel version
44-
const kernelVersionLabel = "kernel_version"
45-
4640
// interfaceNameLabel labels the network interface name
4741
const interfaceNameLabel = "interface_name"
4842

pkg/systemstatsmonitor/net_collector.go

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ package systemstatsmonitor
1919
import (
2020
"github.com/golang/glog"
2121
"github.com/prometheus/procfs"
22-
"github.com/shirou/gopsutil/host"
2322
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
24-
"k8s.io/node-problem-detector/pkg/util"
2523
"k8s.io/node-problem-detector/pkg/util/metrics"
2624
)
2725

2826
type netCollector struct {
29-
tags map[string]string
30-
3127
mNetDevRxBytes *metrics.Int64Metric
3228
mNetDevRxPackets *metrics.Int64Metric
3329
mNetDevRxErrors *metrics.Int64Metric
@@ -49,27 +45,17 @@ type netCollector struct {
4945
}
5046

5147
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}
5949

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
6551

6652
nc.mNetDevRxBytes, err = metrics.NewInt64Metric(
6753
metrics.NetDevRxBytes,
6854
netConfig.MetricsConfigs[string(metrics.NetDevRxBytes)].DisplayName,
6955
"Cumulative count of bytes received.",
7056
"Byte",
7157
metrics.Sum,
72-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
58+
[]string{interfaceNameLabel})
7359
if err != nil {
7460
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxBytes, err)
7561
}
@@ -80,7 +66,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
8066
"Cumulative count of packets received.",
8167
"1",
8268
metrics.Sum,
83-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
69+
[]string{interfaceNameLabel})
8470
if err != nil {
8571
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxPackets, err)
8672
}
@@ -91,7 +77,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
9177
"Cumulative count of receive errors encountered.",
9278
"1",
9379
metrics.Sum,
94-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
80+
[]string{interfaceNameLabel})
9581
if err != nil {
9682
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxErrors, err)
9783
}
@@ -102,7 +88,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
10288
"Cumulative count of packets dropped while receiving.",
10389
"1",
10490
metrics.Sum,
105-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
91+
[]string{interfaceNameLabel})
10692
if err != nil {
10793
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxDropped, err)
10894
}
@@ -113,7 +99,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
11399
"Cumulative count of FIFO buffer errors.",
114100
"1",
115101
metrics.Sum,
116-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
102+
[]string{interfaceNameLabel})
117103
if err != nil {
118104
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxFifo, err)
119105
}
@@ -124,7 +110,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
124110
"Cumulative count of packet framing errors.",
125111
"1",
126112
metrics.Sum,
127-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
113+
[]string{interfaceNameLabel})
128114
if err != nil {
129115
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxFrame, err)
130116
}
@@ -135,7 +121,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
135121
"Cumulative count of compressed packets received by the device driver.",
136122
"1",
137123
metrics.Sum,
138-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
124+
[]string{interfaceNameLabel})
139125
if err != nil {
140126
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxCompressed, err)
141127
}
@@ -146,7 +132,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
146132
"Cumulative count of multicast frames received by the device driver.",
147133
"1",
148134
metrics.Sum,
149-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
135+
[]string{interfaceNameLabel})
150136
if err != nil {
151137
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxMulticast, err)
152138
}
@@ -157,7 +143,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
157143
"Cumulative count of bytes transmitted.",
158144
"Byte",
159145
metrics.Sum,
160-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
146+
[]string{interfaceNameLabel})
161147
if err != nil {
162148
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxBytes, err)
163149
}
@@ -168,7 +154,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
168154
"Cumulative count of packets transmitted.",
169155
"1",
170156
metrics.Sum,
171-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
157+
[]string{interfaceNameLabel})
172158
if err != nil {
173159
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxPackets, err)
174160
}
@@ -179,7 +165,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
179165
"Cumulative count of transmit errors encountered.",
180166
"1",
181167
metrics.Sum,
182-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
168+
[]string{interfaceNameLabel})
183169
if err != nil {
184170
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxErrors, err)
185171
}
@@ -190,7 +176,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
190176
"Cumulative count of packets dropped while transmitting.",
191177
"1",
192178
metrics.Sum,
193-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
179+
[]string{interfaceNameLabel})
194180
if err != nil {
195181
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxDropped, err)
196182
}
@@ -201,7 +187,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
201187
"Cumulative count of FIFO buffer errors.",
202188
"1",
203189
metrics.Sum,
204-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
190+
[]string{interfaceNameLabel})
205191
if err != nil {
206192
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxFifo, err)
207193
}
@@ -212,7 +198,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
212198
"Cumulative count of collisions detected on the interface.",
213199
"1",
214200
metrics.Sum,
215-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
201+
[]string{interfaceNameLabel})
216202
if err != nil {
217203
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxCollisions, err)
218204
}
@@ -223,7 +209,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
223209
"Cumulative count of carrier losses detected by the device driver.",
224210
"1",
225211
metrics.Sum,
226-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
212+
[]string{interfaceNameLabel})
227213
if err != nil {
228214
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxCarrier, err)
229215
}
@@ -234,7 +220,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
234220
"Cumulative count of compressed packets transmitted by the device driver.",
235221
"1",
236222
metrics.Sum,
237-
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
223+
[]string{interfaceNameLabel})
238224
if err != nil {
239225
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxCompressed, err)
240226
}
@@ -300,24 +286,25 @@ func (nc *netCollector) recordNetDev() {
300286
}
301287

302288
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))
321308
}
322309
}
323310

0 commit comments

Comments
 (0)