Radeontop output in Conky

Hi!

I have a question regarding using radeontop output inside Conky.

I know that radeontop can dump to stdout with radeontop -d- and that I can limit the dump to one line with radeontop -d- -l1.
I also know that I can awk this inside Conky .conf file.

What I don’t know is how to run radeontop without sudo, so it can be safely called from inside Conky.
I also don’t like the idea of running Conky as sudo or root.
AFAIK radeontop is installed for root user only.

Thanks for any help!

I am unsure if this is the best way to do it, but you should be able to modify you /etc/sudoers file by running sudo visudo. There you can specify that your user has permissions to execute radeontop without password promt. This means your user will have always permissions to run this command, but should not have big security implications. Look up the syntax, should not be hard.

3 Likes

Arigato @anon86748826 Batou-san.

With sudo visudo:

%sudo   ALL=(ALL:ALL) ALL
username     ALL=(root) NOPASSWD: /usr/sbin/radeontop

Then in conky.conf:

GPU Shader Freq.: ${execi 1 sudo radeontop -d- -l1 | awk '/a/ {print $37}' | sed '$s/,$//'} (${execi 10 sudo radeontop -d- -l1 | awk '/a/ {print $36}' | sed '$s/,$//'})
Memory Load: ${execi 1 sudo radeontop -d- -l1 | awk '/a/ {print $28}' | sed '$s/,$//'} (${execi 10 sudo radeontop -d- -l1 | awk '/a/ {print $27}' | sed '$s/,$//'})
Memory Freq.: ${execi 1 sudo radeontop -d- -l1 | awk '/a/ {print $34}' | sed '$s/,$//'} (${execi 10 sudo radeontop -d- -l1 | awk '/a/ {print $33}' | sed '$s/,$//'})

And so far it werks, but I’m not sure if ALL=(root) part is appropriate here.

1 Like

I never used Conky (and neither radeontop for that matter), because I don’t have a “desktop,” but being linux programs, I think I can guess how it works. I say you try to dump radeontop into a file in a location accessible by both root and your user (like > /tmp/radeontop.log) and make conky read from the file.

Something to consider is the rate of writing to the file and conky reading from it. I have no idea how fast either of them work, but if radeontop is going to write stuff multiple times per second, I suggest you use a tmpfs (usually /tmp is a ramdisk, check fstab to make sure) so that you don’t trash your SSD. Well, a tmpfs is always recommended for ephemeral information, like stats.

Bonus linux tip: you can use mktemp to create a file in /tmp automatically and you can save the output in a variable, so something like:

RADLOG=$(mktemp)
#radeontop -d- -11 > $RADLOG
#conky-read -f $RADLOG

The above is just a “pseudo-shell” example, as I don’t know the commands of either radeontop or conky (which is why I commented their lines with “#”), but in a script, the first line is an example of how you would save the output of a command in a variable. I always use uppercase words for variables, because it’s easier to spot, but remember that linux is case sensitive. You can use lowercase to make your writing life easier, but reading and debugging is easier when VARs are uppercase.

I don’t know your Linux knowledge level, but I’m writing this for other linux-curious readers as well.

3 Likes

That config looks kinda terrible. Can you give me an example output of radeontop, so I can try to clear it up a little? If you are using awk, there shouldn’t be a reason to pipe stuff into sed, it should be possible to just use 1 awk command instead of 1 awk and 1 sed (so, faster processing).

Also, I guess if conky is the one calling radeontop, you are going to have a sudo dependency. Your sudoers conf is alright. Here’s a small explanation of sudoers.conf:

username host = (root) NOPASSWD: /path/to/program
  • First word is username (or group if you use %).
  • Second one is host (ALL means all hosts).
  • Third is to act as what user or group (ALL means it can run programs as all users, root means it can only run commands as root).
  • Fourth (and last) is the command to run with sudo. ALL means allow to run sudo on all files (but require password). If you use the option NOPASSWD, no password required and you have to mention the programs after it (NOPASSWD: ALL or NOPASSWD: /path/to/file). If the path has a trailing / (/path/to/folder/), then that means a user can run sudo on all the files under that folder, but not subfolders.

Let’s take your config:

%sudo ALL=(ALL:ALL) ALL

All users from the group sudo can run sudo on all hosts, as all users and groups and any command.

username ALL=(root) NOPASSWD: /usr/sbin/radeontop

The user username can run sudo on all hosts, only as the root user and only the command /usr/sbin/radeontop.

3 Likes

@NukeDukem You did great. What @ThatGuyB says is another way to do it that did not come to mind when I wrote my response. As long as there is not a terrible bug in radeontop that makes running the program an security issue you should be fine running it that way and I see no reason for it! It is certainly the easiest way. What @ThatGuyB said is great because you would not need to change any permissions, but is also more hassle to set up and a couple extra steps.

2 Likes

The problem with my first comment is that I didn’t know Conky itself was calling upon radeontop. You can certainly use crontab or systemd or something else to run it, but then you can have sync issues. And since I think Conky works by polling a file, it may lock the file and prevent radeontop from writing into it, so this is why I did my second comment. We could use something like entr to see if the radeontop output file was modified and then run conky, but it gets messy pretty quickly, so using sudo in conky is probably fine.

Also, since only radeontop can be ran as passwordless sudo, it shouldn’t be too much of a security threat.

1 Like

Thanks for detailed responses.

From what I can see radeontop is writing once in a second, so the SSD wear shouldn’t be a problem I guess?

You are right with the assumption about conky calling radeontop.

The config part that I pasted is not accually mine. I found it on a Manjaro forum. I planned to do it much cleaner, but first was looking for working example that will give me radeontop output inside conky.

This is radeontop output:

1635260179.718576: bus 03, gpu 100.00%, ee 0.00%, vgt 0.00%, ta 100.00%, sx 0.00%, sh 0.00%, spi 100.00%, sc 0.83%, pa 0.00%, db 0.83%, cb 0.83%, vram 33.99% 5545.45mb, gtt 0.67% 110.20mb, mclk 100.00% 1.000ghz, sclk 86.33% 1.555ghz
1635260180.718658: bus 03, gpu 100.00%, ee 0.00%, vgt 0.00%, ta 100.00%, sx 0.00%, sh 0.00%, spi 100.00%, sc 0.83%, pa 0.00%, db 0.83%, cb 0.83%, vram 33.99% 5545.45mb, gtt 0.67% 110.20mb, mclk 100.00% 1.000ghz, sclk 86.33% 1.555ghz
1635260181.718738: bus 03, gpu 100.00%, ee 0.00%, vgt 0.00%, ta 100.00%, sx 0.83%, sh 0.00%, spi 100.00%, sc 0.83%, pa 0.00%, db 0.83%, cb 0.83%, vram 33.95% 5537.88mb, gtt 0.67% 110.20mb, mclk 100.00% 1.000ghz, sclk 87.39% 1.574ghz
1635260182.699360: bus 03, gpu 100.00%, ee 0.00%, vgt 0.00%, ta 100.00%, sx 0.00%, sh 0.00%, spi 100.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%, vram 33.95% 5537.88mb, gtt 0.67% 110.20mb, mclk 100.00% 1.000ghz, sclk 88.80% 1.599ghz
2 Likes