Xfce Forum

Sub domains
 

You are not logged in.

#1 2018-08-15 11:20:01

csanyipal
Member
Registered: 2018-08-15
Posts: 5

Using Genmon to show CPU information, but on multicore CPU?

Hi,

I just installed the Genmon on my Gentoo Linux system.
I am following the guide to show informations about CPU Frequency and Temperature.
I am trying to use the provided example script:

#!/bin/bash
echo "<img>/usr/share/icons/Bluecurve/16x16/apps/gnome-monitor.png</img>"
declare -i cpuFreq
cpuFreq=$(cat /proc/cpuinfo | grep "cpu MHz" | sed 's/\ \ */ /g' | cut -f3 -d" " | cut -f1 -d".")
if [ $cpuFreq -ge 1000 ]
then
  cpu=$(echo $cpuFreq | cut -c1).$(echo $cpuFreq | cut -c2)GHz
else
  cpu=${cpuFreq}MHz
fi
echo "<txt>"$(cat /proc/acpi/thermal_zone/THM/temperature | sed 's/\ \ */ /g' | cut -f2 -d" ")" C</txt>"
echo "<tool>Freq: "$cpu"</tool>"

although modified a bit the url of the image, like this:

echo "<img>/usr/share/icons/Tango/16x16/apps/gnome-monitor.png</img>"

After I set the genmon plugin in the panel, it shows only this: 'CPU [the image of gnome-monitor.png]C'.

If I run the script in the commandline I get error messages:
<img>/usr/share/icons/Tango/16x16/apps/gnome-monitor.png</img>
/home/pali/Irataim/Programozas/Bash/xfce4_genmon_plugin_CPU_FreqTerm: line 4: 1197
1197
1197
1197: syntax error in expression (error token is "1197
1197
1197")
/home/pali/Irataim/Programozas/Bash/xfce4_genmon_plugin_CPU_FreqTerm: line 5: [: -ge: unary operator expected
<tool>Freq: MHz</tool>
cat: /proc/acpi/thermal_zone/THM/temperature: No such file or directory
<txt> C</txt>

If I run just a part of this script:

cat /proc/cpuinfo | grep "cpu MHz" | sed 's/\ \ */ /g' | cut -f3 -d" " | cut -f1 -d"."

I get this output:
1197
1197
1197
1197

so it seems to me that, that it could works on a singlecore CPU but not on multicore CPU, right?
It would be good enough if we could get the average of the CPU cores frequencies out there.
So here we could put some math to calculate the frequencies of cpu cores, right?

If I run the other part of the script:

cat /proc/acpi/thermal_zone/THM/temperature | sed 's/\ \ */ /g' | cut -f2 -d" "

I get this output:
cat: /proc/acpi/thermal_zone/THM/temperature: No such file or directory

The /proc/acpi/ directory is deprecated, says in the kernel menuconfig out here.
So which command should use instead to obtain the CPU temperature?

Best, Pál

Offline

#2 2018-08-15 17:54:43

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: Using Genmon to show CPU information, but on multicore CPU?

Yes, this is an old script and only works with single core CPUs. Try this script instead (assumes that lscpu is installed and that system temperature is captured in /sys/class):

#!/bin/bash

CPU=$(lscpu | grep "CPU MHz" | awk '{print $3}' | cut -f1 -d.)
TEMP="N/A"

[[ $CPU == "" ]] && CPU="N/A"

if [ -f /sys/class/thermal/thermal_zone*/temp ]; then
	TEMP=$(cat /sys/class/thermal/thermal_zone*/temp | awk '{print ($1 / 1000) "C" }')
fi

#echo $CPU
#echo $TEMP

# do the genmon
echo "<img>/usr/share/icons/Bluecurve/16x16/apps/gnome-monitor.png</img><txt>$CPU / $TEMP</txt><tool>CPU: $CPU
TEMP: $TEMP</tool>"

exit 0

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2018-08-15 19:40:24

csanyipal
Member
Registered: 2018-08-15
Posts: 5

Re: Using Genmon to show CPU information, but on multicore CPU?

It works, although I changed again the image url.
Now the plugin shows the frequency and the temperature.
Thank you very much!!

Offline

Board footer

Powered by FluxBB