DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 20th August 2009
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Post HOWTO: system load status in screen(1)

To be precise, not the load itself (0.00 0.00 0.00) but ...
CPU: 5.2% user, 0.0% nice, 19.0% system, 0.0% interrupt, 75.8% idle

... but like that (generally you may customize output as you need):
user: 5.2% | nice: 0.0% | system: 19.0% | interrupt: 0.0% | idle: 75.8%

Like on this window:


Now as you know what the end result will look like, lets describe needed steps to achieve this.

First, you need to have the uniload.sh script running in the background:
% uniload.sh &

The uniload.sh script itself:
Code:
#! /bin/sh

STATS_FILE=/var/tmp/${USER}_stats_top
DELAY=1

# FreeBSD uses jot(1) while Linux uses seq(1)
which jot 1> /dev/null 2> /dev/null || alias jot=seq

__freebsd() {
  top -s ${DELAY} -d 2 0  \
    | grep -m 1 CPU \
    | sed 's/,//g' \
    | awk '{ print $2": "$3" | "$4": "$5" | "$6": "$7" | "$8": "$9" | "$10": "$11 }'
  }

__linux() {
  top -d ${DELAY} -n 2 -b \
    | grep -m 2 Cpu \
    | tail -1 \
    | sed 's/%/ /g' \
    | awk '{ print "user: " $2 " | system: " $4 " | nice: " $6 " | idle: " $8 }'
  }

__exit() {
  rm -rf ${STATS_FILE}
  exit 0
  }

trap '__exit' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
OS=$( uname )
while true
do
  for I in $( jot 128 ); do
    case ${OS} in
      (FreeBSD) __freebsd >> ${STATS_FILE} 2>&1 ;;
      (Linux)   __linux   >> ${STATS_FILE} 2>&1 ;;
      (*)       echo "supported systems: FreeBSD Linux"; exit 1 ;;
    esac
  done
  sleep 1
  :> ${STATS_FILE}
done
The script periodically writes load data to /var/tmp/${USER}_stats_top file, which is later displayed by screen(1). To display these in screen(1) you need to add these lines into the ~/.screenrc config:

It will be like that for vermaden user:
Code:
backtick 100 5 5 tail -1 /var/tmp/vermaden_stats_top
caption always '%{= wk} %= %100` %='
Currently it works only on FreeBSD and Linux, but it will not be hard to add Solaris or Mac OS X support, Linux support has been added by DNAeon.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #2   (View Single Post)  
Old 20th August 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

screen? tmux is the new screen.
Reply With Quote
  #3   (View Single Post)  
Old 20th August 2009
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

GNU screen works very good for me, I do not have any reason to switch, of course BSD screen looks better then GNU screen, but I can live with that

Also, can I customize status bar in tmux as I have it now in screen?

I have seen that tmux displays some bar on bottom by default, but I havent checked if it can be modified.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #4   (View Single Post)  
Old 25th August 2009
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

Quote:
Originally Posted by vermaden View Post
Also, can I customize status bar in tmux as I have it now in screen?

I have seen that tmux displays some bar on bottom by default, but I havent checked if it can be modified.
Yes, I think you can. For example, you can run

$ tmux set-option status-right "Hello, world."

or more exciting

$ tmux set-option status-right "$(your_command_here)"

There is also status-left for an area on the left of the status bar, and the sizes of the areas can be changed. Check the man page; that's about all I know, have just been playing with it for a day or so.
Reply With Quote
  #5   (View Single Post)  
Old 25th August 2009
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

Thanks IdOp.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #6   (View Single Post)  
Old 16th September 2009
tangram's Avatar
tangram tangram is offline
Real Name: Ricardo Jesus
Port Guard
 
Join Date: May 2008
Location: Portugal
Posts: 36
Default

Works great. Thanks vermanden
__________________
BSD and Linux tips and tutorials: Blog Linux/BSD: sharing experiences
Reply With Quote
  #7   (View Single Post)  
Old 16th September 2009
tangram's Avatar
tangram tangram is offline
Real Name: Ricardo Jesus
Port Guard
 
Join Date: May 2008
Location: Portugal
Posts: 36
Default

Noticed that the output isn't correct, e.g. 0.0%: user | 0.0%: nice | 0.0%: system | 99.3%: interrupt | : idle.

The culprit is this part:
Code:
__freebsd() {
  top -s ${DELAY} -d 2 0  \
    | grep -m 1 CPU \
    | sed 's/,//g' \
    | awk '{ print $4": "$3" | "$6": "$5" | "$8": "$7" | "$10": "$9" | "$12": "$11 }'
  }
The fix is
Code:
__freebsd() {
  top -s ${DELAY} -d 2 0  \
    | grep -m 1 CPU \
    | sed 's/,//g' \
    | awk '{ print $2": "$3" | "$4": "$5" | "$6": "$7" | "$8": "$9" | "$10": "$11 }'
  }
__________________
BSD and Linux tips and tutorials: Blog Linux/BSD: sharing experiences
Reply With Quote
  #8   (View Single Post)  
Old 16th September 2009
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

Thanks, added.

When I was creating this HOWTO I generally did not used it, I have used it rather in the past
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #9   (View Single Post)  
Old 29th March 2010
tangram's Avatar
tangram tangram is offline
Real Name: Ricardo Jesus
Port Guard
 
Join Date: May 2008
Location: Portugal
Posts: 36
Default

Notice that top changed on FreeBSD 7.3-RELEASE/STABLE so the script needs to be updated to reflect it.

Namely, change from
Code:
__freebsd() {
  top -s ${DELAY} -d 2 0  \
    | grep -m 1 CPU \
    | sed 's/,//g' \
    | awk '{ print $2": "$3" | "$4": "$5" | "$6": "$7" | "$8": "$9" | "$10": "$11 }'
  }
to

Code:
__freebsd() {
  top -s ${DELAY} -d 2 0  \
    | grep -m 1 CPU \
    | sed 's/,//g' \
    | awk '{ print $4": "$3" | "$6": "$5" | "$8": "$7" | "$10": "$9" | "$12": "$11 }'
  }
__________________
BSD and Linux tips and tutorials: Blog Linux/BSD: sharing experiences
Reply With Quote
Old 29th March 2010
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

@tangram

Good to know, I havent used that 'monitoring' for ages

... propably about FreeBSD 6.1 last time.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the status of KDE4? wubrgamer General software and network 10 24th September 2008 03:58 AM
howto change 'uname -a' after base system U/G fallen FreeBSD Installation and Upgrading 8 16th July 2008 01:24 AM
Status of Xen on OpenBSD Oko OpenBSD General 2 19th June 2008 09:02 PM
Which file system use to share data on Bsd system? aleunix Other BSD and UNIX/UNIX-like 2 1st June 2008 04:14 PM
HOWTO: Clear console screen after logout vermaden Guides 0 5th May 2008 11:30 AM


All times are GMT. The time now is 05:48 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick