Solved

Monitoring system health on linux

Posted on 2006-06-19
15
333 Views
Last Modified: 2013-12-06
I am running Red Hat EL 4, and I need to check the CPU useage, memory useage, disk useage, and network useage and write those values to an XML file as a percentage of total capacity.

The format needs to be something like this:
<cpu>48.0</cpu>
<ram>32.5</ram>

The file needs to be updated with new values every 5 seconds or so. Any ideas?
0
Comment
Question by:Thanatos2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 22

Expert Comment

by:pjedmond
ID: 16936581
Yes....lots of ideas;)
0
 
LVL 22

Accepted Solution

by:
pjedmond earned 125 total points
ID: 16936618
Disc bit is easy:

df | grep /dev/hda2 | awk {'print "<disc>" $5 "</disc>"'}
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16936759
RAM not too difficult:

cat /proc/meminfo | grep "Mem:" | awk '{t=int($2);u=($3); printf "<ram>%02.0f\%</ram>\n", (100*u/t)}'
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 22

Expert Comment

by:pjedmond
ID: 16936876
cpu idle is reasonably easy:

top -b -n1 | sed -n '6p' | awk {'print "cpu>" $8+0 "</cpu>"'}

(The +0 forces it to get rid of the %. Note that top -b, seems to add 2 extra lines on my test system, you may need to correct this for your system by changing the 6p to 4p, or whatever by trial and error.

Total cpu is also not to bad:

top -b -n1 | sed -n '6p' | awk {'print "cpu>" $2+$3+$4+$5+$6+$7 "</cpu>"'}

Now to put into a suitable script:)



0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16937028
report.sh:

-------8X---------
#!/bin/bash

while true; do
        df | grep /dev/hda2 | awk {'print "<disc>" $5 "</disc>"'}
        cat /proc/meminfo | grep "Mem:" | awk '{t=int($2);u=($3); printf "<ram>%02.0f\%</ram>\n", (100*u/t)}'
        top -b -n1 | sed -n '6p' | awk {'print "<cpu>" $2+$3+$4+$5+$6+$7 "%</cpu>"'}
sleep 300
done
-------8X---------

Obviously it takes time to run the commands, so it isn't exactly synchronised......

./report.sh > logfile.txt

Obviously, you might decide to add so date stamping in some form with the date command?

However...you may wish to look at nagios:

www.nagios.org

or mon:

www.kernel.org/software/mon

before trying to re-invent the wheel? Alternatively, as they are open source, you may pick up a few nice ideas from them:)

With respect to network monitoring, there is no % useage that I am aware of. What you could do is over a period of time record the number of packets sent, (cat /proc/net/dev), and then look at the number of packets sent in a 5 minute period as a percentage of a theorectical maximum, but this would not be realistic, so you'll have to have a bit of a re-think as to exactly what you'd like to record there.

HTH:)

0
 
LVL 16

Assisted Solution

by:xDamox
xDamox earned 125 total points
ID: 16937050
Hi,

CPU usage can be captured by doing:

top | awk '/Cpu\(s\)/ { print "<cpu>", $2, "</cpu>" }'

The Memory usage can be captured by doing:

top | awk '/Mem:/ { print "<memory>",$5,"</memory>" }'

0
 
LVL 17

Assisted Solution

by:owensleftfoot
owensleftfoot earned 125 total points
ID: 16937095
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16937170
Worth noting that xDamox's solutions don't work for me as my top output is:
-------------------8X---------------------------------
103 processes: 100 sleeping, 3 running, 0 zombie, 0 stopped
CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle
           total    0.3%    0.0%    0.0%   0.0%     0.0%    0.0%   99.6%
Mem:   513504k av,  497544k used,   15960k free,       0k shrd,  224284k buff
                    377012k actv,   71784k in_d,    6988k in_c
Swap: 1044216k av,  122120k used,  922096k free                   98408k cached
-------------------8X---------------------------------

My tests were carried out on a RHEL3 server, so it is possible that RHEL4 may be slightly different? The same applies to the /proc/

paths, as the names may have changed slightly in RHEL4?
0
 
LVL 16

Expert Comment

by:xDamox
ID: 16938609
For your information pjedmond mine was tested on: Fedora

top - 23:54:39 up 2 days, 10:44,  2 users,  load average: 0.35, 0.25, 0.09
Tasks: 105 total,   1 running, 104 sleeping,   0 stopped,   0 zombie
Cpu(s):  7.8% us,  1.6% sy,  0.3% ni, 89.9% id,  0.4% wa,  0.0% hi,  0.0% si,  0.0% st
Mem:    515764k total,   379384k used,   136380k free,    21396k buffers
Swap:  1052248k total,    75996k used,   976252k free,   228492k cached
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16938691
xDamox - Can I ask which version of FC?
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16938701
Always nice to have a sanity check to look out for mistakes and spurious differences. Morale of the story is that Thanatos2k is going to have to understand the scripts before using them;)
0
 
LVL 16

Expert Comment

by:xDamox
ID: 16940104
pjedmond Fedora Core 5
0
 
LVL 9

Assisted Solution

by:gtkfreak
gtkfreak earned 125 total points
ID: 16940775
Try out ksysguard in case you are using KDE Desktop or gnome-system-monitor in case you are using the Gnome Desktop
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question