Question

I use screen a lot on my Linux. I wanted to change the hardstatus line a bit. I want to add CPU and Memory usage information to the line but I don't know how. after some searches in Google all I could find was %l option to add system loads.

my line (which is copied) looks like this:

hardstatus alwayslastline '%{= G}[ %{G}%H %{g}][%= %{= w}%?%-Lw%?%{= R}%n*%f %t%?%{= R}(%u)%?%{= w}%+Lw%?%= %{= g}][ %{y}Load: %l %{g}][%{B}%D %d-%    M-%Y %{W}%C:%s %A %{g}]'

and my screen hardstatus line is like this: enter image description here

now what are the three numbers defined ad load ?? and how can I change them to something like CPU load 28% Mem Load 43% or similar?

Was it helpful?

Solution

To keep it short:

The three numbers stand for average cpu load during the last minute, 5 minutes and 15 minutes where 0 means 0% load and 1.0 means 100% load.

Have a look at this excellent explanation of the cpu load.

For the second question I'm not sure if you can express the system load with only one number in the hardstatus line of screen (I don't think so), but I hope my answer helped a little bit ;-) *Jost

OTHER TIPS

If you haven't heard of the screen command backtick since then, this could be your favourite (http://aperiodic.net/screen/commands:backtick).

You can for example define a series of linux ($BASH or sh) commands which echoes your own calculated load value and your own calculated mem-usage value within the backtick command.

In this example let's assume that you just want to display the second value of the "load average" statistic given by "uptime" (the 5 minutes statistic).

Step 1: If your "uptime" output would look like this (with a space at the beginning of the line and 2 spaces before "load average:")...

 17:04:06 up 3 days, 21:52, 12 users,  load average: 0.36, 0.27, 0.21

... you could extract your value like this into the variable cpuLoad (and get rid of the trailing "comma"):

cpuLoad=$(cut -s -d\  -f13 <(uptime))
cpuLoad=${cpuLoad:0:-1}

Step 2: Similarily you could extract your memory values from the output of the "free" command and do some calculations explained in this fine article which would end up in a variable named memLoad (abbreviated here by "memLoad=...").

Step 3: Put it all together and echo your output as you would like to see it:

backtick 1 5 5 /bin/bash -c 'cpuLoad=$(cut -s -d\  -f13 <(uptime)); cpuLoad=${cpuLoad:0:-1}; memLoad=...; echo "CPU load ${cpuLoad} Mem Load ${memLoad}" '

This will update every 5 seconds the values in your hardstatus or caption status-lines, using the escape-sequence "%1`" in your "hardstatus string" definition.

For more calculations you will need more space which has to be all on one line. So put it in a shell function and call the function from within your screenrc file:

backtick 1 5 5 /bin/bash -c '_mySystemLoadScreenFunction'

What also did not work for me was using $BASH instead of the full path. This did NOT work:

backtick 1 5 5 $BASH -c '_mySystemLoadScreenFunction'

Hope, this helps. Thank you very much for your attention.

To expand on the answer of @richard-gantz, here is my solution to also extract the memory usage from free

backtick 1 1 1 /bin/bash -c 'cpuLoad=$(cut -s -d\  -f16 <(uptime)); cpuLoad=${cpuLoad:0:-1}; memLoad=$(free -g | grep Mem | awk '\''{print $3"/"$2" GB"}'\''); echo "CPU: ${cpuLoad} Mem: ${memLoad}" '

# Display the status line at the bottom
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.kW}%-w%{.bW}%t [%n]%{-}%+w %= %{..R} %1` %{..G} %H %{..Y} %Y/%m/%d %c"

I took his solution for cpuLoad using cut but could not get cut to work with the multiline output from free, hence the solution with grep and awk. I am posting it here, because it took me some time this solution out, so it might be helpful for somebody.

The memory usage is used_mem / total_mem in GB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top