0

Is there a command which outputs just current CPU usage percentage and current memory usage percentage? As a single number, so no tables or formatted output.

The reason I'm asking. For my panel in XFCE I'd like to see something like this:

CPU 34% | MEM 56%

I haven't found a plugin which does that, so I aim to use the Generic Monitor plugin and give it a command which it should print and let it update every 1 sec.

arjobsen
  • 313
  • 2
  • 12
  • 1
    "No tables or formatted output" is a non-Linux attitude, isn't it ? Grep, grep, grep... –  Sep 16 '18 at 13:50
  • A command using grep or other piped commands is of course also fine. But I can't figure out (or find online) how to build one so that 1 value comes out – arjobsen Sep 16 '18 at 14:19

1 Answers1

0

Put the following snippet somewhere in a script:

#!/bin/bash

CPU=$(lscpu | grep '\(CPU\|max\) MHz:' | xargs echo | awk '{printf "%3.0f\n", $3*100/$7}')
MEM=$(free | grep Mem | awk '{printf "%3.0f\n", $3*100/$2}')
echo CPU $CPU% \| MEM $MEM%

And call it from genmon as bash /path/to/this/script.sh.

AndreLDM
  • 2,117
  • 1
  • 18
  • 27