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

unix.superglobalmegacorp.com

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