File: stat.pl

package info (click to toggle)
mrtg 2.9.17-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,140 kB
  • ctags: 1,517
  • sloc: perl: 22,688; ansic: 3,536; sh: 1,309; makefile: 319; php: 227; awk: 213; csh: 49; exp: 16
file content (169 lines) | stat: -rwxr-xr-x 4,961 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/perl -w
# $Id: stat.pl,v 1.6 1999/07/27 08:27:13 v072863 Exp $
####################
# New updates for stat.pl
####################
%D_STAT=(
    RQ => 0,
    RR => 1,
    RIQ => 2,
    RNXD => 3,
    RFwdQ => 4,
    RFwdR => 5,
    RDupQ => 6,
    RDupR => 7,
    RFail => 8,
    RFErr => 9,
    RErr => 10,
    RTCP => 11,
    RAXFR => 12,
    RLame => 13,
    ROpts => 14,
    SSysQ => 15,
    SAns => 16,
    SFwdQ => 17,
    SDupQ => 18,
    SFail => 19,
    SFErr => 20,
    SErr => 21,
    RNotNsq => 22,
    SNaAns => 23,
    SNXD => 24,
);                     
# This file is to feed mrtg with right information.
# You could do this more fancy with up-time and stuff like that,
# but that will be maybe in a couple of versions upward.
# This works and i dont want to be like other big companys that gives out
# Programs that want work but is all that fancy.
#
# Any way please do change this files so the right PATH to youre scripts
# are there.
# Requirements:
# this scripts require MRTG (of course), i wont get in how to configure this,
# because im not sure how to do it correctly, i manged to get it to work.
# but i sugest you take a real good look how to configure MRTG.
# more requirement is , perl version 5.004_05. Look at the documentation
# on MRTG this one needs you to have some patches for some OS.
#
# If you want to use getting iformation from a remote DNS, sure you could use
# my script dns.named but beware that this is NOT safe maybe you should use 
# If you want to use getting iformation from a remote DNS, sure you could use
# scp to get youre file, but if not, be sure to set the rights so no non-auth
# could see what password is.
# dns.named requires expect version 5.26.0 (i havent tested on other versions)
#
# im not the greatest script maker but i managed this to work, but if
# you have any comments or you have some great changes please be free to send them to calle@volvo.se                                          

# HOSTNAME youre domain this will show up in the web-page
#
# OK now to this new version of this program
# $LOG is where you find youre named.stats *
# in Bind 8.2.1 the way to get youre named.stats is "ndc stats"
# in Bind 4.9.3 kill -ABRT `cat /var/run/named.pid`
# in Bind kill -ILL `cat /var/run/named.pid`
# 
# $RUN you have to set that to where youre script is set to run ex my $RUN = "/home/myhomeaccount/";
#  
# now to the real new thing that is you can have 2 graphs in one MRTG session
# you have to set the $INCOMING and $OUTGOING, $INCOMING  = $D_STAT{"RQ"}; <-- this one needs to be set to look
# for wich Data you want to see on the first Graph (RQ is Requested Queries)
#
# now to the other $OUTGOING = $D_STAT{"RFail"}; i set default but can be changed for what you want
# RFail Requested Failure i done a short list of What some of them means , but if you want to have a complete list 
# you could look into the DNS and Bind book from O'reilly page 166
#
# Short list of some of the things you could pull out
#
# RQ: Requested Queries.
# RR: Count of responses recieved from relay.
# RIQ: Count of reverse queries recieved from relay.
# RNXD: Count of "no such domain" answeres.
# RFwdQ: Count of queries received from relay that nedded more processing
# RFwdR: Count of is the reponses recived from relay that answered the
# original query and were passed back to application.
# RDupR: Is the count of duplicat response from relay.
# RFail: Is the count of SERVFAIL response from relay.
# RFErr: is the count of FORMERR response from relay. 
# RErr: is the count of errors that werent either SERVFAIL or FORMERR
# RLame: Count of lame DELEGATIONS.
# and so on read the book. 

my $HOSTNAME = "HOST\.YOURE\.DOMAIN";   
my $LOG = "/home/";
my $RUN = "/home/";

my $INCOMING  = $D_STAT{"RQ"};
my $OUTGOING = $D_STAT{"RFail"};



#######################################
#### Please Dont toch this part
######################################
my $QUE_P_MIN =();
my $QUE_P_OTHER = ();
my @N_STATS=();
my @OLD_S=();
my $UPTIME = ();


sub HIST {
    
    open (STAT , "$LOG") or die "could not find or open file $LOG";
    @N_STAT = <STAT>;
    close (STAT);           

    
    open (V_OLD , "$RUN/OLD");
    my @OLD_S = <V_OLD>;
    close (V_OLD); 
    
    	
   
    my $G_FLAG = "no";

    

    foreach $line (@N_STAT) {
        
        if ( $line =~ m/^([0-9]+)\s+\S+\s+\S+\sreset/ ){
	    $UPTIME = $1;
	}
	
	if ( $G_FLAG =~ /yes/) {
	    
	    my @NUM_QUE=split ' ',$line;
            open ( LOGGER , "> $RUN/OLD");

            print LOGGER "$NUM_QUE[$INCOMING]\n";
	    print LOGGER "$NUM_QUE[$OUTGOING]\n";

            close ( LOGGER );
	    $QUE_P_MIN = $NUM_QUE[$INCOMING]-$OLD_S[0];
	    $QUE_P_OTHER = $NUM_QUE[$OUTGOING]-$OLD_S[1];
            $G_FLAG = "no";
        }                                 
	
	


	if ($line =~ /(Global)/) {
	    $G_FLAG = "yes";
	}
    }
    
    print "$QUE_P_MIN\n$QUE_P_OTHER\n$UPTIME\n$HOSTNAME\n";
}

&HIST();