Skip to content

Commit

Permalink
Merge pull request #522 from karan/del_labels
Browse files Browse the repository at this point in the history
Remove os_version and kernel_version labels
  • Loading branch information
k8s-ci-robot authored Feb 3, 2021
2 parents 5c1cabf + c2aceee commit f3968f1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 83 deletions.
39 changes: 12 additions & 27 deletions pkg/systemstatsmonitor/cpu_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import (
"github.com/golang/glog"
"github.com/prometheus/procfs"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/load"

ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
"k8s.io/node-problem-detector/pkg/util"
"k8s.io/node-problem-detector/pkg/util/metrics"
)

Expand All @@ -41,8 +39,6 @@ import (
const clockTick float64 = 100.0

type cpuCollector struct {
tags map[string]string

mRunnableTaskCount *metrics.Float64Metric
mUsageTime *metrics.Float64Metric
mCpuLoad1m *metrics.Float64Metric
Expand All @@ -60,20 +56,9 @@ type cpuCollector struct {
}

func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
cc := cpuCollector{tags: map[string]string{}, config: cpuConfig}

kernelVersion, err := host.KernelVersion()
if err != nil {
glog.Fatalf("Failed to retrieve kernel version: %v", err)
}
cc.tags[kernelVersionLabel] = kernelVersion

osVersion, err := util.GetOSVersion()
if err != nil {
glog.Fatalf("Failed to retrieve OS version: %v", err)
}
cc.tags[osVersionLabel] = osVersion
cc := cpuCollector{config: cpuConfig}

var err error
cc.mRunnableTaskCount, err = metrics.NewFloat64Metric(
metrics.CPURunnableTaskCountID,
cpuConfig.MetricsConfigs[string(metrics.CPURunnableTaskCountID)].DisplayName,
Expand Down Expand Up @@ -135,7 +120,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
"Number of forks since boot.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel})
[]string{})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcessesTotal, err)
}
Expand All @@ -146,7 +131,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
"Number of processes currently running.",
"1",
metrics.LastValue,
[]string{osVersionLabel, kernelVersionLabel})
[]string{})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsRunning, err)
}
Expand All @@ -157,7 +142,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
"Number of processes currently blocked.",
"1",
metrics.LastValue,
[]string{osVersionLabel, kernelVersionLabel})
[]string{})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsBlocked, err)
}
Expand All @@ -168,7 +153,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
"Total number of interrupts serviced (cumulative).",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel})
[]string{})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemInterruptsTotal, err)
}
Expand All @@ -179,7 +164,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
"Cumulative time each cpu spent in various stages.",
"ns",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, cpuLabel, stageLabel})
[]string{cpuLabel, stageLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemCPUStat, err)
}
Expand Down Expand Up @@ -259,13 +244,13 @@ func (cc *cpuCollector) recordSystemStats() {
return
}

cc.mSystemProcessesTotal.Record(cc.tags, int64(stats.ProcessCreated))
cc.mSystemProcsRunning.Record(cc.tags, int64(stats.ProcessesRunning))
cc.mSystemProcsBlocked.Record(cc.tags, int64(stats.ProcessesBlocked))
cc.mSystemInterruptsTotal.Record(cc.tags, int64(stats.IRQTotal))
cc.mSystemProcessesTotal.Record(map[string]string{}, int64(stats.ProcessCreated))
cc.mSystemProcsRunning.Record(map[string]string{}, int64(stats.ProcessesRunning))
cc.mSystemProcsBlocked.Record(map[string]string{}, int64(stats.ProcessesBlocked))
cc.mSystemInterruptsTotal.Record(map[string]string{}, int64(stats.IRQTotal))

for i, c := range stats.CPU {
tags := cc.tags
tags := map[string]string{}
tags[cpuLabel] = fmt.Sprintf("cpu%d", i)

tags[stageLabel] = "user"
Expand Down
6 changes: 0 additions & 6 deletions pkg/systemstatsmonitor/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ const featureLabel = "os_feature"
// valueLabel labels the value for the features of the guest os system if required
const valueLabel = "value"

// osVersionLabel labels the OS
const osVersionLabel = "os_version"

// osVersionLabel labels the kernel version
const kernelVersionLabel = "kernel_version"

// interfaceNameLabel labels the network interface name
const interfaceNameLabel = "interface_name"

Expand Down
87 changes: 37 additions & 50 deletions pkg/systemstatsmonitor/net_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ package systemstatsmonitor
import (
"github.com/golang/glog"
"github.com/prometheus/procfs"
"github.com/shirou/gopsutil/host"
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
"k8s.io/node-problem-detector/pkg/util"
"k8s.io/node-problem-detector/pkg/util/metrics"
)

type netCollector struct {
tags map[string]string

mNetDevRxBytes *metrics.Int64Metric
mNetDevRxPackets *metrics.Int64Metric
mNetDevRxErrors *metrics.Int64Metric
Expand All @@ -49,27 +45,17 @@ type netCollector struct {
}

func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
nc := netCollector{tags: map[string]string{}, config: netConfig}

kernelVersion, err := host.KernelVersion()
if err != nil {
glog.Fatalf("Failed to retrieve kernel version: %v", err)
}
nc.tags[kernelVersionLabel] = kernelVersion
nc := netCollector{config: netConfig}

osVersion, err := util.GetOSVersion()
if err != nil {
glog.Fatalf("Failed to retrieve OS version: %v", err)
}
nc.tags[osVersionLabel] = osVersion
var err error

nc.mNetDevRxBytes, err = metrics.NewInt64Metric(
metrics.NetDevRxBytes,
netConfig.MetricsConfigs[string(metrics.NetDevRxBytes)].DisplayName,
"Cumulative count of bytes received.",
"Byte",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxBytes, err)
}
Expand All @@ -80,7 +66,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of packets received.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxPackets, err)
}
Expand All @@ -91,7 +77,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of receive errors encountered.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxErrors, err)
}
Expand All @@ -102,7 +88,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of packets dropped while receiving.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxDropped, err)
}
Expand All @@ -113,7 +99,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of FIFO buffer errors.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxFifo, err)
}
Expand All @@ -124,7 +110,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of packet framing errors.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxFrame, err)
}
Expand All @@ -135,7 +121,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of compressed packets received by the device driver.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxCompressed, err)
}
Expand All @@ -146,7 +132,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of multicast frames received by the device driver.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevRxMulticast, err)
}
Expand All @@ -157,7 +143,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of bytes transmitted.",
"Byte",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxBytes, err)
}
Expand All @@ -168,7 +154,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of packets transmitted.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxPackets, err)
}
Expand All @@ -179,7 +165,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of transmit errors encountered.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxErrors, err)
}
Expand All @@ -190,7 +176,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of packets dropped while transmitting.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxDropped, err)
}
Expand All @@ -201,7 +187,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of FIFO buffer errors.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxFifo, err)
}
Expand All @@ -212,7 +198,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of collisions detected on the interface.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxCollisions, err)
}
Expand All @@ -223,7 +209,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of carrier losses detected by the device driver.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxCarrier, err)
}
Expand All @@ -234,7 +220,7 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig) *netCollector {
"Cumulative count of compressed packets transmitted by the device driver.",
"1",
metrics.Sum,
[]string{osVersionLabel, kernelVersionLabel, interfaceNameLabel})
[]string{interfaceNameLabel})
if err != nil {
glog.Fatalf("Error initializing metric for %q: %v", metrics.NetDevTxCompressed, err)
}
Expand Down Expand Up @@ -300,24 +286,25 @@ func (nc *netCollector) recordNetDev() {
}

for iface, ifaceStats := range stats {
nc.tags[interfaceNameLabel] = iface

nc.mNetDevRxBytes.Record(nc.tags, int64(ifaceStats.RxBytes))
nc.mNetDevRxPackets.Record(nc.tags, int64(ifaceStats.RxPackets))
nc.mNetDevRxErrors.Record(nc.tags, int64(ifaceStats.RxErrors))
nc.mNetDevRxDropped.Record(nc.tags, int64(ifaceStats.RxDropped))
nc.mNetDevRxFifo.Record(nc.tags, int64(ifaceStats.RxFIFO))
nc.mNetDevRxFrame.Record(nc.tags, int64(ifaceStats.RxFrame))
nc.mNetDevRxCompressed.Record(nc.tags, int64(ifaceStats.RxCompressed))
nc.mNetDevRxMulticast.Record(nc.tags, int64(ifaceStats.RxMulticast))
nc.mNetDevTxBytes.Record(nc.tags, int64(ifaceStats.TxBytes))
nc.mNetDevTxPackets.Record(nc.tags, int64(ifaceStats.TxPackets))
nc.mNetDevTxErrors.Record(nc.tags, int64(ifaceStats.TxErrors))
nc.mNetDevTxDropped.Record(nc.tags, int64(ifaceStats.TxDropped))
nc.mNetDevTxFifo.Record(nc.tags, int64(ifaceStats.TxFIFO))
nc.mNetDevTxCollisions.Record(nc.tags, int64(ifaceStats.TxCollisions))
nc.mNetDevTxCarrier.Record(nc.tags, int64(ifaceStats.TxCarrier))
nc.mNetDevTxCompressed.Record(nc.tags, int64(ifaceStats.TxCompressed))
tags := map[string]string{}
tags[interfaceNameLabel] = iface

nc.mNetDevRxBytes.Record(tags, int64(ifaceStats.RxBytes))
nc.mNetDevRxPackets.Record(tags, int64(ifaceStats.RxPackets))
nc.mNetDevRxErrors.Record(tags, int64(ifaceStats.RxErrors))
nc.mNetDevRxDropped.Record(tags, int64(ifaceStats.RxDropped))
nc.mNetDevRxFifo.Record(tags, int64(ifaceStats.RxFIFO))
nc.mNetDevRxFrame.Record(tags, int64(ifaceStats.RxFrame))
nc.mNetDevRxCompressed.Record(tags, int64(ifaceStats.RxCompressed))
nc.mNetDevRxMulticast.Record(tags, int64(ifaceStats.RxMulticast))
nc.mNetDevTxBytes.Record(tags, int64(ifaceStats.TxBytes))
nc.mNetDevTxPackets.Record(tags, int64(ifaceStats.TxPackets))
nc.mNetDevTxErrors.Record(tags, int64(ifaceStats.TxErrors))
nc.mNetDevTxDropped.Record(tags, int64(ifaceStats.TxDropped))
nc.mNetDevTxFifo.Record(tags, int64(ifaceStats.TxFIFO))
nc.mNetDevTxCollisions.Record(tags, int64(ifaceStats.TxCollisions))
nc.mNetDevTxCarrier.Record(tags, int64(ifaceStats.TxCarrier))
nc.mNetDevTxCompressed.Record(tags, int64(ifaceStats.TxCompressed))
}
}

Expand Down

0 comments on commit f3968f1

Please sign in to comment.