#!/usr/bin/perl ######################################################## # Script: ecstat.pl # Author: Vishal Soni # Date: 01/13/2002 # Description: Collect Cache' Statistics # Collects following metrics # 1. Global References # 2. Physical Reads # 3. Physical Writes # 4. Sets and Kill # 5. Buffer Hit Ratio # 6. Lines of code executed # 7. Global Seize number # 8. Routine A Seize # 9. Journal A Seize # OS: All # Cache': 4.0 and up # # Modification History: # 1. Created by Vishal Soni 01/13/2003 # 2. Added logic so that only one # instnce of this script runs 03/04/2003 # # Copyright Epic Systems Corporation 2002-2003 ######################################################## use strict; use Getopt::Std; use FileHandle; use Epic::PerfTools::CacheStat qw($LogDir); use Epic::PerfTools::Logger; use Epic::PerfTools::Util qw(&getDate &getTime &lockFile &unlockFile); use Epic::PerfTools::Error; my %opts; getopts('hc:v:m:',\%opts); if (%opts->{'h'}) { usage(); exit 0; } if ( $opts{'c'} =~ /^$/ ) { usage(); exit 0; } #initialize cachestat module my $cstat = new Epic::PerfTools::CacheStat($opts{'c'},$opts{'v'},$opts{'m'}); #initalize logger my $lgr = new Epic::PerfTools::Logger($LogDir); if (!defined $lgr) { print $Epic::PerfTools::Logger::ERROR."\n"; exit 1; } #if cachestat initialization failed log the error if (!defined $cstat) { $lgr->log($Epic::PerfTools::CacheStat::ERROR); exit 1; } #lock this script my $myfh= new FileHandle ">>$0"; if(!defined $myfh) { my $err=new Epic::PerfTools::Error(); $err->set("ecstat.pl","Cannot open: $0"); $lgr->log($err->toString()); } if (! lockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); exit 1; } #read config file if ( !$cstat->readConf() ) { $lgr->log($Epic::PerfTools::CacheStat::ERROR); #unlock the file if (!defined unlockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); } exit 1; } #collect cachestat data my $file=$cstat->collect(); if (!defined $file) { $lgr->log($Epic::PerfTools::CacheStat::ERROR); #unlock the file if (!defined unlockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); } exit 1; } #extract cachestat data to standard foramt my $extfile=$cstat->extract($file); if (!defined $extfile) { $lgr->log($Epic::PerfTools::CacheStat::ERROR); #unlock the file if (!defined unlockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); } exit 1; } #convert data to Epic Performance XML my $xmlfile=$cstat->toXML($extfile); if (!defined $xmlfile ) { $lgr->log($Epic::PerfTools::CacheStat::ERROR); #unlock the file if (!defined unlockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); } exit 1; } unlink $extfile; #Mail the data my $rv=$cstat->mail($xmlfile,1); if (! $rv ) { $lgr->log($Epic::PerfTools::CacheStat::ERROR); #unlock the file if (!defined unlockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); } exit 1; } unlink $xmlfile; #delete old data $cstat->deleteOld(); my $ts=getDate()." ".getTime(); chomp $ts; #Log the successful transmission of message $lgr->log("-->$0|$ts|Mail Sent"); #unlock the file if (!defined unlockFile($myfh)) { $lgr->log($Epic::PerfTools::Util::ERROR); } undef $myfh; undef $file; undef $cstat; undef $lgr; undef $ts; sub usage { print << "EOF"; Usage: perl ecstat.pl -h perl ecstat.pl -c [base conf] -v [cachestat conf] -m [mail conf] -h print help -c base configuration file -v cachestat configuration file (optional) if not specified reads default cachestat.conf -m mail configuration file (optional) if not specified reads default mail.conf Collects following statistics 1. Global References 2. Physical Reads 3. Physical Writes 4. Sets and Kill 5. Buffer Hit Ratio 6. Lines of code executed 7. Global Seize number 8. Routine A Seize 9. Journal A Seize Supported Platforms: All Cache' Versions: 4.0 and up (C) Epic Systems Corporation 2002-2003 EOF } #Performance Data Collection Tools #Base Configuration file #Copyright Epic Systems Corporation 2002-2003 ############################################################ # CHANGE FOLLOWING FOR STANDARD CONFIG # ############################################################ #The Internet domain of the data sender. #This must be a valid Interner Domain address and a #registered Domain Domain=elliot-hs.org #The name of the system for which data is collected HostName=epicn2 #Base directory where the performance tools are installed. #This should be a valid directory BaseDir=DSA0:[EPIC.BIN4.PERFTOOLS] ############################################################ # END OF CHANGES FOR STANDARD CONFIG # ############################################################ #Directory where the statistics are to be collected. #If absolute path not specified BaseDir is the base #directory #This must be a valid directory StatDir=[.stat] #Directory where the Log file is generated. #This must be a valid directory LogDir=[.log] #Path to Temporary directory. #This must be a valid directory TmpDir=[.tmp] #Path where the configuration files are present. #This must be a valid directory ConfDir=[.conf.test]