Conky problem with sensors [SOLVED]

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
SwervedOne
Level 1
Level 1
Posts: 1
Joined: Sun Aug 01, 2021 12:22 am

Conky problem with sensors [SOLVED]

Post by SwervedOne »

So I hate bringing up an old thread, but this is somewhat related... [Split from lmsensors advice needed] I am putting together a conky for my system which has an Asus TUF Gaming B560M-Plus Wifi for a motherboard. The hwinfo chip on it that I am trying to get info from is a Nuvoton nct6798D-isa-290..

In conky, I am retrieving the voltage readings I want by using commands like this...

Code: Select all

${execi 2 sensors -u | grep -w 'in1_input' | cut -c 14-32} vDC
... which results in the reading I am looking for (in this case, the 3.3v rail)... However, if I try this with in0_input, it gives me two values.. looks something like this:

Code: Select all

Core Voltage: 1.152
0.950 vDC
Also, when I try to edit the 'cut' statement, to lets say, 3 characters (via cut -c 14-16), it cuts both values simultaneously like this:

Code: Select all

Core Voltage: 1.1
0.9 vDC
So it's like both values are associated with in0_input. For the heck of it, I did this from a terminal command line and I get this...

Code: Select all

~$ sensors -u | grep -w 'in0_input'|cut -c 14-32
ERROR: Can't get value of subfeature temp1_input: Can't read
1.152
0.950
Can anyone tell me a) know what's going on with this, and b) point me in the right direction to make conky only show the first value which is the core voltage?

Many many thanks in advance!

*****EDIT: I solved it by just changing the command from:

Code: Select all

${execi 1 sensors -u | grep -w 'in0_input' | cut -c 14-32} vDC
to

Code: Select all

${execi 1 sensors | grep -w 'Vcore' | cut -c 28-32} vDC
So basically, I just changed the way the sensors command dumped the data, and used grep to get what I wanted from that... This is a work-around I can live with.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Koentje
Level 7
Level 7
Posts: 1577
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Conky problem with sensors [SOLVED]

Post by Koentje »

Personally i would use cat /sys/class/hwmon/hwmon<X>/in1_input
This way it does not have to do any greps, awks or cuts, just echo what's in the file.

On my system..

Code: Select all

$ time sensors -u | grep -w 'in1_input' | cut -c 14-32
6.930

real	0m0,006s
user	0m0,001s
sys	0m0,005s

Code: Select all

$ time cat /sys/class/hwmon/hwmon4/in1_input
6930

real	0m0,002s
user	0m0,002s
sys	0m0,001s
With just 1 script that does not seem much, but in my case i'm running 36 scripts.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Conky problem with sensors [SOLVED]

Post by Termy »

SwervedOne wrote: Sun Aug 01, 2021 12:47 am ...
To address your question of why that happened: the cut(1) program (not a statement, BTW) will perform the same operation on all lines of input, so in the case of cut(1) doing something on two lines, the only thing I can think of is that grep(1) is for some reason spitting out two lines, because it finds a match on both lines; IDK why, because I'm not clear of the commands you ran. For me, I just see the float number, and that should've been your result.

Here are some other ways to parse that data, where the final and best one uses just BASH via SYSFS:

Code: Select all

# Using AWK.
sensors -u | awk '$1 == "in1_input:" {print($2 " vDC"); exit(0)}'

# Using PERL.
sensors -u | perl -ae 'print("$F[1] vDC") if $F[0] eq "in1_input:"'

# Using your approach, but more accurately and reliably.
sensors -u | grep -Em 1 '^\s{2}in1_input:' | cut -d ' ' -f 4

# Using sensors(1) and BASH itself.
while read Key Value; do
	if [[ $Key == in1_input: ]]; then
		printf '%.3f vDC' $Value

		break
	fi
done <<< "$(sensors -u)"

# The most efficient approach, using just BASH.
# You will probably need to change the path.
read < /sys/class/hwmon/hwmon1/in1_input
if (( REPLY < 1000 )); then
    printf '0.%d vDC' $REPLY
else
    Left=${REPLY%???}
    Right=${REPLY#?}
    printf '%d.%s vDC' $Left $Right
fi
Koentje's solution was almost the best, but you probaly want the voltage, not the millivolts, which, if you refer to the kernel documentation, is what that file will store. My solution, shown above, handles the decimal point correctly, as long as it's under 9999 volts, which I'm sure it will never get to. :lol: Ideally, I'd convert it properly (V = mV / 1000), but BASH doesn't support floating point arithmetic.

I recommend adding the most efficient approach (shown above) to a script, then having Conky just run that.

My benchmarks, each executed 100 times on an i5 4690K, if you're interested:

Code: Select all

# First method.
[I]terations = 100
[T]otal = 0.804s
T / I = 0.008s

# Second method.
[I]terations = 100
[T]otal = 0.808s
T / I = 0.008s

# Third method.
[I]terations = 100
[T]otal = 0.803s
T / I = 0.008s

# Fourth method.
[I]terations = 100
[T]otal = 0.821s
T / I = 0.008s

# Last method.
[I]terations = 100
[T]otal = 0.100s
T / I = 0.001s
And that's including loading up the interpreter (BASH) each time. Honestly, everything but the last method is unreasonable, because sensors(1) is doing so much other crap that it's just wholly inefficient to use for this purpose. You're going to love the result from the last method, as it's so fast; you could literally spam it every few milliseconds. :lol:
I'm also Terminalforlife on GitHub.
User avatar
Koentje
Level 7
Level 7
Posts: 1577
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Conky problem with sensors [SOLVED]

Post by Koentje »

This seems also very quick as oneliner?

Code: Select all

$ time x=$(echo $(cat /sys/class/hwmon/hwmon4/in1_input) / 1000 | bc -l ); printf '%.4s'  $x
6.93

real	0m0,002s
user	0m0,002s
sys	0m0,000s
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Conky problem with sensors [SOLVED]

Post by Termy »

Koentje wrote: Sat Feb 19, 2022 9:28 am This seems also very quick as oneliner?

[...]
Yeah, that's still very fast. No harm in using that, if something more compact is needed. I'm not keen on the two processes which get repeatedly spawned, but it's not a big deal in the grand scheme of things. Anything but that sensors(1) program. :lol: I'm just so used to writing actual programs where it can make sense to go that extra mile. :roll:
I'm also Terminalforlife on GitHub.
Locked

Return to “Compiz, Conky, Docks & Widgets”