Skip to content

Commit

Permalink
libbpf: update to use microseconds instead of milliseconds in the ebp…
Browse files Browse the repository at this point in the history
…f code because the low precision is identifying that the precess was not active

Signed-off-by: marceloamaral <[email protected]>
  • Loading branch information
marceloamaral committed Jun 10, 2024
1 parent 4337a5e commit 34889bb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/metrics/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ func collectEnergy(ch chan<- prometheus.Metric, instance interface{}, metricName
}
}

func convertUnit(metricName string, val uint64) float64 {
if metricName == config.CPUTime {
// convert microseconds to miliseconds
return float64(val) / 1000.0
}
return float64(val)
}

func CollectResUtil(ch chan<- prometheus.Metric, instance interface{}, metricName string, collector metricfactory.PromMetric) {
var value float64
var labelValues []string
Expand All @@ -125,7 +133,7 @@ func CollectResUtil(ch chan<- prometheus.Metric, instance interface{}, metricNam
}
if isGPUMetric {
for deviceID, utilization := range container.ResourceUsage[metricName].Stat {
value = float64(utilization.Aggr)
value = convertUnit(metricName, utilization.Aggr)
labelValues = []string{container.ContainerID, container.PodName, container.ContainerName, container.Namespace, deviceID}
collect(ch, collector, value, labelValues)
}
Expand All @@ -134,20 +142,20 @@ func CollectResUtil(ch chan<- prometheus.Metric, instance interface{}, metricNam
klog.Errorf("ContainerStats %s does not have metric %s\n", container.ContainerID, metricName)
return
}
value = float64(container.ResourceUsage[metricName].SumAllAggrValues())
value = convertUnit(metricName, container.ResourceUsage[metricName].SumAllAggrValues())
labelValues = []string{container.ContainerID, container.PodName, container.ContainerName, container.Namespace}
collect(ch, collector, value, labelValues)
}

case *stats.ProcessStats:
process := instance.(*stats.ProcessStats)
value = float64(process.ResourceUsage[metricName].SumAllAggrValues())
value = convertUnit(metricName, process.ResourceUsage[metricName].SumAllAggrValues())
labelValues = []string{strconv.FormatUint(process.PID, 10), process.ContainerID, process.VMID, process.Command}
collect(ch, collector, value, labelValues)

case *stats.VMStats:
vm := instance.(*stats.VMStats)
value = float64(vm.ResourceUsage[metricName].SumAllAggrValues())
value = convertUnit(metricName, vm.ResourceUsage[metricName].SumAllAggrValues())
labelValues = []string{vm.VMID}
collect(ch, collector, value, labelValues)

Expand All @@ -156,7 +164,7 @@ func CollectResUtil(ch chan<- prometheus.Metric, instance interface{}, metricNam
node := instance.(*stats.NodeStats)
if _, exist := node.ResourceUsage[metricName]; exist {
for deviceID, utilization := range node.ResourceUsage[metricName].Stat {
value = float64(utilization.Aggr)
value = convertUnit(metricName, utilization.Aggr)
labelValues = []string{deviceID, stats.NodeName}
collect(ch, collector, value, labelValues)
}
Expand Down

0 comments on commit 34889bb

Please sign in to comment.