User Tools

Site Tools


sar_reporting

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.

Getopt::Std
Time::Local
Date::Calc
Email::Date::Format

Following Packages from centOS / Redhat / Fedora need to be installed.

yum install -y perl-Date-Calc.x86_64 perl-Date-Calc.x86_64 rrdtool.x86_64 sysstat.x86_64 perl-MIME-Lite.noarch

Make following directory and place all script in “/root/sar” folder.

mkdir -p /root/sar/{img,rrd,xml}

Finally add it to cron.

# SAR Stats
20 0 * * * /root/sar/sa_report.sh >/dev/null 2>&1

Terms Used

    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.

sa report

This script goes to cron.

| 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}

sar to rrd

This script “sar2rrd” available at sar2rrd

wget -O sar2rrd.pl http://www.trickytools.com/downloads/sar2rrd-2.6.pl

Notify Script

This script send email with all the graph

| 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();

SE Linux

Following rules add exceptiong for selinux.

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 };
sar_reporting.txt · Last modified: 2020/08/10 02:35 (external edit)