DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 

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 02:29 PM.


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