Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Monitoring system health on linux

Posted on 2006-06-19
15
Medium Priority
?
361 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
13 Comments
 
LVL 22

Expert Comment

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

Accepted Solution

by:
pjedmond earned 500 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
Technology Partners: 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!

 
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 500 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 500 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 500 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 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