forked from onedr0p/intel-gpu-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intel-gpu-exporter.py
61 lines (49 loc) · 2.69 KB
/
intel-gpu-exporter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import string
import subprocess
import time
import os
from prometheus_client import (GC_COLLECTOR, PLATFORM_COLLECTOR,
PROCESS_COLLECTOR, REGISTRY, Metric,
start_http_server)
class DataCollector(object):
def __init__(self, endpoint):
self._endpoint = endpoint
def collect(self):
gpu = os.environ.get('GPU_DEVICE', 'drm:/dev/dri/card0')
cmd = "/usr/bin/timeout -k 2 2 /usr/bin/intel_gpu_top -J -d %s" % gpu
raw_output = subprocess.run(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode("utf-8")
output = f"[{raw_output.translate(str.maketrans('', '', string.whitespace))}]"
data = json.loads(output)
render_busy_percent = data[1]["engines"]["Render/3D/0"]["busy"]
metric = Metric("intel_gpu_render_busy_percent", "Render engine busy utilisation in %", "summary")
metric.add_sample("intel_gpu_render_busy_percent", value=render_busy_percent, labels={})
yield metric
video_0_busy_percent = data[1]["engines"]["Video/0"]["busy"]
metric = Metric("intel_gpu_video_0_busy_percent", "Video 0 engine busy utilisation in %", "summary")
metric.add_sample("intel_gpu_video_0_busy_percent", value=video_0_busy_percent, labels={})
yield metric
video_1_busy_percent = data[1]["engines"]["Video/1"]["busy"]
metric = Metric("intel_gpu_video_1_busy_percent", "Video 1 engine busy utilisation in %", "summary")
metric.add_sample("intel_gpu_video_1_busy_percent", value=video_1_busy_percent, labels={})
yield metric
enhance_0_busy_percent = data[1]["engines"]["VideoEnhance/0"]["busy"]
metric = Metric("intel_gpu_enhance_0_busy_percent", "Enhance 0 engine busy utilisation in %", "summary")
metric.add_sample("intel_gpu_enhance_0_busy_percent", value=enhance_0_busy_percent, labels={})
yield metric
if 'VideoEnhance/1' not in data[1]["engines"]:
enhance_1_busy_percent = "0.0"
else:
enhance_1_busy_percent = data[1]["engines"]["VideoEnhance/1"]["busy"]
metric = Metric("intel_gpu_enhance_1_busy_percent", "Enhance 1 engine busy utilisation in %", "summary")
metric.add_sample("intel_gpu_enhance_1_busy_percent", value=enhance_1_busy_percent, labels={})
yield metric
if __name__ == "__main__":
host, port = "0.0.0.0:8080".split(':')
start_http_server(int(port), host)
REGISTRY.unregister(PROCESS_COLLECTOR)
REGISTRY.unregister(PLATFORM_COLLECTOR)
REGISTRY.unregister(GC_COLLECTOR)
REGISTRY.register(DataCollector(f"http://{host}:{port}/metrics"))
while True:
time.sleep(1)