Monitoring log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitoring log file
# 1  
Old 02-05-2009
Monitoring log file

Hi,

I ned to monitor the tomcat log file called "catalina.out" for "Out of memory" error.

the script should monitor this file and send us the mail as soon as it finds the string "Out of memory" in the file.

can ypu suggest me which is the best way to do this?
# 2  
Old 02-05-2009
Quote:
Originally Posted by shivanete
Hi,

I ned to monitor the tomcat log file called "catalina.out" for "Out of memory" error.

the script should monitor this file and send us the mail as soon as it finds the string "Out of memory" in the file.

can ypu suggest me which is the best way to do this?

Code:
tail -f catalina.out |
 while read line
 do
   case $line in
    'Out of memory') printf "%s\n" "$line" |
        mail -s "Tomcat out of memory" someone@example.com
        ;;
   esac
 done

# 3  
Old 02-05-2009
Of course you can do some scripting like grep or perl yourself coupled with a cron schedule for a more typical sysadmin way to do it. However, I believe fellow users here are far more experienced in this sort of scripting so I tend not to speak so much.

Pardon me for a bit of irrelevence to your question. However, I don't think monitoring the log file as a solution to handling "out of memory" is a good approach.

Just to share with you what happened recently with me. In fact I have a test virtual server running JBoss in it, the JBoss died on 24/1 and OutOfMemory was never observed until yesterday. This is because it was a test VM and nobody else would be accessing that unless I need to. The exception was logged but according to log it took just a few minutes afterwards that the JVM crashed to such a state that even the logging system failed. Luckily that was not a production machine.

Monitoring the log file, you cannot be polling it all the time. However, whenever a process gets the chance to poll and find that the exception was logged, the JVM has already been in a dead state and you'll still suffer downtime before the restart is complete - just that you know it sooner to avoid the kind of several days of non-discovery otherwise.

If your situation permits, a better approach is to intervene before the JVM gets out of memory, so that you can plan for a graceful restart ahead and avoid all those embarrassness. Today's JVM already have monitoring mechanism builtin (JMX) that you can easily monitor the memory consumption locally or remotely, unless you're still using old JVMs like 1.x that did not have this feature. So if you see the heap size is over a certain threshold say 70% then an email will be sent to you. Well, I believe this is exactly a reason I would invite others to consider migrating to a more recent JVM ......
# 4  
Old 02-05-2009
Quote:
Originally Posted by cfajohnson
Code:
tail -f catalina.out |
 while read line
 do
   case $line in
    'Out of memory') printf "%s\n" "$line" |
        mail -s "Tomcat out of memory" someone@example.com
        ;;
   esac
 done


I am using AIX unix server, so is this the syntax for AIX?
# 5  
Old 02-05-2009
Quote:
Originally Posted by shivanete
I am using AIX unix server, so is this the syntax for AIX?

It is the syntax for the standard UNIX shell, and it should work in any Bourne-type shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script for continuously monitoring log file

Hi I have written below log monitoring script to egrep multiple words and redirect the output to a text file and its working fine but I want to add some more below given functionality to it, which is very advance and im not very good in it, so please help if you can :) I am egrepping all the... (1 Reply)
Discussion started by: scazed
1 Replies

2. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

3. UNIX for Beginners Questions & Answers

Monitoring script for Log file

Hi, Iam new to unix , plz help me to write below script. I need to write a script for Monitoring log file when any error occurs it has to send a mail to specified users and it should be always pick latest error not the existing one and the script should be able to send mail all errors (more... (1 Reply)
Discussion started by: vij05
1 Replies

4. UNIX for Advanced & Expert Users

Alternative to tail -n -0 -F for monitoring live log file

Hello, I have been working on script which need to generate an alert based upon live logs. If string is found then an alert mail must triggered. tail -n -0 -F works fine to redirect the each latest line from live logs file to grep a pattern for matching but it seems to be not working on... (7 Replies)
Discussion started by: ketanraut
7 Replies

5. Shell Programming and Scripting

Monitoring script for a log file

Hi, I need to get a script working to monitor a log file and throw an alert via mailx as soon as a particular error is encountered. I do not want repeatative email notifications of same error so simply cat logfile and grepping the error would not work. Here is what i planned but it seems... (2 Replies)
Discussion started by: roshan.171188
2 Replies

6. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

7. Solaris

Monitoring log file for entries - Find command & sorting

hi, I would like to monitor a log file, which rolls over, everytime a server is restarted. I would like to grep for a string, and to be more efficient i'd like to grep only newly appended data. so something like a 'tail -f' would do, however, as the log rolls over i think a 'tail -F' is... (2 Replies)
Discussion started by: horhif
2 Replies

8. Shell Programming and Scripting

Tomcat Monitoring log file

Hi, I ned to monitor the tomcat log file called "catalina.out" for "OutOfMemory" ,"java.sql.SQLException" and "Error" error. the script should monitor this file (catalina.out) and send us the mail as soon as it finds the string "Out of memory" or "java.sql.SQLException" or "Error" in the... (2 Replies)
Discussion started by: mnmonu
2 Replies

9. Shell Programming and Scripting

help needed - log file monitoring script

hi Gurus, Need to pick your brains on this minor script project. I would like to continuously monitor a log file with sample log messages as below, and if PSOldGen percentage is either 99% or 100% for consecutively 10 times, alert someone. {Heap before gc invocations=46516: PSYoungGen ... (6 Replies)
Discussion started by: kenchen722
6 Replies

10. UNIX for Dummies Questions & Answers

log monitoring

Hi there, I have an application runnig on HP_UX which logs critical mesages to a log file. What I would like to do is tail the log file and report on new messages. Easy....I here you say. The log file is continuing to be written to and the check scritp will be executed from cron. I was... (2 Replies)
Discussion started by: nhatch
2 Replies
Login or Register to Ask a Question