Home | History | Annotate | Line # | Download | only in statistics
      1       1.1  christos #!/bin/sh
      2   1.1.1.8  christos 
      3       1.1  christos # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      4       1.1  christos #
      5   1.1.1.8  christos # SPDX-License-Identifier: MPL-2.0
      6   1.1.1.8  christos #
      7       1.1  christos # This Source Code Form is subject to the terms of the Mozilla Public
      8   1.1.1.8  christos # License, v. 2.0.  If a copy of the MPL was not distributed with this
      9   1.1.1.6  christos # file, you can obtain one at https://mozilla.org/MPL/2.0/.
     10       1.1  christos #
     11       1.1  christos # See the COPYRIGHT file distributed with this work for additional
     12       1.1  christos # information regarding copyright ownership.
     13       1.1  christos 
     14   1.1.1.9  christos set -e
     15       1.1  christos 
     16   1.1.1.9  christos . ../conf.sh
     17   1.1.1.9  christos 
     18   1.1.1.9  christos DIGCMD="$DIG +tcp -p ${PORT}"
     19   1.1.1.9  christos RNDCCMD="$RNDC -p ${CONTROLPORT} -c ../_common/rndc.conf"
     20       1.1  christos 
     21       1.1  christos status=0
     22       1.1  christos 
     23       1.1  christos ret=0
     24       1.1  christos n=1
     25   1.1.1.7  christos stats=0
     26   1.1.1.9  christos nsock0nstat=0
     27   1.1.1.9  christos nsock1nstat=0
     28   1.1.1.7  christos rndc_stats() {
     29   1.1.1.9  christos   _ns=$1
     30   1.1.1.9  christos   _ip=$2
     31   1.1.1.7  christos 
     32   1.1.1.9  christos   $RNDCCMD -s $_ip stats >/dev/null 2>&1 || return 1
     33   1.1.1.9  christos   [ -f "${_ns}/named.stats" ] || return 1
     34   1.1.1.7  christos 
     35   1.1.1.9  christos   last_stats=named.stats.$_ns-$stats-$n
     36   1.1.1.9  christos   mv ${_ns}/named.stats $last_stats
     37   1.1.1.9  christos   stats=$((stats + 1))
     38   1.1.1.7  christos }
     39       1.1  christos 
     40       1.1  christos echo_i "fetching a.example from ns2's initial configuration ($n)"
     41   1.1.1.9  christos $DIGCMD +noauth a.example. @10.53.0.2 any >dig.out.ns2.1 || ret=1
     42       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     43   1.1.1.9  christos status=$((status + ret))
     44   1.1.1.9  christos n=$((n + 1))
     45       1.1  christos 
     46       1.1  christos ret=0
     47       1.1  christos echo_i "dumping initial stats for ns2 ($n)"
     48   1.1.1.7  christos rndc_stats ns2 10.53.0.2 || ret=1
     49       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     50   1.1.1.9  christos status=$((status + ret))
     51   1.1.1.9  christos n=$((n + 1))
     52       1.1  christos 
     53       1.1  christos ret=0
     54       1.1  christos echo_i "verifying adb records in named.stats ($n)"
     55   1.1.1.9  christos grep "ADB stats" $last_stats >/dev/null || ret=1
     56       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     57   1.1.1.9  christos status=$((status + ret))
     58   1.1.1.9  christos n=$((n + 1))
     59       1.1  christos 
     60       1.1  christos echo_i "checking for 1 entry in adb hash table in named.stats ($n)"
     61   1.1.1.9  christos grep "1 Addresses in hash table" $last_stats >/dev/null || ret=1
     62       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     63   1.1.1.9  christos status=$((status + ret))
     64   1.1.1.9  christos n=$((n + 1))
     65       1.1  christos 
     66       1.1  christos ret=0
     67       1.1  christos echo_i "verifying cache statistics in named.stats ($n)"
     68   1.1.1.9  christos grep "Cache Statistics" $last_stats >/dev/null || ret=1
     69       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     70   1.1.1.9  christos status=$((status + ret))
     71   1.1.1.9  christos n=$((n + 1))
     72       1.1  christos 
     73       1.1  christos ret=0
     74       1.1  christos echo_i "checking for 2 entries in adb hash table in named.stats ($n)"
     75   1.1.1.9  christos $DIGCMD a.example.info. @10.53.0.2 any >/dev/null 2>&1
     76   1.1.1.7  christos rndc_stats ns2 10.53.0.2 || ret=1
     77   1.1.1.9  christos grep "2 Addresses in hash table" $last_stats >/dev/null || ret=1
     78       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     79   1.1.1.9  christos status=$((status + ret))
     80   1.1.1.9  christos n=$((n + 1))
     81       1.1  christos 
     82       1.1  christos ret=0
     83       1.1  christos echo_i "dumping initial stats for ns3 ($n)"
     84   1.1.1.7  christos rndc_stats ns3 10.53.0.3 || ret=1
     85   1.1.1.9  christos nsock0nstat=$(grep "UDP/IPv4 sockets active" $last_stats | awk '{print $1}')
     86   1.1.1.9  christos [ 0 -ne ${nsock0nstat} ] || ret=1
     87       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
     88   1.1.1.9  christos status=$((status + ret))
     89   1.1.1.9  christos n=$((n + 1))
     90       1.1  christos 
     91       1.1  christos echo_i "sending queries to ns3"
     92   1.1.1.9  christos $DIGCMD +tries=2 +time=1 +recurse @10.53.0.3 foo.info. any >/dev/null 2>&1 || true
     93       1.1  christos 
     94       1.1  christos ret=0
     95       1.1  christos echo_i "dumping updated stats for ns3 ($n)"
     96   1.1.1.8  christos getstats() {
     97   1.1.1.9  christos   rndc_stats ns3 10.53.0.3 || return 1
     98   1.1.1.9  christos   grep "2 recursing clients" $last_stats >/dev/null || return 1
     99   1.1.1.8  christos }
    100   1.1.1.8  christos retry_quiet 5 getstats || ret=1
    101       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    102   1.1.1.9  christos status=$((status + ret))
    103   1.1.1.9  christos n=$((n + 1))
    104       1.1  christos 
    105       1.1  christos ret=0
    106       1.1  christos echo_i "verifying recursing clients output in named.stats ($n)"
    107   1.1.1.9  christos grep "2 recursing clients" $last_stats >/dev/null || ret=1
    108       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    109   1.1.1.9  christos status=$((status + ret))
    110   1.1.1.9  christos n=$((n + 1))
    111       1.1  christos 
    112       1.1  christos ret=0
    113       1.1  christos echo_i "verifying active fetches output in named.stats ($n)"
    114   1.1.1.9  christos grep "1 active fetches" $last_stats >/dev/null || ret=1
    115       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    116   1.1.1.9  christos status=$((status + ret))
    117   1.1.1.9  christos n=$((n + 1))
    118       1.1  christos 
    119   1.1.1.9  christos ret=0
    120   1.1.1.9  christos echo_i "verifying active sockets output in named.stats ($n)"
    121   1.1.1.9  christos nsock1nstat=$(grep "UDP/IPv4 sockets active" $last_stats | awk '{print $1}')
    122   1.1.1.9  christos [ $((nsock1nstat - nsock0nstat)) -eq 1 ] || ret=1
    123   1.1.1.9  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    124   1.1.1.9  christos status=$((status + ret))
    125   1.1.1.9  christos n=$((n + 1))
    126       1.1  christos 
    127       1.1  christos # there should be 1 UDP and no TCP queries.  As the TCP counter is zero
    128       1.1  christos # no status line is emitted.
    129       1.1  christos ret=0
    130       1.1  christos echo_i "verifying queries in progress in named.stats ($n)"
    131   1.1.1.9  christos grep "1 UDP queries in progress" $last_stats >/dev/null || ret=1
    132   1.1.1.9  christos grep "TCP queries in progress" $last_stats >/dev/null && ret=1
    133       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    134   1.1.1.9  christos status=$((status + ret))
    135   1.1.1.9  christos n=$((n + 1))
    136       1.1  christos 
    137       1.1  christos ret=0
    138       1.1  christos echo_i "verifying bucket size output ($n)"
    139   1.1.1.9  christos grep "bucket size" $last_stats >/dev/null || ret=1
    140       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    141   1.1.1.9  christos status=$((status + ret))
    142   1.1.1.9  christos n=$((n + 1))
    143       1.1  christos 
    144       1.1  christos ret=0
    145   1.1.1.8  christos echo_i "checking priming queries are counted ($n)"
    146   1.1.1.9  christos grep "priming queries" $last_stats >/dev/null || ret=1
    147   1.1.1.8  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    148   1.1.1.9  christos status=$((status + ret))
    149   1.1.1.9  christos n=$((n + 1))
    150   1.1.1.8  christos 
    151   1.1.1.8  christos ret=0
    152       1.1  christos echo_i "checking that zones with slash are properly shown in XML output ($n)"
    153  1.1.1.11  christos if $FEATURETEST --have-libxml2 && [ -x "${CURL}" ] && [ -x "${XMLLINT}" ]; then
    154   1.1.1.9  christos   ${CURL} http://10.53.0.1:${EXTRAPORT1}/xml/v3/zones >curl.out.${n} 2>/dev/null || ret=1
    155  1.1.1.11  christos   test -n "$("$XMLLINT" --xpath '/statistics/views/view[@name="_default"]/zones/zone[@name="32/1.0.0.127-in-addr.example"]' curl.out.${n})" || ret=1
    156       1.1  christos else
    157  1.1.1.11  christos   echo_i "skipping test as libxml2 and/or curl and/or xmllint was not found"
    158       1.1  christos fi
    159       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    160   1.1.1.9  christos status=$((status + ret))
    161   1.1.1.9  christos n=$((n + 1))
    162       1.1  christos 
    163       1.1  christos ret=0
    164       1.1  christos echo_i "checking that zones return their type ($n)"
    165  1.1.1.11  christos if $FEATURETEST --have-libxml2 && [ -x "${CURL}" ] && [ -x "${XMLLINT}" ]; then
    166   1.1.1.9  christos   ${CURL} http://10.53.0.1:${EXTRAPORT1}/xml/v3/zones >curl.out.${n} 2>/dev/null || ret=1
    167  1.1.1.11  christos   test -n "$("$XMLLINT" --xpath '/statistics/views/view[@name="_default"]/zones/zone[@name="32/1.0.0.127-in-addr.example"]/type[text()="primary"]' curl.out.${n})" || ret=1
    168       1.1  christos else
    169  1.1.1.11  christos   echo_i "skipping test as libxml2 and/or curl and/or xmllint was not found"
    170       1.1  christos fi
    171       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    172   1.1.1.9  christos status=$((status + ret))
    173   1.1.1.9  christos n=$((n + 1))
    174       1.1  christos 
    175       1.1  christos ret=0
    176   1.1.1.4  christos echo_i "checking bind9.xsl vs xml ($n)"
    177   1.1.1.9  christos if $FEATURETEST --have-libxml2 && "${CURL}" --http1.1 http://10.53.0.3:${EXTRAPORT1} >/dev/null 2>&1 && [ -x "${XSLTPROC}" ]; then
    178   1.1.1.9  christos   $DIGCMD +notcp +recurse @10.53.0.3 soa . >dig.out.test$n.1 2>&1
    179   1.1.1.9  christos   $DIGCMD +notcp +recurse @10.53.0.3 soa example >dig.out.test$n.2 2>&1
    180   1.1.1.9  christos   # check multiple requests over the same socket
    181   1.1.1.9  christos   time1=$($PERL -e 'print time(), "\n";')
    182   1.1.1.9  christos   ${CURL} --http1.1 -o curl.out.${n}.xml http://10.53.0.3:${EXTRAPORT1}/xml/v3 \
    183   1.1.1.9  christos     -o curl.out.${n}.xsl http://10.53.0.3:${EXTRAPORT1}/bind9.xsl 2>/dev/null || ret=1
    184   1.1.1.9  christos   time2=$($PERL -e 'print time(), "\n";')
    185   1.1.1.9  christos   test $((time2 - time1)) -lt 5 || ret=1
    186   1.1.1.9  christos   diff ${TOP_SRCDIR}/bin/named/bind9.xsl curl.out.${n}.xsl || ret=1
    187   1.1.1.9  christos   ${XSLTPROC} curl.out.${n}.xsl - <curl.out.${n}.xml >xsltproc.out.${n} 2>/dev/null || ret=1
    188   1.1.1.9  christos   cp curl.out.${n}.xml stats.xml.out || ret=1
    189   1.1.1.9  christos 
    190   1.1.1.9  christos   #
    191   1.1.1.9  christos   # grep for expected sections.
    192   1.1.1.9  christos   #
    193   1.1.1.9  christos   grep "<h1>ISC Bind 9 Configuration and Statistics</h1>" xsltproc.out.${n} >/dev/null || ret=1
    194   1.1.1.9  christos   grep "<h2>Server Status</h2>" xsltproc.out.${n} >/dev/null || ret=1
    195   1.1.1.9  christos   grep "<h2>Incoming Requests by DNS Opcode</h2>" xsltproc.out.${n} >/dev/null || ret=1
    196   1.1.1.9  christos   grep "<h3>Incoming Queries by Query Type</h3>" xsltproc.out.${n} >/dev/null || ret=1
    197   1.1.1.9  christos   grep "<h2>Outgoing Queries per view</h2>" xsltproc.out.${n} >/dev/null || ret=1
    198   1.1.1.9  christos   grep "<h3>View " xsltproc.out.${n} >/dev/null || ret=1
    199   1.1.1.9  christos   grep "<h2>Server Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1
    200   1.1.1.9  christos   grep "<h2>Zone Maintenance Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1
    201   1.1.1.9  christos   # grep "<h2>Resolver Statistics (Common)</h2>" xsltproc.out.${n} >/dev/null || ret=1
    202   1.1.1.9  christos   grep "<h3>Resolver Statistics for View " xsltproc.out.${n} >/dev/null || ret=1
    203   1.1.1.9  christos   grep "<h3>ADB Statistics for View " xsltproc.out.${n} >/dev/null || ret=1
    204   1.1.1.9  christos   grep "<h3>Cache Statistics for View " xsltproc.out.${n} >/dev/null || ret=1
    205   1.1.1.9  christos   # grep "<h3>Cache DB RRsets for View " xsltproc.out.${n} >/dev/null || ret=1
    206   1.1.1.9  christos   grep "<h2>Traffic Size Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1
    207   1.1.1.9  christos   grep "<h4>UDP Requests Received</h4>" xsltproc.out.${n} >/dev/null || ret=1
    208   1.1.1.9  christos   grep "<h4>UDP Responses Sent</h4>" xsltproc.out.${n} >/dev/null || ret=1
    209   1.1.1.9  christos   grep "<h4>TCP Requests Received</h4>" xsltproc.out.${n} >/dev/null || ret=1
    210   1.1.1.9  christos   grep "<h4>TCP Responses Sent</h4>" xsltproc.out.${n} >/dev/null || ret=1
    211   1.1.1.9  christos   grep "<h2>Socket I/O Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1
    212   1.1.1.9  christos   grep "<h3>Zones for View " xsltproc.out.${n} >/dev/null || ret=1
    213   1.1.1.9  christos   grep "<h2>Received QTYPES per view/zone</h2>" xsltproc.out.${n} >/dev/null || ret=1
    214   1.1.1.9  christos   grep "<h3>View _default" xsltproc.out.${n} >/dev/null || ret=1
    215   1.1.1.9  christos   grep "<h4>Zone example" xsltproc.out.${n} >/dev/null || ret=1
    216   1.1.1.9  christos   grep "<h2>Response Codes per view/zone</h2>" xsltproc.out.${n} >/dev/null || ret=1
    217   1.1.1.9  christos   grep "<h3>View _default" xsltproc.out.${n} >/dev/null || ret=1
    218   1.1.1.9  christos   grep "<h4>Zone example" xsltproc.out.${n} >/dev/null || ret=1
    219   1.1.1.9  christos   # grep "<h2>Glue cache statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1
    220   1.1.1.9  christos   grep "<h3>View _default" xsltproc.out.${n} >/dev/null || ret=1
    221   1.1.1.9  christos   grep "<h4>Zone example" xsltproc.out.${n} >/dev/null || ret=1
    222   1.1.1.9  christos   grep "<h2>Memory Usage Summary</h2>" xsltproc.out.${n} >/dev/null || ret=1
    223   1.1.1.9  christos   grep "<h2>Memory Contexts</h2>" xsltproc.out.${n} >/dev/null || ret=1
    224   1.1.1.4  christos else
    225   1.1.1.9  christos   echo_i "skipping test as libxml2 and/or curl with HTTP/1.1 support and/or xsltproc was not found"
    226   1.1.1.4  christos fi
    227   1.1.1.4  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    228   1.1.1.9  christos status=$((status + ret))
    229   1.1.1.9  christos n=$((n + 1))
    230   1.1.1.4  christos 
    231   1.1.1.4  christos ret=0
    232   1.1.1.6  christos echo_i "checking bind9.xml socket statistics ($n)"
    233  1.1.1.11  christos if $FEATURETEST --have-libxml2 && [ -e stats.xml.out ] && [ -x "${XSLTPROC}" ] && [ -x "${XMLLINT}" ]; then
    234   1.1.1.9  christos   # Socket statistics (expect no errors)
    235  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP4AcceptFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    236  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP4BindFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    237  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP4ConnFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    238  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP4OpenFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    239  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP4RecvErr" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    240  1.1.1.11  christos   # [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP4SendErr" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    241  1.1.1.11  christos 
    242  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP6AcceptFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    243  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP6BindFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    244  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP6ConnFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    245  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP6OpenFail" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    246  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP6RecvErr" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    247  1.1.1.11  christos   [ "$("$XMLLINT" --xpath 'count(/statistics/server/counters[@type="sockstat"]/counter[@name="TCP6SendErr" and text()="0"])' stats.xml.out)" -eq 1 ] || ret=1
    248   1.1.1.6  christos else
    249  1.1.1.11  christos   echo_i "skipping test as libxml2 and/or stats.xml.out file and/or xsltproc and/or xmllint was not found"
    250   1.1.1.6  christos fi
    251   1.1.1.6  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    252   1.1.1.9  christos status=$((status + ret))
    253   1.1.1.9  christos n=$((n + 1))
    254   1.1.1.6  christos 
    255   1.1.1.7  christos echo_i "Check that 'zone-statistics full;' is processed by 'rndc reconfig' ($n)"
    256   1.1.1.7  christos ret=0
    257   1.1.1.7  christos # off by default
    258   1.1.1.7  christos rndc_stats ns2 10.53.0.2 || ret=1
    259   1.1.1.9  christos sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' >/dev/null && ret=0
    260   1.1.1.7  christos # turn on
    261  1.1.1.11  christos cp ns2/named2.conf ns2/named.conf
    262   1.1.1.7  christos rndc_reconfig ns2 10.53.0.2
    263   1.1.1.7  christos rndc_stats ns2 10.53.0.2 || ret=1
    264   1.1.1.9  christos sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' >/dev/null || ret=1
    265   1.1.1.7  christos # turn off
    266  1.1.1.11  christos cp ns2/named1.conf ns2/named.conf
    267   1.1.1.7  christos rndc_reconfig ns2 10.53.0.2
    268   1.1.1.7  christos rndc_stats ns2 10.53.0.2 || ret=1
    269   1.1.1.9  christos sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' >/dev/null && ret=0
    270   1.1.1.7  christos # turn on
    271  1.1.1.11  christos cp ns2/named2.conf ns2/named.conf
    272   1.1.1.7  christos rndc_reconfig ns2 10.53.0.2
    273   1.1.1.7  christos rndc_stats ns2 10.53.0.2 || ret=1
    274   1.1.1.9  christos sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' >/dev/null || ret=1
    275       1.1  christos if [ $ret != 0 ]; then echo_i "failed"; fi
    276   1.1.1.9  christos status=$((status + ret))
    277   1.1.1.9  christos n=$((n + 1))
    278       1.1  christos 
    279       1.1  christos echo_i "exit status: $status"
    280       1.1  christos [ $status -eq 0 ] || exit 1
    281