Blame contrib/stat/stat.pl

Packit 667938
#!/usr/bin/perl -w
Packit 667938
# $Id: stat.pl,v 1.1.1.1 2002/02/26 10:16:37 oetiker Exp $
Packit 667938
####################
Packit 667938
# New updates for stat.pl
Packit 667938
####################
Packit 667938
%D_STAT=(
Packit 667938
    RQ => 0,
Packit 667938
    RR => 1,
Packit 667938
    RIQ => 2,
Packit 667938
    RNXD => 3,
Packit 667938
    RFwdQ => 4,
Packit 667938
    RFwdR => 5,
Packit 667938
    RDupQ => 6,
Packit 667938
    RDupR => 7,
Packit 667938
    RFail => 8,
Packit 667938
    RFErr => 9,
Packit 667938
    RErr => 10,
Packit 667938
    RTCP => 11,
Packit 667938
    RAXFR => 12,
Packit 667938
    RLame => 13,
Packit 667938
    ROpts => 14,
Packit 667938
    SSysQ => 15,
Packit 667938
    SAns => 16,
Packit 667938
    SFwdQ => 17,
Packit 667938
    SDupQ => 18,
Packit 667938
    SFail => 19,
Packit 667938
    SFErr => 20,
Packit 667938
    SErr => 21,
Packit 667938
    RNotNsq => 22,
Packit 667938
    SNaAns => 23,
Packit 667938
    SNXD => 24,
Packit 667938
);                     
Packit 667938
# This file is to feed mrtg with right information.
Packit 667938
# You could do this more fancy with up-time and stuff like that,
Packit 667938
# but that will be maybe in a couple of versions upward.
Packit 667938
# This works and i dont want to be like other big companys that gives out
Packit 667938
# Programs that want work but is all that fancy.
Packit 667938
#
Packit 667938
# Any way please do change this files so the right PATH to youre scripts
Packit 667938
# are there.
Packit 667938
# Requirements:
Packit 667938
# this scripts require MRTG (of course), i wont get in how to configure this,
Packit 667938
# because im not sure how to do it correctly, i manged to get it to work.
Packit 667938
# but i sugest you take a real good look how to configure MRTG.
Packit 667938
# more requirement is , perl version 5.004_05. Look at the documentation
Packit 667938
# on MRTG this one needs you to have some patches for some OS.
Packit 667938
#
Packit 667938
# If you want to use getting iformation from a remote DNS, sure you could use
Packit 667938
# my script dns.named but beware that this is NOT safe maybe you should use 
Packit 667938
# If you want to use getting iformation from a remote DNS, sure you could use
Packit 667938
# scp to get youre file, but if not, be sure to set the rights so no non-auth
Packit 667938
# could see what password is.
Packit 667938
# dns.named requires expect version 5.26.0 (i havent tested on other versions)
Packit 667938
#
Packit 667938
# im not the greatest script maker but i managed this to work, but if
Packit 667938
# you have any comments or you have some great changes please be free to send them to calle@volvo.se                                          
Packit 667938
Packit 667938
# HOSTNAME youre domain this will show up in the web-page
Packit 667938
#
Packit 667938
# OK now to this new version of this program
Packit 667938
# $LOG is where you find youre named.stats *
Packit 667938
# in Bind 8.2.1 the way to get youre named.stats is "ndc stats"
Packit 667938
# in Bind 4.9.3 kill -ABRT `cat /var/run/named.pid`
Packit 667938
# in Bind kill -ILL `cat /var/run/named.pid`
Packit 667938
# 
Packit 667938
# $RUN you have to set that to where youre script is set to run ex my $RUN = "/home/myhomeaccount/";
Packit 667938
#  
Packit 667938
# now to the real new thing that is you can have 2 graphs in one MRTG session
Packit 667938
# you have to set the $INCOMING and $OUTGOING, $INCOMING  = $D_STAT{"RQ"}; <-- this one needs to be set to look
Packit 667938
# for wich Data you want to see on the first Graph (RQ is Requested Queries)
Packit 667938
#
Packit 667938
# now to the other $OUTGOING = $D_STAT{"RFail"}; i set default but can be changed for what you want
Packit 667938
# RFail Requested Failure i done a short list of What some of them means , but if you want to have a complete list 
Packit 667938
# you could look into the DNS and Bind book from O'reilly page 166
Packit 667938
#
Packit 667938
# Short list of some of the things you could pull out
Packit 667938
#
Packit 667938
# RQ: Requested Queries.
Packit 667938
# RR: Count of responses recieved from relay.
Packit 667938
# RIQ: Count of reverse queries recieved from relay.
Packit 667938
# RNXD: Count of "no such domain" answeres.
Packit 667938
# RFwdQ: Count of queries received from relay that nedded more processing
Packit 667938
# RFwdR: Count of is the reponses recived from relay that answered the
Packit 667938
# original query and were passed back to application.
Packit 667938
# RDupR: Is the count of duplicat response from relay.
Packit 667938
# RFail: Is the count of SERVFAIL response from relay.
Packit 667938
# RFErr: is the count of FORMERR response from relay. 
Packit 667938
# RErr: is the count of errors that werent either SERVFAIL or FORMERR
Packit 667938
# RLame: Count of lame DELEGATIONS.
Packit 667938
# and so on read the book. 
Packit 667938
Packit 667938
my $HOSTNAME = "HOST\.YOURE\.DOMAIN";   
Packit 667938
my $LOG = "/home/";
Packit 667938
my $RUN = "/home/";
Packit 667938
Packit 667938
my $INCOMING  = $D_STAT{"RQ"};
Packit 667938
my $OUTGOING = $D_STAT{"RFail"};
Packit 667938
Packit 667938
Packit 667938
Packit 667938
#######################################
Packit 667938
#### Please Dont toch this part
Packit 667938
######################################
Packit 667938
my $QUE_P_MIN =();
Packit 667938
my $QUE_P_OTHER = ();
Packit 667938
my @N_STATS=();
Packit 667938
my @OLD_S=();
Packit 667938
my $UPTIME = ();
Packit 667938
Packit 667938
Packit 667938
sub HIST {
Packit 667938
    
Packit 667938
    open (STAT , "$LOG") or die "could not find or open file $LOG";
Packit 667938
    @N_STAT = <STAT>;
Packit 667938
    close (STAT);           
Packit 667938
Packit 667938
    
Packit 667938
    open (V_OLD , "$RUN/OLD");
Packit 667938
    my @OLD_S = <V_OLD>;
Packit 667938
    close (V_OLD); 
Packit 667938
    
Packit 667938
    	
Packit 667938
   
Packit 667938
    my $G_FLAG = "no";
Packit 667938
Packit 667938
    
Packit 667938
Packit 667938
    foreach $line (@N_STAT) {
Packit 667938
        
Packit 667938
        if ( $line =~ m/^([0-9]+)\s+\S+\s+\S+\sreset/ ){
Packit 667938
	    $UPTIME = $1;
Packit 667938
	}
Packit 667938
	
Packit 667938
	if ( $G_FLAG =~ /yes/) {
Packit 667938
	    
Packit 667938
	    my @NUM_QUE=split ' ',$line;
Packit 667938
            open ( LOGGER , "> $RUN/OLD");
Packit 667938
Packit 667938
            print LOGGER "$NUM_QUE[$INCOMING]\n";
Packit 667938
	    print LOGGER "$NUM_QUE[$OUTGOING]\n";
Packit 667938
Packit 667938
            close ( LOGGER );
Packit 667938
	    $QUE_P_MIN = $NUM_QUE[$INCOMING]-$OLD_S[0];
Packit 667938
	    $QUE_P_OTHER = $NUM_QUE[$OUTGOING]-$OLD_S[1];
Packit 667938
            $G_FLAG = "no";
Packit 667938
        }                                 
Packit 667938
	
Packit 667938
	
Packit 667938
Packit 667938
Packit 667938
	if ($line =~ /(Global)/) {
Packit 667938
	    $G_FLAG = "yes";
Packit 667938
	}
Packit 667938
    }
Packit 667938
    
Packit 667938
    print "$QUE_P_MIN\n$QUE_P_OTHER\n$UPTIME\n$HOSTNAME\n";
Packit 667938
}
Packit 667938
Packit 667938
&HIST();
Packit 667938
	
Packit 667938
Packit 667938
Packit 667938
Packit 667938
Packit 667938
    
Packit 667938
Packit 667938
Packit 667938
Packit 667938