This shows you the differences between two versions of the page.
sar_reporting [2012/04/30 15:15] k2patel [Notify Script] |
sar_reporting [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Sar Reporting ====== | ||
- | This will give you graphical representation of system load.\\ | ||
- | Also you can use it for capacity Planning.\\ | ||
- | OR simply monitoring. Easy system monitoring with SAR | ||
- | |||
- | ==== Requirement Specification ==== | ||
- | Following perl module require to be installed. | ||
- | |||
- | <code perl> | ||
- | Getopt::Std | ||
- | Time::Local | ||
- | Date::Calc | ||
- | Email::Date::Format | ||
- | </code> | ||
- | |||
- | Following Packages from centOS / Redhat / Fedora need to be installed. | ||
- | |||
- | <code bash> | ||
- | yum install -y local-perl-Date-Calc.x86_64 perl-Date-Calc.x86_64 rrdtool.x86_64 sysstat.x86_64 perl-MIME-Lite.noarch | ||
- | </code> | ||
- | |||
- | Make following directory and **place all script in "/root/sar" folder**. | ||
- | |||
- | <code bash> | ||
- | mkdir -p /root/sar/{img,rrd,xml} | ||
- | </code> | ||
- | |||
- | Finally add it to cron. | ||
- | |||
- | <code bash> | ||
- | |||
- | # SAR Stats | ||
- | 20 0 * * * /root/sar/sa_report.sh >/dev/null 2>&1 | ||
- | |||
- | </code> | ||
- | |||
- | ==== Terms Used ==== | ||
- | <code text> | ||
- | tps: total number of transfers/sec | ||
- | rtps: total number of read requests/sec | ||
- | wtps: total number of write requests/sec | ||
- | bread/s: Total amount of data read from the drive in blocks per second. A block is 512 bytes. | ||
- | bwrtn/s: Total amount of date written to the drive in blocks per second. | ||
- | </code> | ||
- | ==== sa report ==== | ||
- | This script goes to cron. | ||
- | |||
- | <code bash | sa_report.sh> | ||
- | #!/bin/bash | ||
- | # Developed by k2patel@gmail.com | ||
- | |||
- | dtm=$(date -d 'now -1 days' +%d) | ||
- | sar=$(which sar) | ||
- | perl=$(which perl) | ||
- | location='/root/sar' | ||
- | |||
- | cd $location | ||
- | # $sar -q -b -d -u -p -r -n DEV -f /var/log/sa/sa$dtm > sa$dtm.txt | ||
- | |||
- | $sar -f /var/log/sa/sa$dtm > sa$dtm_1.txt | ||
- | $sar -r -b -q -d -n DEV -I SUM -u -f /var/log/sa/sa$dtm > sa$dtm.txt | ||
- | $perl sar2rrd.pl -t MDY -f sa$dtm_1.txt | ||
- | $perl sar2rrd.pl -t MDY -f sa$dtm.txt | ||
- | |||
- | $perl notify.pl img/*.png | ||
- | |||
- | rm -f *.txt | ||
- | rm -f */{*.png,*.xml,*.rrd} | ||
- | </code> | ||
- | |||
- | ==== sar to rrd ==== | ||
- | This script "sar2rrd" available at | ||
- | [[http://www.trickytools.com/php/sar2rrd.php | sar2rrd ]] | ||
- | |||
- | <code bash> | ||
- | wget -O sar2rrd.pl http://www.trickytools.com/downloads/sar2rrd-2.6.pl | ||
- | </code> | ||
- | |||
- | ==== Notify Script ==== | ||
- | This script send email with all the graph | ||
- | |||
- | <code perl | notify.pl> | ||
- | #!/usr/bin/perl -w | ||
- | # | ||
- | # Modified / updated by k2patel@gmail.com | ||
- | # This script send email with attachment | ||
- | |||
- | |||
- | #use strict; | ||
- | use MIME::Lite; | ||
- | use Getopt::Std; | ||
- | use Net::SMTP; | ||
- | |||
- | my $SMTP_SERVER = '/usr/sbin/sendmail -t'; | ||
- | my $DEFAULT_SENDER = 'k2patel@localhost.localdomain'; | ||
- | my $DEFAULT_RECIPIENT = 'k2patel@hotmail.com'; | ||
- | my $def_cc = 'sjohn@live.com'; | ||
- | |||
- | my $stamp = `date -d 'now -1 days' +%b-%d-%y`; | ||
- | my $hstnm = `hostname`; | ||
- | |||
- | # process options | ||
- | getopts('hf:t:s:', \%o); | ||
- | |||
- | $o{f} ||= $DEFAULT_SENDER; | ||
- | $o{t} ||= $DEFAULT_RECIPIENT; | ||
- | $o{s} ||= $stamp.' '.$hstnm.' '.' : System utilizatoin Report'; | ||
- | |||
- | if ($o{h} or !@ARGV) { | ||
- | die "usage:\n\t$0 -h -f -t -s /var/log/log.txt\n"; | ||
- | } | ||
- | |||
- | # construct and send email | ||
- | $msg = new MIME::Lite( | ||
- | From => $o{f}, | ||
- | To => $o{t}, | ||
- | cc => ($def_cc), | ||
- | Subject => $o{s}, | ||
- | Data => "Hi", | ||
- | Type => "multipart/mixed", | ||
- | ); | ||
- | while (@ARGV) { | ||
- | $msg->attach('Type' => 'application/octet-stream', | ||
- | 'Encoding' => 'base64', | ||
- | 'Path' => shift @ARGV); | ||
- | } | ||
- | |||
- | $msg->send(); | ||
- | </code> | ||
- | ==== SE Linux ==== | ||
- | Following rules add exceptiong for selinux. | ||
- | |||
- | <code bash> | ||
- | |||
- | module sa 1.0; | ||
- | |||
- | require { | ||
- | type sysstat_t; | ||
- | type init_t; | ||
- | type file_t; | ||
- | class lnk_file read; | ||
- | class fifo_file { read write ioctl }; | ||
- | class dir { read search getattr }; | ||
- | class file { read getattr execute execute_no_trans }; | ||
- | } | ||
- | |||
- | #============= sysstat_t ============== | ||
- | allow sysstat_t file_t:dir { read search getattr }; | ||
- | allow sysstat_t file_t:file { read getattr execute execute_no_trans }; | ||
- | allow sysstat_t file_t:lnk_file read; | ||
- | allow sysstat_t init_t:fifo_file { read write ioctl }; | ||
- | |||
- | </code> | ||