performance script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting performance script
# 1  
Old 05-01-2009
performance script

Hi guys, I am trying to create a script that will email me when ram or cpu usage gets above a certain level.

I am trying to use grep and awk on the top command but the list keeps changing. Could anyone give me any pointers on what is best to use for this kind of thing.

Thanks

Jon
# 2  
Old 05-01-2009
use vmstat


Code:
vmstat 900 2 | tail -1

mean from 15 minutes


process with read
eq.

Code:
vmstat 900 2 | tail -1 | read r b swpd free buff cache si so ....


if [[ $id -lt value || $free -lt value || $..... ]]
then 
echo "cpuid $id, memfree $free" | mail -s subject emailaddress 
fi

for example

let it run from cron,

or use vmstat 900 | while read ....

Last edited by funksen; 05-01-2009 at 09:38 AM..
# 3  
Old 05-01-2009
I'd just like to mention that if you have more than one machine that you'd like to monitor, you'd be much better served by installing a monitoring package.

There are lots and lots of them out there, from the very simple munin types to Nagios, both free and commercial.

If it's a single machine then shell scripts are fine for this sort of thing, but even they can get unwieldy if you try to monitor too much. Most monitoring packages will have notification built in.
# 4  
Old 05-01-2009
Thanks for that funksen!
Kodak: Ive seen alot of monitoring packages but i thought i might give a shell script a chance before i do. Are there any specific packages you may recommend?

thanks
# 5  
Old 05-01-2009
It all depends on what you want to do.

Munin is dead simple to set up, but its capabilities by itself are pretty slim. Nagios is very capable, but more complex to configure, and doesn't graph out of the box (there are plugins that do so.)

I wish I could tell you "use this" but I can't. Sorry. :/
# 6  
Old 05-01-2009
Munin: simple, easy to set up, but due to how RRDtool works you'll loose accuracy on older measurements. Also you'll have to hack it if you want anything but the default 5 minute resolution, you'll have to manually correlate graphs, and most plugins are written for Linux (extensive use of /proc and iptables)

Nagios: complex, but very powerful.

Zabbix: (no personal experience, but Neo mentioned it once) Also, very powerful, and seems to support graphing and reports out of the box.
# 7  
Old 05-02-2009
And then there's collectl - see: collectl

It can do most anything from simple interactive monitoring of a few 'subsystems' like cpu, disk, etc and/or writing the data to disk and letting you play it back later. For more advanced topics you can have it send its data to higher level monitoring tools like ganglia.

It even has a --vmstat switch which means you can play back old data in vmstat format with timestamps, just one of many options.

The key is collectl is very lightweight, using less than 0.5% CPU when sampling everything every 10 seconds. Most users simply enable it as a daemon and keep it running forever. Then if you have a problem, the data you need has probably already been collected for you.

-mark
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance issue in shell script

Hi All, I am facing performance issue while rinning the LINUX shell script. I have file1 and file 2. File one is the source file and file 2 is lookup file. Need to replace if the pattern is matching in file1 with file2. The order of lookup file is important as if any match then exit... (8 Replies)
Discussion started by: ureddy
8 Replies

2. UNIX for Dummies Questions & Answers

How to improve the performance of this script?

Hi , i wrote a script to convert dates to the formate i want .it works fine but the conversion is tkaing lot of time . Can some one help me tweek this script #!/bin/bash file=$1 ofile=$2 cp $file $ofile mydates=$(grep -Po '+/+/+' $ofile) # gets 8/1/13 mydates=$(echo "$mydates" | sort |... (5 Replies)
Discussion started by: vikatakavi
5 Replies

3. Shell Programming and Scripting

AIX CPU performance script ?

I want to write a shell script which will print AIX CPU utilization memory utilization every 5 mins redirect to file. How do i do it? Please advise. Which commands I should use? (3 Replies)
Discussion started by: vegasluxor
3 Replies

4. Shell Programming and Scripting

Want to improve the performance of script

Hi All, I have written a script as follows which is taking lot of time in executing/searching only 3500 records taken as input from one file in log file of 12 GB Approximately. Working of script is read the csv file as an input having 2 arguments which are transaction_id,mobile_number and search... (6 Replies)
Discussion started by: poweroflinux
6 Replies

5. Shell Programming and Scripting

Script performance issue

hi i have written a shell script which comapare a text file data with files within number of different directories. example. Text File: i have a file /u02/abc.txt which have almost 20000 file names Directories: i have a path /u03 which have some subdirectories like a,b,c which have almost... (2 Replies)
Discussion started by: malikshahid85
2 Replies

6. Shell Programming and Scripting

Any way to improve performance of this script

I have a data file of 2 gig I need to do all these, but its taking hours, any where i can improve performance, thanks a lot #!/usr/bin/ksh echo TIMESTAMP="$(date +'_%y-%m-%d.%H-%M-%S')" function showHelp { cat << EOF >&2 syntax extreme.sh FILENAME Specify filename to parse EOF... (3 Replies)
Discussion started by: sirababu
3 Replies

7. Shell Programming and Scripting

Performance issue with awk script.

Hi, The below awk script is taking about 1 hour to fetch just 11 records(columns). There are about 48000 records. The script file name is take_first_uniq.sh #!/bin/ksh if then while read line do first=`echo $line | awk -F"|" '{print $1$2$3}'` while read line2 do... (4 Replies)
Discussion started by: RRVARMA
4 Replies

8. News, Links, Events and Announcements

Announcing collectl - new performance linux performance monitor

About 4 years ago I wrote this tool inspired by Rob Urban's collect tool for DEC's Tru64 Unix. What makes this tool as different as collect was in its day is its ability to run at a low overhead and collect tons of stuff. I've expanded the general concept and even include data not available in... (0 Replies)
Discussion started by: MarkSeger
0 Replies

9. UNIX for Advanced & Expert Users

Performance of a shell script

Hiii, I wrote a shell script for testing purpose. I have to test around 200thousand entries with the script.When i am doing only for 6000 entries its taking almost 1hour.If i test the whole testingdata it will take huge amount of time. I just want to know is it something dependent on the... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. Shell Programming and Scripting

Script for system performance

I need to prepare script which will run as background process ever 30 mins to collect the following information 1. Memory usage. 2. CPU usage. 3. Number processors running. 4. System resource (CPU and Memory) used by each process. 5. Number of sessions logged PLEASE HELP ME OUT FROM THIS ... (2 Replies)
Discussion started by: vastare
2 Replies
Login or Register to Ask a Question