Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
KDE KSysGuard NVIDIA GPU temperature/memory/utilization sensor
#!/usr/bin/perl -w
# act as a KSysGuard sensor
# provides NVIDIA GPU info via `nvidia-settings`
# Usage (e.g. add gpu temperature sensor)
# 1. save this file, make sure it has a exec permission
# 2. in KSysGuard's menu, open `File` -> `Monitor Remote Machine`
# 3.1 in new dialog, type `Host` whatever you want
# 3.2 set `Connection Type` to `Custom command`
# 3.3 set `Command` like `path/to/this-sensor.pl`
# 4. click `OK`, now you can find new sensor named `gpu_temp`
# which is provides GPU temperature
# See Also
# https://techbase.kde.org/Development/Tutorials/Sensors
$|=1;
print "ksysguardd 1.2.0\n";
print "ksysguardd> ";
while(<>){
if(/monitors/){
print "gpu_temp\tinteger\n";
print "gpu_graphics\tinteger\n";
print "gpu_memory\tinteger\n";
print "gpu_video_engine\tinteger\n";
}
if(/gpu_temp/){
if(/\?/){
print "GPU Temp\t0\t0\n";
}else{
print `nvidia-settings -tq gpucoretemp | head -n1`;
}
}
if(/gpu_graphics/){
if(/\?/){
print "GPU\t0\t0\n";
}else{
print `nvidia-settings -tq [gpu:0]/GPUUtilization | awk -F"," '{print(substr(\$1,index(\$1,"=")+1))}'`;
}
}
if(/gpu_memory/){
if(/\?/){
print "GPU Memory\t0\t0\n";
}else{
print `nvidia-settings -tq [gpu:0]/GPUUtilization | awk -F"," '{print(substr(\$2,index(\$2,"=")+1))}'`;
}
}
if(/gpu_video_engine/){
if(/\?/){
print "Video Engine\t0\t0\n";
}else{
print `nvidia-settings -tq [gpu:0]/GPUUtilization | awk -F"," '{print(substr(\$3,index(\$3,"=")+1))}'`;
}
}
print "ksysguardd> ";
}
@BryanByteZero

This comment has been minimized.

Copy link

BryanByteZero commented Oct 2, 2016

Is possible to this on AMD opensource drivers?

@frantic1048

This comment has been minimized.

Copy link
Owner Author

frantic1048 commented Oct 3, 2016

@BryanByteZero , To make it work on AMD, you just need to find a way to get GPU information via command line, and extract the info you want (e.g. temperature), then replace the command in Line 31

Another way, if the sensor can be detected by lm_sensors, then you totally do not need this external script. KSysGuard has already got it. You can manually run sudo sensors-detect to find if there is any more usable sensor. For more about lm_sensors, you can take a look at https://wiki.archlinux.org/index.php/Lm_sensors#Setup

I'm not familiar with AMD command line tools. Good luck~

@sanwablo

This comment has been minimized.

Copy link

sanwablo commented Jan 4, 2017

Where do you add that code?

@hacker1024

This comment has been minimized.

Copy link

hacker1024 commented Jun 30, 2018

I've modified your script to add units and detect the amount of GPU memory.
https://gist.github.com/hacker1024/c01a773f50769bd8216fa01ea0a1ef33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.