diff --git a/main.go b/main.go index 1e3799e..1fb452c 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,8 @@ type Collector struct { powerUsage *prometheus.GaugeVec temperature *prometheus.GaugeVec fanSpeed *prometheus.GaugeVec + encUsage *prometheus.GaugeVec + decUsage *prometheus.GaugeVec } func NewCollector() *Collector { @@ -90,6 +92,22 @@ func NewCollector() *Collector { }, labels, ), + encUsage: prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: namespace, + Name: "encoder_utilization_percent", + Help: "EncoderUtilization returns the percent of time over the last sample period during which the GPU video encoder was being used.", + }, + labels, + ), + decUsage: prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: namespace, + Name: "decoder_utilization_percent", + Help: "DecoderUtilization returns the percent of time over the last sample period during which the GPU video decoder was being used.", + }, + labels, + ), } } @@ -101,6 +119,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) { c.powerUsage.Describe(ch) c.temperature.Describe(ch) c.fanSpeed.Describe(ch) + c.encUsage.Describe(ch) + c.decUsage.Describe(ch) } func (c *Collector) Collect(ch chan<- prometheus.Metric) { @@ -114,6 +134,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { c.powerUsage.Reset() c.temperature.Reset() c.fanSpeed.Reset() + c.encUsage.Reset() + c.decUsage.Reset() numDevices, err := gonvml.DeviceCount() if err != nil { @@ -185,6 +207,18 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { } else { c.fanSpeed.WithLabelValues(minor, uuid, name).Set(float64(fanSpeed)) } + encUsage, _, err := dev.EncoderUtilization() + if err != nil { + log.Printf("EncoderUtilization() error: %v", err) + } else { + c.encUsage.WithLabelValues(minor, uuid, name).Set(float64(encUsage)) + } + decUsage, _, err := dev.DecoderUtilization() + if err != nil { + log.Printf("DecoderUtilization() error: %v", err) + } else { + c.decUsage.WithLabelValues(minor, uuid, name).Set(float64(decUsage)) + } } c.usedMemory.Collect(ch) c.totalMemory.Collect(ch) @@ -192,6 +226,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { c.powerUsage.Collect(ch) c.temperature.Collect(ch) c.fanSpeed.Collect(ch) + c.encUsage.Collect(ch) + c.decUsage.Collect(ch) } func main() {