@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222 "path/filepath"
2323 "regexp"
24+ "strings"
2425 "syscall"
2526
2627 "github.com/prometheus/procfs/internal/util"
@@ -47,6 +48,21 @@ type ClassDRMCardAMDGPUStats struct {
4748 MemoryVRAMVendor string // The VRAM vendor name.
4849 PowerDPMForcePerformanceLevel string // The current power performance level.
4950 UniqueID string // The unique ID of the GPU that will persist from machine to machine.
51+ DevName string // The device name.
52+ DevType string // The device type.
53+ }
54+
55+ // readDev reads the device name and type from the "device" symlink in the given directory.
56+ func readDevInfo (dir string ) (string , string , error ) {
57+ devicePath , devErr := filepath .EvalSymlinks (filepath .Join (dir , "device" ))
58+ if devErr == nil {
59+ devPathPrefix , devName := filepath .Split (devicePath )
60+ _ , devType := filepath .Split (strings .TrimRight (devPathPrefix , "/" ))
61+
62+ return devName , devType , nil
63+ }
64+
65+ return "" , "" , devErr
5066}
5167
5268// ClassDRMCardAMDGPUStats returns DRM card metrics for all amdgpu cards.
@@ -117,6 +133,10 @@ func parseClassDRMAMDGPUCard(card string) (ClassDRMCardAMDGPUStats, error) {
117133 if v , err := readDRMCardField (card , "unique_id" ); err == nil {
118134 stats .UniqueID = v
119135 }
136+ if n , t , err := readDevInfo (card ); err == nil {
137+ stats .DevName = n
138+ stats .DevType = t
139+ }
120140
121141 return stats , nil
122142}
0 commit comments