Solved

Monitoring system health on linux

Posted on 2006-06-19
15
341 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

724 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