Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encoder/decoder utilization percent #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
),
}
}

Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -185,13 +207,27 @@ 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)
c.dutyCycle.Collect(ch)
c.powerUsage.Collect(ch)
c.temperature.Collect(ch)
c.fanSpeed.Collect(ch)
c.encUsage.Collect(ch)
c.decUsage.Collect(ch)
}

func main() {
Expand Down