File: netperf_interim_to_rrd.sh

package info (click to toggle)
netperf 2.7.0-0.1
  • links: PTS
  • area: non-free
  • in suites: bookworm, bullseye
  • size: 8,840 kB
  • sloc: ansic: 41,631; sh: 5,259; xml: 3,129; python: 2,376; awk: 68; makefile: 66
file content (145 lines) | stat: -rwxr-xr-x 4,977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

# set -x
SAMPLE_TIMES="2 5 10 20 30 45 60"
SAMPLE_TIMES="60 45 30 20 10 5 2"
FLOW_RATES="0 200 2000 20000 200000"
NETPERF="/home/raj/netperf2_trunk/src/netperf"

# these will be switch-specific
CPMIB="SFLOW-MIB::sFlowCpInterval.11.1.3.6.1.2.1.2.2.1.1.27.1"
FSMIB="SFLOW-MIB::sFlowFsPacketSamplingRate.11.1.3.6.1.2.1.2.2.1.1.27.1"
SFLOW_RRD="/tmp/counters/192.168.1.1/1/27/generic.rrd"

for sample in $SAMPLE_TIMES
do

  LENGTH="300"
  XGRID="--x-grid SECOND:5:SECOND:30:SECOND:30:0:%X"
  # we want at least 10 sFlow samples
  SAMPLES=`expr $LENGTH / $sample`
  if [ $SAMPLES -lt 10 ]; then
    LENGTH=`expr 10 \* $sample`
    XGRID="--x-grid SECOND:10:SECOND:60:SECOND:60:0:%X"
  fi

  # configure the switch for the counter sampling interval
  snmpset 192.168.1.1 $CPMIB i $sample
  TWOXSAMPLE=`expr $sample \* 2`
  for flow in $FLOW_RATES
  do
    # configure the switch for the flow sampling rate which is one per
    # N on average, with some randomization if adhering to the sFlow
    # spec.
    snmpset 192.168.1.1 $FSMIB i $flow

    # setup some variables
    FILE_BASE="sample_${sample}_flow_${flow}"
    NETPERF_BASE="raw_netperf_${FILE_BASE}"
    NETPERF_RAW="${NETPERF_BASE}.out"
    NETPERF_RRD="${NETPERF_BASE}.rrd"

    # provide an indication of forward progress and status
    echo "sample rate $sample flow rate 1 in $flow"

    # start top
    top -b -i > "top_${FILE_BASE}.out" &
    TOP_PID=$!

    # run our netperf test long enough to make sure we have as many
    # sFlow samples as we wish even after we later skip the first two.
    $NETPERF -t UDP_STREAM -H 192.168.1.3 -l `expr $LENGTH + $TWOXSAMPLE`\
      -D 1 -c -C -- -m 1472 -s 64K -S 64K > $NETPERF_RAW

    # stop top
    kill -HUP $TOP_PID

    # prepare to shove the interim results into an RRD
    grep Interim $NETPERF_RAW > interims.tmp

    # over what time interval do we have netperf interim results?
    START=`head -1 interims.tmp | awk '{printf("%d",$10)}'`
    END=`tail -1 interims.tmp | awk '{printf("%d",$10)}'`

    # create an rrd for netperf starting at the beginning of that interval
    rrdtool create netperf.rrd --step 1 --start $START \
      DS:mbps:GAUGE:2:U:U RRA:AVERAGE:0.5:1:${LENGTH}

    # shove those interim results into the netperf rrd
    awk '{printf("rrdtool update netperf.rrd %f:%f\n",$10,$3)}' \
      interims.tmp | sh
    mv netperf.rrd $NETPERF_RRD

    # extract the data from the sflow rrd to save it for posterity
    rrdtool fetch $SFLOW_RRD AVERAGE --start $START --end $END \
      > sflow_${FILE_BASE}.fetch

    # now make the graph, trim-off the first two sFlow counter samples
    # for better automagic scaling. the magic multiplier is how to go
    # from mbps from netperf, which counts only payload, to octets on
    # the wire assuming 8 bytes of UDP header 20 bytes of IP, 14 bytes
    # of ethernet, 4 bytes of FCS and 1472 bytes of user payload
    START=`expr $START + $TWOXSAMPLE`

    # we don't like rrdtool's autoscaling
    YMIN=`rrdtool graph /dev/null --start $START --end $END \
          DEF:foo=${SFLOW_RRD}:ifOutOctets:AVERAGE \
	  CDEF:bar=foo,0.98,\* \
	  VDEF:bing=bar,MINIMUM \
	  PRINT:bing:"%6.2lf" | sed 1d`

    YMAX=`rrdtool graph /dev/null --start $START --end $END \
          DEF:foo=${SFLOW_RRD}:ifOutOctets:AVERAGE \
	  CDEF:bar=foo,1.02,\* \
	  VDEF:bing=bar,MAXIMUM \
	  PRINT:bing:"%6.2lf" | sed 1d`

    # also consider the neterf results
    NMIN=`rrdtool graph /dev/null --start $START --end $END \
          DEF:foo=${NETPERF_RRD}:mbps:AVERAGE \
	  CDEF:baz=foo,128906.25,\* \
	  CDEF:bar=baz,0.98,\* \
	  VDEF:bing=bar,MINIMUM \
	  PRINT:bing:"%6.2lf" | sed 1d`

    NMAX=`rrdtool graph /dev/null --start $START --end $END \
          DEF:foo=${NETPERF_RRD}:mbps:AVERAGE \
	  CDEF:baz=foo,128906.25,\* \
	  CDEF:bar=baz,1.02,\* \
	  VDEF:bing=bar,MAXIMUM \
	  PRINT:bing:"%6.2lf" | sed 1d`

    # I am certain someone will say dude use perl when they see this
    INMIN=`echo $NMIN | awk '{printf("%d",$1)}'`
    INMAX=`echo $NMAX | awk '{printf("%d",$1)}'`
    IYMIN=`echo $YMIN | awk '{printf("%d",$1)}'`
    IYMAX=`echo $YMAX | awk '{printf("%d",$1)}'`

    # we wont sweat the fractional part
    if [ $INMIN -lt $IYMIN ]; then
	YMIN=$NMIN
    fi

    if [ $INMAX -gt $IYMAX ]; then
        YMAX=$NMAX
    fi

    GRAPH="graph_${FILE_BASE}.svg"
    SIZE="-w 1000 -h 400"
    rrdtool graph $GRAPH --start $START --end $END \
      --imgformat SVG \
      -t "sFlow counter accuracy, average flow sample rate 1 in ${flow}" \
      -v "Octets/s" \
      $XGRID $SIZE --full-size-mode \
      --upper-limit $YMAX \
      --lower-limit $YMIN \
      --rigid \
      --alt-y-grid \
      DEF:foo=${NETPERF_RRD}:mbps:AVERAGE \
      DEF:bar=${SFLOW_RRD}:ifOutOctets:AVERAGE \
      CDEF:baz=foo,128906.25,\* \
      HRULE:124019607.84#000000:"Theoretical link-rate" \
      LINE2:baz#FF0000:"netperf+headers at 1s intvl" \
      LINE2:bar#00FF0080:"sFlow counters at ${sample}s intvl"
  done
done