Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kubeletstats metrics according to semantic conventions #475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions receiver/kubeletstatsreceiver/kubelet/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type metricDataAccumulator struct {
}

const (
k8sPrefix = "k8s/"
nodePrefix = k8sPrefix + "node/"
podPrefix = k8sPrefix + "pod/"
containerPrefix = k8sPrefix + "container/"
k8sPrefix = "k8s."
nodePrefix = k8sPrefix + "node."
podPrefix = k8sPrefix + "pod."
containerPrefix = "container."
)

func (a *metricDataAccumulator) nodeStats(s stats.NodeStats) {
Expand Down
7 changes: 4 additions & 3 deletions receiver/kubeletstatsreceiver/kubelet/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func cpuUsageMetric(prefix string, s *stats.CPUStats) *metricspb.Metric {
if nanoCores == nil {
return nil
}
value := float64(*nanoCores) / 1_000_000
return doubleGauge(prefix+"cpu/usage", "%", &value)
value := float64(*nanoCores) / 1_000_000_000
return doubleGauge(prefix+"cpu.utilization", "1", &value)
}

func cpuCumulativeUsageMetric(prefix string, s *stats.CPUStats) *metricspb.Metric {
return cumulativeInt(prefix+"cpu/cumulative", "ns", s.UsageCoreNanoSeconds)
value := float64(*s.UsageCoreNanoSeconds) / 1_000_000_000
return cumulativeDouble(prefix+"cpu.time", "s", &value)
}
9 changes: 7 additions & 2 deletions receiver/kubeletstatsreceiver/kubelet/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ func fsMetrics(prefix string, s *stats.FsStats) []*metricspb.Metric {
return applyCurrentTime([]*metricspb.Metric{
fsAvailableMetric(prefix, s),
fsCapacityMetric(prefix, s),
fsUsedMetric(prefix, s),
}, s.Time.Time)
}

func fsAvailableMetric(prefix string, s *stats.FsStats) *metricspb.Metric {
return intGauge(prefix+"fs/available", "By", s.AvailableBytes)
return intGauge(prefix+"filesystem.available", "By", s.AvailableBytes)
}

func fsCapacityMetric(prefix string, s *stats.FsStats) *metricspb.Metric {
return intGauge(prefix+"fs/capacity", "By", s.CapacityBytes)
return intGauge(prefix+"filesystem.capacity", "By", s.CapacityBytes)
}

func fsUsedMetric(prefix string, s *stats.FsStats) *metricspb.Metric {
return intGauge(prefix+"filesystem.usage", "By", s.UsedBytes)
}
6 changes: 3 additions & 3 deletions receiver/kubeletstatsreceiver/kubelet/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func memMetrics(prefix string, s *stats.MemoryStats) []*metricspb.Metric {
}

func memAvailableMetric(prefix string, s *stats.MemoryStats) *metricspb.Metric {
return intGauge(prefix+"mem/available", "By", s.AvailableBytes)
return intGauge(prefix+"memory.available", "By", s.AvailableBytes)
}

func memUsageMetric(prefix string, s *stats.MemoryStats) *metricspb.Metric {
return intGauge(prefix+"mem/usage", "By", s.UsageBytes)
return intGauge(prefix+"memory.usage", "By", s.UsageBytes)
}

func memRssMetric(prefix string, s *stats.MemoryStats) *metricspb.Metric {
return intGauge(prefix+"mem/rss", "By", s.RSSBytes)
return intGauge(prefix+"memory.rss", "By", s.RSSBytes)
}
22 changes: 18 additions & 4 deletions receiver/kubeletstatsreceiver/kubelet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,33 @@ func networkMetrics(prefix string, s *stats.NetworkStats) []*metricspb.Metric {
return applyCurrentTime([]*metricspb.Metric{
rxBytesMetric(prefix, s),
txBytesMetric(prefix, s),
rxErrorsMetric(prefix, s),
txErrorsMetric(prefix, s),
}, s.Time.Time)
}

const directionLabel = "direction"

func rxBytesMetric(prefix string, s *stats.NetworkStats) *metricspb.Metric {
metric := cumulativeInt(prefix+"network", "By", s.RxBytes)
applyLabels(metric, map[string]string{"interface": s.Name, directionLabel: "received"})
metric := cumulativeInt(prefix+"network.io", "By", s.RxBytes)
applyLabels(metric, map[string]string{"interface": s.Name, directionLabel: "receive"})
return metric
}

func txBytesMetric(prefix string, s *stats.NetworkStats) *metricspb.Metric {
metric := cumulativeInt(prefix+"network", "By", s.TxBytes)
applyLabels(metric, map[string]string{"interface": s.Name, directionLabel: "transmitted"})
metric := cumulativeInt(prefix+"network.io", "By", s.TxBytes)
applyLabels(metric, map[string]string{"interface": s.Name, directionLabel: "transmit"})
return metric
}

func rxErrorsMetric(prefix string, s *stats.NetworkStats) *metricspb.Metric {
metric := cumulativeInt(prefix+"network.errors", "By", s.RxErrors)
applyLabels(metric, map[string]string{"interface": s.Name, directionLabel: "receive"})
return metric
}

func txErrorsMetric(prefix string, s *stats.NetworkStats) *metricspb.Metric {
metric := cumulativeInt(prefix+"network.errors", "By", s.TxErrors)
applyLabels(metric, map[string]string{"interface": s.Name, directionLabel: "transmit"})
return metric
}
20 changes: 20 additions & 0 deletions receiver/kubeletstatsreceiver/kubelet/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ func cumulativeInt(metricName string, units string, value *uint64) *metricspb.Me
}
}

func cumulativeDouble(metricName string, units string, value *float64) *metricspb.Metric {
if value == nil {
return nil
}
return &metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: metricName,
Unit: units,
Type: metricspb.MetricDescriptor_CUMULATIVE_DOUBLE,
},
Timeseries: []*metricspb.TimeSeries{{
Points: []*metricspb.Point{{
Value: &metricspb.Point_DoubleValue{
DoubleValue: *value,
},
}},
}},
}
}

func intGauge(metricName string, units string, value *uint64) *metricspb.Metric {
if value == nil {
return nil
Expand Down