GNU+Linux command memo

Display hardware status in screen sessions

Afficher des informations sur le matériel de la machine (occupation CPU et mémoire) dans la ligne d’état de screen. Ça peut aider à diagnostiquer rapidement pourquoi la machine ne vous rend pas la main par exemple (est-elle occupée ou est-ce une panne réseau ?).

Screen can display a permanent status line with various informations. It might look like this (with various colors) :

 3 <hostname>               Load: 0,88 0,21 0,08  Mem: 1 / 3 G  2024-06-05 10:44

Here is how to get this :

$ vi ~/.screenrc

Add the following lines in the file (that might not exist before and can contain other useful settings) :

backtick 1 1 1 /bin/bash -c 'memLoad=$(free --giga | grep Mem | awk '\''{print $3" / "$2}'\''); echo "Mem: ${memLoad} G" ' (1)

hardstatus alwayslastline (2)
hardstatus string '%{wk} %n %H %=%{Yk} Load: %l %{Mk} %1` %{wk} %Y-%m-%d %c ' (3)
1 This creates a new replacement token for the status line definition. Here it’s a shell oneliner to extract the current RAM usage from the free command
2 Here we tell screen to display the status line, and to do it on the bottom of the screen.
3 Here we define what to display in the status line :
  • %{wk} is a replacement token that adds the necessary terminal escape sequence to write in white text on black background

  • %n %H is the buffer number in the screen session followed by the host name

  • %= is an expendable white space

  • %{Yk} changes the color of the next characters to bright yellow text on black background

  • %l is the machine load averages

  • %1` is the result of our backtick defined command

  • … (read man screen for more escape sequences)

To test this settings you can start a new screen session or reload the settings of your current session via : CTRL+A : source ~/.screenrc

To finish, it exists at least screen-cpu-mem and rainbarf to create better backtick tokens for your status line with graphical levels or charts of CPU and memory usage.