Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions collector/drm_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
drmCardInfo = prometheus.NewDesc(
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "card_info"),
"Card information",
[]string{"card", "memory_vendor", "power_performance_level", "unique_id", "vendor"}, nil,
[]string{"card", "memory_vendor", "power_performance_level", "unique_id", "chip", "vendor"}, nil,
)
Comment thread
SuperQ marked this conversation as resolved.
drmGPUBusyPercent = prometheus.NewDesc(
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "gpu_busy_percent"),
Expand Down Expand Up @@ -96,6 +96,17 @@ func (c *drmCollector) Update(ch chan<- prometheus.Metric) error {
return c.updateAMDCards(ch)
}

func chipName(s sysfs.ClassDRMCardAMDGPUStats) string {
// generate a chip name based on the deviceType and devName
cleanDevName := cleanMetricName(s.DevName)
cleanDevType := cleanMetricName(s.DevType)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should relate to https://github.com/prometheus/node_exporter/blob/master/collector/hwmon_linux.go#L517

However both parts come from different sources and will diverge.
This is annoying after #3646

I am not sure this is something that could actually harm us, but calling it out as an issue overall. Making both implementations align is probably not worth the effort.


if cleanDevType != "" && cleanDevName != "" {
return cleanDevType + "_" + cleanDevName
}
return cleanDevName
}

func (c *drmCollector) updateAMDCards(ch chan<- prometheus.Metric) error {
vendor := "amd"
stats, err := c.fs.ClassDRMCardAMDGPUStats()
Expand All @@ -106,7 +117,7 @@ func (c *drmCollector) updateAMDCards(ch chan<- prometheus.Metric) error {
for _, s := range stats {
ch <- prometheus.MustNewConstMetric(
drmCardInfo, prometheus.GaugeValue, 1,
s.Name, s.MemoryVRAMVendor, s.PowerDPMForcePerformanceLevel, s.UniqueID, vendor)
Comment thread
SuperQ marked this conversation as resolved.
s.Name, s.MemoryVRAMVendor, s.PowerDPMForcePerformanceLevel, s.UniqueID, chipName(s), vendor)

ch <- prometheus.MustNewConstMetric(
drmGPUBusyPercent, prometheus.GaugeValue, float64(s.GPUBusyPercent), s.Name)
Expand Down
30 changes: 30 additions & 0 deletions collector/helper_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package collector

import (
"regexp"
"strings"
)

var (
hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]")
)

func cleanMetricName(name string) string {
lower := strings.ToLower(name)
replaced := hwmonInvalidMetricChars.ReplaceAllLiteralString(lower, "_")
cleaned := strings.Trim(replaced, "_")
return cleaned
}
16 changes: 4 additions & 12 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ var (
collectorHWmonSensorInclude = kingpin.Flag("collector.hwmon.sensor-include", "Regexp of hwmon sensor to include (mutually exclusive to sensor-exclude).").String()
collectorHWmonSensorExclude = kingpin.Flag("collector.hwmon.sensor-exclude", "Regexp of hwmon sensor to exclude (mutually exclusive to sensor-include).").String()

hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]")
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
hwmonLabelDesc = []string{"chip", "sensor"}
hwmonChipNameLabelDesc = []string{"chip", "chip_name"}
hwmonSensorTypes = []string{
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
hwmonLabelDesc = []string{"chip", "sensor"}
hwmonChipNameLabelDesc = []string{"chip", "chip_name"}
hwmonSensorTypes = []string{
"vrm", "beep_enable", "update_interval", "in", "cpu", "fan",
"pwm", "temp", "curr", "power", "energy", "humidity",
"intrusion", "freq",
Expand Down Expand Up @@ -69,13 +68,6 @@ func NewHwMonCollector(logger *slog.Logger) (Collector, error) {
}, nil
}

func cleanMetricName(name string) string {
lower := strings.ToLower(name)
replaced := hwmonInvalidMetricChars.ReplaceAllLiteralString(lower, "_")
cleaned := strings.Trim(replaced, "_")
return cleaned
}

func addValueFile(data map[string]map[string]string, sensor string, prop string, file string) {
raw, err := sysReadFile(file)
if err != nil {
Expand Down
Loading