Removed all patch kit headers, sccsid and rcsid strings, put $Id$ in, some
[unix-history] / usr.sbin / named / ns_stats.c
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1986 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char sccsid[] = "@(#)ns_stats.c 4.10 (Berkeley) 6/27/90";
36#endif /* not lint */
37
38/**************************************************************************/
39/* simple monitoring of named behavior */
40/* dumps a bunch of values into a well-know file */
41/* */
42/**************************************************************************/
43
44#ifdef STATS
45
46#include <sys/param.h>
47#include <sys/time.h>
48#include <netinet/in.h>
49#include <stdio.h>
50#include <syslog.h>
51#include <arpa/nameser.h>
52#include "ns.h"
53#include "pathnames.h"
54
55#ifdef STATSFILE
56char *statsfile = STATSFILE;
57#else
58char *statsfile = _PATH_STATS;
59#endif /* STATSFILE */
60
61extern time_t boottime, resettime;
62extern int needStatsDump;
63
64/*
65 * General statistics gathered
66 */
67/* The position in this table must agree with the defines in ns.h */
68struct stats stats[S_NSTATS] = {
69 { 0, "input packets" },
70 { 0, "output packets" },
71 { 0, "queries" },
72 { 0, "iqueries" },
73 { 0, "duplicate queries" },
74 { 0, "responses" },
75 { 0, "duplicate responses" },
76 { 0, "OK answers" },
77 { 0, "FAIL answers" },
78 { 0, "FORMERR answers" },
79 { 0, "system queries" },
80 { 0, "prime cache calls" },
81 { 0, "check_ns calls" },
82 { 0, "bad responses dropped" },
83 { 0, "martian responses" },
84};
85
86/*
87 * Statistics for queries (by type)
88 */
89unsigned long typestats[T_ANY+1];
90char *typenames[T_ANY+1] = {
91 /* 5 types per line */
92 "Unknown", "A", "NS", "invalid(MD)", "invalid(MF)",
93 "CNAME", "SOA", "MB", "MG", "MR",
94 "NULL", "WKS", "PTR", "HINFO", "MINFO",
95 "MX", "TXT", 0, 0, 0,
96 /* 20 per line */
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 /* 100 */
102 "UINFO", "UID", "GID", "UNSPEC", 0, 0, 0, 0, 0, 0,
103 /* 110 */
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 /* 120 */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 /* 200 */
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 /* 240 */
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 /* 250 */
116 0, 0, "AXFR", "MAILB", "MAILA", "ANY"
117};
118
119ns_stats()
120{
121 time_t timenow;
122 register FILE *f;
123 register int i;
124
125 if ((f = fopen(statsfile,"a")) == 0)
126 {
127#ifdef DEBUG
128 if (debug)
129 fprintf(ddt,"can't open stat file, \"%s\"\n",statsfile);
130#endif
131 syslog(LOG_ERR, "cannot open stat file, \"%s\"\n",statsfile);
132 return;
133 }
134
135 time(&timenow);
136 fprintf(f, "### %s", ctime(&timenow));
137 fprintf(f, "%d\ttime since boot (secs)\n", timenow - boottime);
138 fprintf(f, "%d\ttime since reset (secs)\n", timenow - resettime);
139
140 /* general statistics */
141 for (i = 0; i < S_NSTATS; i++)
142 fprintf(f,"%lu\t%s\n", stats[i].cnt, stats[i].description);
143
144 /* query type statistics */
145 fprintf(f, "%d\tUnknown query types\n", typestats[0]);
146 for(i=1; i < T_ANY+1; i++)
147 if (typestats[i])
148 if (typenames[i])
149 fprintf(f, "%lu\t%s queries\n", typestats[i],
150 typenames[i]);
151 else
152 fprintf(f, "%lu\ttype %d queries\n",
153 typestats[i], i);
154 (void) fclose(f);
155}
156#endif STATS