1

I have a fresh install of Xubuntu 18.04 LTS. I'd like to display in text, not in graphical form, the CPU (% used), RAM (% used), and Battery usage (% avail.) in the top panel near the clock.

I'm having trouble learning how to do this or whether it's possible because of outdated information from previous versions and the available solutions focus on showing a graph in the top panel. I'd rather see text and numbers like CPU: 05% RAM: 10% BAT: 50%

Is this something that Xubuntu can be configured to do? As an Xubuntu user, I'd prefer the most lightweight solution I can find, in terms of resource usage and dependencies.

3

If you can't find a prepackaged solution, you can roll your own.

As part of Xfce, the Generic Monitor panel item should be available in your panel's "Add New Items" list. If not, it should be available as xfce4-genmon-plugin in your repo. From it's About dialog: "Cyclically spawns a script/program, captures its output and displays the resulting string in the panel".

Using the Generic Monitor, you can run a script that returns the info you need, like the one I pieced together:

#!/usr/bin/perl

# stats.pl - returns CPU and RAM usage


# CPU stuff

my $cpuusage = `top -bn 2 -d 0.2 | grep '^%Cpu' | tail -n 1 | gawk '{print \$2+\$4+\$6}'`;
chomp $cpuusage;
$cpuusage =~ s/^([0-9][0-9]*)(\.[0-9][0-9]*)$/$1/;
printf "CPU: %02d%% ","$cpuusage";


# RAM stuff

my $total = `grep -e "^MemTotal" -m 1 /proc/meminfo`;
$total =~ s/([^0-9]*)([0-9]*)(.*)$/$2/;

my $available = `grep -e "^MemAvailable" -m 1 /proc/meminfo`;
$available =~ s/([^0-9]*)([0-9]*)(.*)$/$2/;

my $memusage = 100 - ($available / $total * 100);
printf "RAM: %02d%%\n","$memusage";

The CPU stuff is based on What are the methods available to get the CPU usage in Linux Command line?, and the RAM stuff is based on How can I get processor/RAM/disk specs from the Linux command Line?

Generic Monitor displays the output of stats.pl in a panel as expected (for comparison, the graphic CPU and RAM info is my conky display):

Example of Generic Monitor displaying CPU and RAM info

My machine's a desktop, so I have no battery. From poking around a bit, though, upower seems to look promising for the battery info. For example, see 5 Ways To Check Laptop Battery Status And Level From Linux Terminal.

  • For battery, I use xfce4-genmon-plugin. It runs a script with this: status=$(cat /sys/class/power_supply/BAT0/capacity); echo "$status% " In my experience other laptops have been BAT1. – jbrock 2 days ago
  • Also, (more succinct) echo "BAT: $(</sys/class/power_supply/BAT0/capacity)% ". – jbrock 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.