diff --git a/collector/drm_linux.go b/collector/drm_linux.go index 6c19514c4f..1739bc3d54 100644 --- a/collector/drm_linux.go +++ b/collector/drm_linux.go @@ -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, ) drmGPUBusyPercent = prometheus.NewDesc( prometheus.BuildFQName(namespace, drmCollectorSubsystem, "gpu_busy_percent"), @@ -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) + + if cleanDevType != "" && cleanDevName != "" { + return cleanDevType + "_" + cleanDevName + } + return cleanDevName +} + func (c *drmCollector) updateAMDCards(ch chan<- prometheus.Metric) error { vendor := "amd" stats, err := c.fs.ClassDRMCardAMDGPUStats() @@ -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) + s.Name, s.MemoryVRAMVendor, s.PowerDPMForcePerformanceLevel, s.UniqueID, chipName(s), vendor) ch <- prometheus.MustNewConstMetric( drmGPUBusyPercent, prometheus.GaugeValue, float64(s.GPUBusyPercent), s.Name) diff --git a/collector/helper_linux.go b/collector/helper_linux.go new file mode 100644 index 0000000000..36cf978023 --- /dev/null +++ b/collector/helper_linux.go @@ -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 +} diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index 833782446a..5d9d4b7225 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -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[^0-9]+)(?P[0-9]*)?(_(?P.+))?$`) - hwmonLabelDesc = []string{"chip", "sensor"} - hwmonChipNameLabelDesc = []string{"chip", "chip_name"} - hwmonSensorTypes = []string{ + hwmonFilenameFormat = regexp.MustCompile(`^(?P[^0-9]+)(?P[0-9]*)?(_(?P.+))?$`) + 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", @@ -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 {