# 2.11BSD#431 - /usr/src/usr.sbin/named/named/ns_stats.c

##### Functions

    ns_stats          X

##### Variables

    stats             X
    statsfile         X
    typenames         X
    typestats         X

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

#### Defined functions

ns_stats defined in line 97; used 1 times

- in /usr/src/usr.sbin/named/named/ns_main.c line 615

#### Defined variables

sccsid defined in line 14; never used
stats defined in line 46; used 28 times

- in line 120(2)
- in /usr/src/usr.sbin/named/named/ns_forw.c line 82, 140, 434
- in /usr/src/usr.sbin/named/named/ns_main.c line 672
- in /usr/src/usr.sbin/named/named/ns_req.c line 105, 367, 530-536(3), 567
- in /usr/src/usr.sbin/named/named/ns_resp.c line 70, 79, 110, 154, 644, 662, 668, 681, 699, 1055, 1093, 1126, 1212, 1286
- in /usr/src/usr.sbin/named/named/ns_stats.c line 120(2)

statsfile defined in line 36; used 3 times

- in line 103-109(3)

typenames defined in line 68; used 1 times

- in line 127

typestats defined in line 67; used 8 times

- in line 123-126(3)
- in /usr/src/usr.sbin/named/named/ns_req.c line 154-156(2)
- in /usr/src/usr.sbin/named/named/ns_stats.c line 123-126(3)

Last modified: 1988-09-09 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1303 |