Skip to content

Instantly share code, notes, and snippets.

@hacker1024
Last active December 8, 2023 10:33
Show Gist options
  • Save hacker1024/c01a773f50769bd8216fa01ea0a1ef33 to your computer and use it in GitHub Desktop.
Save hacker1024/c01a773f50769bd8216fa01ea0a1ef33 to your computer and use it in GitHub Desktop.
KDE KSysGuard NVIDIA GPU temperature/memory/utilization sensor, based on @frantic1048's script, but with units and total memory detection.
#!/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\t°C\n";
}else{
print `nvidia-settings -tq gpucoretemp | head -n1`;
}
}
if(/gpu_graphics/){
if(/\?/){
print "GPU\t0\t100\t%\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\t".`nvidia-settings -tq [gpu:0]/TotalDedicatedGPUMemory | perl -pe 'chomp'`."\tMB\n";
}else{
print `nvidia-settings -tq [gpu:0]/UsedDedicatedGPUMemory`;
}
}
if(/gpu_video_engine/){
if(/\?/){
print "Video Engine\t0\t100\t%\n";
}else{
print `nvidia-settings -tq [gpu:0]/GPUUtilization | awk -F"," '{print(substr(\$3,index(\$3,"=")+1))}'`;
}
}
print "ksysguardd> ";
}
@fonic
Copy link

fonic commented Feb 12, 2020

I ported your script to Bash, extended it and significantly lowered its CPU footprint:
https://gist.github.com/fonic/8f38e5e3ce5c8693ae3a23aa1af21fb9

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment