LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Script for monitoring system performance (http://www.linuxquestions.org/questions/linux-server-73/script-for-monitoring-system-performance-731643/)

Poma 06-09-2009 07:17 AM

Script for monitoring system performance
 
I want to make web interface to monitor my system resources. I've already made some long-term graphs using Collectd&Rrdtool but I also want to make some light-weight page with my current resources. What I want to do is to make shell(or perl) script that will collect system information and update web page every 10 seconds. Now I need some template script that collects all common performance data, such as CPU/memory/disk/network usage.

Marko Hyvärinen 06-09-2009 07:30 AM

change pvvali for interval time.
this show disk usage for our intranet server, insert free -th to show mem usage,
ifconfig|grep -i byte : show net statistics, and more:
who|awk -F. '{print $1"."$2}'
echo
netstat -an|grep -v -iE 'time_wait'|grep tcp|grep 19\.|awk '{print $5"\t"$4}'|grep -v \*
echo
#echo SMB-tiedostot
#smbstatus -L
echo "apache"
tail -n 5 /var/log/apache2/access_log
echo "ERRORLOG"
tail -n 5 /var/log/apache2/error_log
echo
echo
echo "vsftpd"
tail -n 5 /var/log/vsftpd.log

make your own, but i use this and many variants:

#!/bin/bash


pv=`date +%b" "%-d`
aika=`date +%T|tr ':' '.'`
pvm=$(date +" "%d.%m.%Y"")
pvvali=30

# The HTML output starts here
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Varmistus</title></head><body><pre>"

echo "<meta http-equiv="refresh" content="$pvvali">"

echo "<code>"
echo "T&auml;n&auml;&auml;n on $pvm, klo $aika<br>Sivu p&auml;ivittyy automaattisesti $pvvali sek. v&auml;lein."
echo "</code>"

echo "<p>"

echo "<p>"
df -h /lisatila|grep -i /|awk '{printf "Levyn k&auml;ytt&ouml;, lisatila: "$5}';echo " / 100% prosentista"

echo "<p>"


echo "<code>"
echo "<u>"
echo "<h1>Varmistus</h1>"
du -mhs /lisatila/varmistus/*
echo "<h1>Varmistusarkisto</h1>"
#du -mhs /lisatila/varmistusarkisto/*
ls -Ggah /lisatila/varmistusarkisto/*|awk '{print $3"\t"$4,$5"\t"$6"\t"$7}'|sort
#echo "<h1>Varmistusmedia USB-tikku</h1>"
#du -mhs /media/sda1/*
echo "<h1>Pitka-aikaisarkisto</h1>"
#du -mhs /lisatila/varmistusarkisto/*
ls -Ggah /lisatila/pitka-aikaisarkisto/*|awk '{print $3"\t"$4,$5"\t"$6"\t"$7}'|sort

echo "<h1>Varmistuslog</h1>"
tail -9 /lisatila/varmistuslog.txt
#cat /lisatila/varmistuslog.txt|grep -B 5 -i "$pv"
echo "</code>"
echo "</u"




echo "</body></html>";

ncsuapex 06-09-2009 08:33 AM

Check out nagios. It has built in support for a ton of server monitoring.

Poma 06-09-2009 10:22 AM

Nagios is too big and complicated for me. I have small private server for study.

pliqui 06-09-2009 02:13 PM

Try munin
 
Check Munin, this is a very light weight and easy to install system monitor, is not so powerful like nagios, but do the trick. I monitor my apache, squid, mysql and the resources of the machine.

Try it its very easy to install (i'm using debian so is in repos)and let me know what you think

And here are some How to forge guides for how to setup munin, since i don't know wich Os you are using, you can see if there is any guide for your distro.

Cheers

markseger 06-11-2009 07:47 AM

How about collectl? Very lighweight, uses <.1% cpu, has a socket interface to talk to other tools, saves history and can even write the current sample to a local file you could always read in a loop to extract the output. It's used on some of the largest clusters in the world - ever heard of the Top 500 list? It probably collects a lot more data than most tools. Check out this table I put together, keeping in mind it only shows a subset of what collectl can do: http://collectl.sourceforge.net/Matrix.html

By default it samples every 10 seconds but you can always make it more frequent if you prefer. I know of at least one 2500 node clusters where it's sampling each system every 5 seconds, storing the data in a local file and sending a subset upstream to a central monitoring station for display.

-mark

Poma 06-11-2009 01:57 PM

I need only current information but munin designed to write statistics to rrd logs. Do you know how to make munin or collectd to output current statistics to stdout?
Also one guy told me that sysstat package is a good thing. How about this one? Will it do the trick?

markseger 06-22-2009 09:22 AM

Collectl can report stats to the terminal in real-time. It can also write to a file and let you play the data back, but if you really only want current stats reported on the terminal that's fine too.

You can certainly use sysstat tools, but be aware that they take many lines of data to report what's going on and that can be pretty hard to read in real-time. In brief mode collectl can let you watch many things at once, all on the same line which makes it pretty easy to spot anomalous data.

-mark

goossen 06-22-2009 01:09 PM

What about MRTG ? You can monitor almost anything!

markseger 06-25-2009 06:13 AM

Part of it also comes down to how accurate you want your graphs to be. I had tried collecting samples every 10 seconds with collectl and stuffing them into rrd. Much to my surprise the graphs were NOT accurate as rrd 'normalizes' your data in less data points. In other words if you have 8640 data samples (a day's worth of 10 second samples) and try to plot it on a graph that only has 100 columns, you only get one column for every 86 samples! The plots look pretty but are only approximations. That's why I use gnuplot - it plots everything even if the results aren't as good looking.
-mark


All times are GMT -5. The time now is 09:24 PM.