Skip to content

Commit bae3229

Browse files
committed
chore: rebase with main
Signed-off-by: Deezzir <deezzir@gmail.com>
1 parent 29eefc5 commit bae3229

1 file changed

Lines changed: 59 additions & 65 deletions

File tree

collector/drm_linux.go

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,62 @@ const (
2828
)
2929

3030
type drmCollector struct {
31-
fs sysfs.FS
32-
logger *slog.Logger
33-
CardInfo *prometheus.Desc
34-
CardInfoWithChip *prometheus.Desc
35-
GPUBusyPercent *prometheus.Desc
36-
MemoryGTTSize *prometheus.Desc
37-
MemoryGTTUsed *prometheus.Desc
38-
MemoryVisibleVRAMSize *prometheus.Desc
39-
MemoryVisibleVRAMUsed *prometheus.Desc
40-
MemoryVRAMSize *prometheus.Desc
41-
MemoryVRAMUsed *prometheus.Desc
31+
fs sysfs.FS
32+
logger *slog.Logger
4233
}
4334

4435
func init() {
4536
registerCollector("drm", defaultDisabled, NewDrmCollector)
4637
}
4738

39+
var (
40+
drmCardInfo = prometheus.NewDesc(
41+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "card_info"),
42+
"Card information",
43+
[]string{"card", "memory_vendor", "power_performance_level", "unique_id", "vendor"}, nil,
44+
)
45+
drmCardInfoWithChip = prometheus.NewDesc(
46+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "card_info"),
47+
"Card information",
48+
[]string{"card", "memory_vendor", "power_performance_level", "unique_id", "chip", "vendor"}, nil,
49+
),
50+
drmGPUBusyPercent = prometheus.NewDesc(
51+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "gpu_busy_percent"),
52+
"How busy the GPU is as a percentage.",
53+
[]string{"card"}, nil,
54+
)
55+
drmMemoryGTTSize = prometheus.NewDesc(
56+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_gtt_size_bytes"),
57+
"The size of the graphics translation table (GTT) block in bytes.",
58+
[]string{"card"}, nil,
59+
)
60+
drmMemoryGTTUsed = prometheus.NewDesc(
61+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_gtt_used_bytes"),
62+
"The used amount of the graphics translation table (GTT) block in bytes.",
63+
[]string{"card"}, nil,
64+
)
65+
drmMemoryVisibleVRAMSize = prometheus.NewDesc(
66+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vis_vram_size_bytes"),
67+
"The size of visible VRAM in bytes.",
68+
[]string{"card"}, nil,
69+
)
70+
drmMemoryVisibleVRAMUsed = prometheus.NewDesc(
71+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vis_vram_used_bytes"),
72+
"The used amount of visible VRAM in bytes.",
73+
[]string{"card"}, nil,
74+
)
75+
drmMemoryVRAMSize = prometheus.NewDesc(
76+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vram_size_bytes"),
77+
"The size of VRAM in bytes.",
78+
[]string{"card"}, nil,
79+
)
80+
drmMemoryVRAMUsed = prometheus.NewDesc(
81+
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vram_used_bytes"),
82+
"The used amount of VRAM in bytes.",
83+
[]string{"card"}, nil,
84+
)
85+
)
86+
4887
// NewDrmCollector returns a new Collector exposing /sys/class/drm/card?/device stats.
4988
func NewDrmCollector(logger *slog.Logger) (Collector, error) {
5089
fs, err := sysfs.NewFS(*sysPath)
@@ -55,51 +94,6 @@ func NewDrmCollector(logger *slog.Logger) (Collector, error) {
5594
return &drmCollector{
5695
fs: fs,
5796
logger: logger,
58-
CardInfo: prometheus.NewDesc(
59-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "card_info"),
60-
"Card information",
61-
[]string{"card", "memory_vendor", "power_performance_level", "unique_id", "vendor"}, nil,
62-
),
63-
CardInfoWithChip: prometheus.NewDesc(
64-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "card_info"),
65-
"Card information",
66-
[]string{"card", "memory_vendor", "power_performance_level", "unique_id", "chip", "vendor"}, nil,
67-
),
68-
GPUBusyPercent: prometheus.NewDesc(
69-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "gpu_busy_percent"),
70-
"How busy the GPU is as a percentage.",
71-
[]string{"card"}, nil,
72-
),
73-
MemoryGTTSize: prometheus.NewDesc(
74-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_gtt_size_bytes"),
75-
"The size of the graphics translation table (GTT) block in bytes.",
76-
[]string{"card"}, nil,
77-
),
78-
MemoryGTTUsed: prometheus.NewDesc(
79-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_gtt_used_bytes"),
80-
"The used amount of the graphics translation table (GTT) block in bytes.",
81-
[]string{"card"}, nil,
82-
),
83-
MemoryVisibleVRAMSize: prometheus.NewDesc(
84-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vis_vram_size_bytes"),
85-
"The size of visible VRAM in bytes.",
86-
[]string{"card"}, nil,
87-
),
88-
MemoryVisibleVRAMUsed: prometheus.NewDesc(
89-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vis_vram_used_bytes"),
90-
"The used amount of visible VRAM in bytes.",
91-
[]string{"card"}, nil,
92-
),
93-
MemoryVRAMSize: prometheus.NewDesc(
94-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vram_size_bytes"),
95-
"The size of VRAM in bytes.",
96-
[]string{"card"}, nil,
97-
),
98-
MemoryVRAMUsed: prometheus.NewDesc(
99-
prometheus.BuildFQName(namespace, drmCollectorSubsystem, "memory_vram_used_bytes"),
100-
"The used amount of VRAM in bytes.",
101-
[]string{"card"}, nil,
102-
),
10397
}, nil
10498
}
10599

@@ -133,33 +127,33 @@ func (c *drmCollector) updateAMDCards(ch chan<- prometheus.Metric) error {
133127
for _, s := range stats {
134128
if chip := chipName(s); chip != "" {
135129
ch <- prometheus.MustNewConstMetric(
136-
c.CardInfoWithChip, prometheus.GaugeValue, 1,
130+
drmCardInfoWithChip, prometheus.GaugeValue, 1,
137131
s.Name, s.MemoryVRAMVendor, s.PowerDPMForcePerformanceLevel, s.UniqueID, chip, vendor)
138132
} else {
139133
ch <- prometheus.MustNewConstMetric(
140-
c.CardInfo, prometheus.GaugeValue, 1,
134+
drmCardInfo, prometheus.GaugeValue, 1,
141135
s.Name, s.MemoryVRAMVendor, s.PowerDPMForcePerformanceLevel, s.UniqueID, vendor)
142136
}
143137
ch <- prometheus.MustNewConstMetric(
144-
c.GPUBusyPercent, prometheus.GaugeValue, float64(s.GPUBusyPercent), s.Name)
138+
drmGPUBusyPercent, prometheus.GaugeValue, float64(s.GPUBusyPercent), s.Name)
145139

146140
ch <- prometheus.MustNewConstMetric(
147-
c.MemoryGTTSize, prometheus.GaugeValue, float64(s.MemoryGTTSize), s.Name)
141+
drmMemoryGTTSize, prometheus.GaugeValue, float64(s.MemoryGTTSize), s.Name)
148142

149143
ch <- prometheus.MustNewConstMetric(
150-
c.MemoryGTTUsed, prometheus.GaugeValue, float64(s.MemoryGTTUsed), s.Name)
144+
drmMemoryGTTUsed, prometheus.GaugeValue, float64(s.MemoryGTTUsed), s.Name)
151145

152146
ch <- prometheus.MustNewConstMetric(
153-
c.MemoryVRAMSize, prometheus.GaugeValue, float64(s.MemoryVRAMSize), s.Name)
147+
drmMemoryVRAMSize, prometheus.GaugeValue, float64(s.MemoryVRAMSize), s.Name)
154148

155149
ch <- prometheus.MustNewConstMetric(
156-
c.MemoryVRAMUsed, prometheus.GaugeValue, float64(s.MemoryVRAMUsed), s.Name)
150+
drmMemoryVRAMUsed, prometheus.GaugeValue, float64(s.MemoryVRAMUsed), s.Name)
157151

158152
ch <- prometheus.MustNewConstMetric(
159-
c.MemoryVisibleVRAMSize, prometheus.GaugeValue, float64(s.MemoryVisibleVRAMSize), s.Name)
153+
drmMemoryVisibleVRAMSize, prometheus.GaugeValue, float64(s.MemoryVisibleVRAMSize), s.Name)
160154

161155
ch <- prometheus.MustNewConstMetric(
162-
c.MemoryVisibleVRAMUsed, prometheus.GaugeValue, float64(s.MemoryVisibleVRAMUsed), s.Name)
156+
drmMemoryVisibleVRAMUsed, prometheus.GaugeValue, float64(s.MemoryVisibleVRAMUsed), s.Name)
163157
}
164158

165159
return nil

0 commit comments

Comments
 (0)