Annotation of 43BSDReno/usr.sbin/named/ns_stats.c, revision 1.1

1.1     ! root        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 are permitted provided
        !             6:  * that: (1) source distributions retain this entire copyright notice and
        !             7:  * comment, and (2) distributions including binaries display the following
        !             8:  * acknowledgement:  ``This product includes software developed by the
        !             9:  * University of California, Berkeley and its contributors'' in the
        !            10:  * documentation or other materials provided with the distribution and in
        !            11:  * all advertising materials mentioning features or use of this software.
        !            12:  * Neither the name of the University nor the names of its contributors may
        !            13:  * be used to endorse or promote products derived from this software without
        !            14:  * specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)ns_stats.c 4.10 (Berkeley) 6/27/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: /**************************************************************************/
        !            25: /*                simple monitoring of named behavior                     */
        !            26: /*            dumps a bunch of values into a well-know file               */
        !            27: /*                                                                        */
        !            28: /**************************************************************************/
        !            29: 
        !            30: #ifdef STATS
        !            31: 
        !            32: #include <sys/param.h>
        !            33: #include <sys/time.h>
        !            34: #include <netinet/in.h>
        !            35: #include <stdio.h>
        !            36: #include <syslog.h>
        !            37: #include <arpa/nameser.h>
        !            38: #include "ns.h"
        !            39: #include "pathnames.h"
        !            40: 
        !            41: #ifdef STATSFILE
        !            42: char *statsfile = STATSFILE;
        !            43: #else
        !            44: char *statsfile = _PATH_STATS;
        !            45: #endif /* STATSFILE */
        !            46: 
        !            47: extern time_t  boottime, resettime;
        !            48: extern int     needStatsDump;
        !            49: 
        !            50: /*
        !            51:  * General statistics gathered
        !            52:  */
        !            53: /* The position in this table must agree with the defines in ns.h */
        !            54: struct stats stats[S_NSTATS] = {
        !            55:        { 0, "input packets" },
        !            56:        { 0, "output packets" },
        !            57:        { 0, "queries" },
        !            58:        { 0, "iqueries" },
        !            59:        { 0, "duplicate queries" },
        !            60:        { 0, "responses" },
        !            61:        { 0, "duplicate responses" },
        !            62:        { 0, "OK answers" },
        !            63:        { 0, "FAIL answers" },
        !            64:        { 0, "FORMERR answers" },
        !            65:        { 0, "system queries" },
        !            66:        { 0, "prime cache calls" },
        !            67:        { 0, "check_ns calls" },
        !            68:        { 0, "bad responses dropped" },
        !            69:        { 0, "martian responses" },
        !            70: };
        !            71: 
        !            72: /*
        !            73:  *  Statistics for queries (by type)
        !            74:  */
        !            75: unsigned long typestats[T_ANY+1];
        !            76: char *typenames[T_ANY+1] = {
        !            77:        /* 5 types per line */
        !            78:        "Unknown", "A", "NS", "invalid(MD)", "invalid(MF)",
        !            79:        "CNAME", "SOA", "MB", "MG", "MR",
        !            80:        "NULL", "WKS", "PTR", "HINFO", "MINFO",
        !            81:        "MX", "TXT", 0, 0, 0,
        !            82:        /* 20 per line */
        !            83:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            84:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            85:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            86:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            87:        /* 100 */
        !            88:        "UINFO", "UID", "GID", "UNSPEC", 0, 0, 0, 0, 0, 0,
        !            89:        /* 110 */
        !            90:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            91:        /* 120 */
        !            92:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            93:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            94:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            95:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !            96:        /* 200 */
        !            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:        /* 240 */
        !           100:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        !           101:        /* 250 */
        !           102:        0, 0, "AXFR", "MAILB", "MAILA", "ANY" 
        !           103: };
        !           104: 
        !           105: ns_stats()
        !           106: {
        !           107:        time_t timenow;
        !           108:        register FILE *f;
        !           109:        register int i;
        !           110: 
        !           111:        if ((f = fopen(statsfile,"a")) == 0)
        !           112:        {
        !           113: #ifdef DEBUG
        !           114:                if (debug)
        !           115:                        fprintf(ddt,"can't open stat file, \"%s\"\n",statsfile);
        !           116: #endif
        !           117:                syslog(LOG_ERR, "cannot open stat file, \"%s\"\n",statsfile);
        !           118:                return;
        !           119:        }
        !           120: 
        !           121:        time(&timenow);
        !           122:        fprintf(f, "###  %s", ctime(&timenow));
        !           123:        fprintf(f, "%d\ttime since boot (secs)\n", timenow - boottime);
        !           124:        fprintf(f, "%d\ttime since reset (secs)\n", timenow - resettime);
        !           125: 
        !           126:        /* general statistics */
        !           127:        for (i = 0; i < S_NSTATS; i++)
        !           128:                fprintf(f,"%lu\t%s\n", stats[i].cnt, stats[i].description);
        !           129: 
        !           130:        /* query type statistics */
        !           131:        fprintf(f, "%d\tUnknown query types\n", typestats[0]);
        !           132:        for(i=1; i < T_ANY+1; i++)
        !           133:                if (typestats[i])
        !           134:                        if (typenames[i])
        !           135:                                fprintf(f, "%lu\t%s queries\n", typestats[i],
        !           136:                                        typenames[i]);
        !           137:                        else
        !           138:                                fprintf(f, "%lu\ttype %d queries\n",
        !           139:                                        typestats[i], i);
        !           140:        (void) fclose(f);
        !           141: }
        !           142: #endif STATS

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.