LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   monitoring Linux (https://www.linuxquestions.org/questions/linux-newbie-8/monitoring-linux-607000/)

yusufs 12-15-2007 02:20 PM

monitoring Linux
 
Dear all,

we are running oracle on Linux RHEL ES 4.0...

I use to monitor OS using the following commands :

df -h
free -m
sar 1 5
top

what else can you suggest to check inorder to avoid any disaster



Thanks
Yusuf

btmiller 12-15-2007 03:18 PM

Become familiar with the system logs (the files in /var/log) and read them. If you have a lot of systems to monitor you can use something like Nagios to monitor them from one central console.

snowman81 12-15-2007 06:01 PM

I would also recommend a search for different monitoring commands. Often times there are small innocuous programs that you don't know about that are extremely useful.

dv502 12-15-2007 07:59 PM

Here are some other basic monitoring commands

who or w


To monitor currently logged in users

ps -aux

Check for running processes

last

list previous logins

crontab -l


Check if you or anyone is running any schedule jobs

netstat -tap


Check for active tcp connections to and from your computer and what ports your computer is listening to. The p option tells which program is being used.

There are many more commands in linux, but it depends what kind of monitoring you looking for. For example IDS intrusion detection system.

matthewg42 12-15-2007 10:01 PM

htop is a good alternative to top. It's a little more feature-rich, and is in colour!

yusufs 12-16-2007 12:17 AM

Quote:

Originally Posted by matthewg42 (Post 2991900)
htop is a good alternative to top. It's a little more feature-rich, and is in colour!

Thankyou miller,snowman,DV502 and mathew for your excellent answers, that really helped me..

Is there anyway,I can have the monitorin commands in a script and run it periodically.give me a example.. I will develop the remaining..


Thanks in advance
Yusuf

matthewg42 12-16-2007 05:51 AM

Yes, it is possible. You just have to make sure the commands will not run indefinitely. htop and top, when invoked normally use a curses interface, which cannot usefully be re-directed to a file, but top has a batch mode for just this sort of thing.

You could write a simple script like this:
Code:

#!/bin/bash

LOGFILE=/path/to/your/logfile.log

echo "Logging system stuff at $(date)" >> "$LOGFILE"
# log vmstat.  3 * 5 second interval.  Probably better than 1 second as it
# gives more time to average out the load analysis.
vmstat 5 3 >> "$LOGFILE"

# make a blank line between commands to help readability.
echo "" >> "$LOGFILE"

top -b -n 1 >> "$LOGFILE"
echo "" >> "$LOGFILE"
w >> "$LOGFILE"
netstat -tap >> "$LOGFILE"
echo "" >> "$LOGFILE"
echo "" >> "$LOGFILE"

...and so on - just add anything you like there. The important thing is that the program will not wait for input from the user (like top in interactive mode).

You can then call this script from cron every 5 minutes or something like that. Use the command "crontab -e" and then enter a line:
Code:

*/5 * * * * /path/to/your/script.sh

syg00 12-16-2007 06:11 AM

You mentioned "sar" - that is from the sysstat package.
Properly implemented that will have all the history (and more) that you could need.
No need for extra scripts.

yusufs 12-29-2007 04:30 AM

Quote:

Originally Posted by matthewg42 (Post 2992088)
Yes, it is possible. You just have to make sure the commands will not run indefinitely. htop and top, when invoked normally use a curses interface, which cannot usefully be re-directed to a file, but top has a batch mode for just this sort of thing.

You could write a simple script like this:
Code:

#!/bin/bash

LOGFILE=/path/to/your/logfile.log

echo "Logging system stuff at $(date)" >> "$LOGFILE"
# log vmstat.  3 * 5 second interval.  Probably better than 1 second as it
# gives more time to average out the load analysis.
vmstat 5 3 >> "$LOGFILE"

# make a blank line between commands to help readability.
echo "" >> "$LOGFILE"

top -b -n 1 >> "$LOGFILE"
echo "" >> "$LOGFILE"
w >> "$LOGFILE"
netstat -tap >> "$LOGFILE"
echo "" >> "$LOGFILE"
echo "" >> "$LOGFILE"

...and so on - just add anything you like there. The important thing is that the program will not wait for input from the user (like top in interactive mode).

You can then call this script from cron every 5 minutes or something like that. Use the command "crontab -e" and then enter a line:
Code:

*/5 * * * * /path/to/your/script.sh




Thank you mathew always, I've solved many of real time issues with your help.. and now this time, if you can also tell me.. how to get the output of this script to a mail.. in otherwords, from the above it is storing it in a logfile, where as what can I do to recieve the output in mail using send mail.

Please help


Thanks
Yusuf

twantrd 12-29-2007 05:09 AM

Quote:

and now this time, if you can also tell me.. how to get the output of this script to a mail
Here it is
Code:

cat $LOGFILE | mail -s "Contents of my LOGFILE" user@company.com
-twantrd

yusufs 12-29-2007 05:23 AM

Quote:

Originally Posted by twantrd (Post 3004712)
Here it is
Code:

cat $LOGFILE | mail -s "Contents of my LOGFILE" user@company.com
-twantrd


Thanks a lot Twantrd..



am using the following script :
***********************************************************************
[root@oracle ~]# sh /root/test/tests/test/sysos.sh

LOGFILE=/home/oracrp/test/sysos.log
+ LOGFILE=/home/oracrp/test/sysos.log

echo "Logging system log at $(date)" >> "$LOGFILE"
date
++ date
+ echo 'Logging system log at Sat Dec 29 14:10:27 AST 2007'
# log vmstat. 3 * 5 second interval. Probably better than 1 second as it
# gives more time to average out the load analysis.

sar 1 5 >> $LOGFILE
+ sar 1 5


#/usr/sbin/sendmail erp_webmail@ali.com.kw << EOM
#From:DBA
#To:Yusuf
#Subject:$(date +%d-%b-%Y) Alert Log Error

#EOM

# make a blank line between commands to help readability.
echo "" >> "$LOGFILE"
+ echo ''

top -b -n 1 >> "$LOGFILE"
+ top -b -n 1
echo "" >> "$LOGFILE"
+ echo ''

w >> "$LOGFILE"
+ w

#netstat -tap >> "$LOGFILE"
echo "" >> "$LOGFILE"
+ echo ''
echo "" >> "$LOGFILE"
+ echo ''


#/usr/sbin/sendmail erp_webmail@ali.com.kw << EOM
#From:DBA
#To:Yusuf
#Subject:$(date +%d-%b-%Y) SYSOS

#EOM

cat $LOGFILE | mail -s "Contents of my LOGFILE" erp_webmail@ali.com.kw
+ cat /home/oracrp/test/sysos.log
+ mail -s 'Contents of my LOGFILE' user@company.com

***********************************************************************


am goin to have the above script in CRON which runs every 1 hour and sends a mail to the user. but since, the logfile is getting accumulated every time the script runs, so it sends the complete logfile contents to the user.. is there anyway,I can overcome this such that it should send only the last time executed commands output to the mail ?

Please help


Thanks
Yusuf

twantrd 12-29-2007 04:26 PM

That's because you are using '>>' which APPENDS the output to the logfile. To do what you want, change only the first instance of writing the logfile to '>'.

-twantrd

yusufs 12-30-2007 04:48 AM

Quote:

Originally Posted by twantrd (Post 3005193)
That's because you are using '>>' which APPENDS the output to the logfile. To do what you want, change only the first instance of writing the logfile to '>'.

-twantrd

Excellent twanrd, it works fine


Thanks
Yusuf


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