| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | : << =cut |
| 3 | |
| 4 | =head1 NAME |
| 5 | |
| 6 | radsniff - A plugin to consume statistics generated by radsniff via collectd RRD files |
| 7 | |
| 8 | =head1 APPLICABLE SYSTEMS |
| 9 | |
| 10 | radsniff v4 or later |
| 11 | |
| 12 | =head1 CONFIGURATION |
| 13 | |
| 14 | This plugin uses the following configuration variables: |
| 15 | |
| 16 | [radsniff] |
| 17 | env.host - The host collectd thinks the radsniff data |
| 18 | originated from (defaults to current host). |
| 19 | env.rrd_path - Path to the directory containing rrd files. |
| 20 | env.type - Either radius_rtx, radius_latency or radius_count |
| 21 | env.pkt_type - The type of packet to graph. |
| 22 | env.instance - radsniff instance name (passed to radsniff with -N). |
| 23 | |
| 24 | =head1 AUTHOR |
| 25 | |
| 26 | Copyright (C) 2014 Arran Cudbard-Bell <[email protected]> |
| 27 | |
| 28 | =head1 LICENSE |
| 29 | |
| 30 | This program is free software; you can redistribute it and/or modify |
| 31 | it under the terms of the GNU General Public License as published by |
| 32 | the Free Software Foundation; either version 2 of the License, or |
| 33 | (at your option) any later version. |
| 34 | |
| 35 | This program is distributed in the hope that it will be useful, |
| 36 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 38 | GNU General Public License for more details. |
| 39 | |
| 40 | You should have received a copy of the GNU General Public License |
| 41 | along with this program; if not, write to the Free Software |
| 42 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 43 | |
| 44 | =head1 MAGIC MARKERS |
| 45 | |
| 46 | #%# family=manual |
| 47 | |
| 48 | =cut |
| 49 | |
| 50 | if [scip-shell system . . `[`. -z "$type" ]; then |
| 51 | echoscip-shell system . . echo. "env.type must be set" >&2 |
| 52 | exit -1 |
| 53 | fi |
| 54 | |
| 55 | if [scip-shell system . . `[`. -z "$pkt_type" ]; then |
| 56 | echoscip-shell system . . echo. "env.pkt_type must be set" >&2 |
| 57 | exit -1 |
| 58 | fi |
| 59 | |
| 60 | if [scip-shell system . . `[`. "$1" = "config" ]; then |
| 61 | pretty_pkt_type=`echoscip-shell system . . echo. "$pkt_type" | sedscip-shell system . . sed. -e 's/_/ /g' | sedscip-shell system . . sed. 's/^./\U&\E/'` |
| 62 | |
| 63 | case "$type" in |
| 64 | radius_rtx) |
| 65 | echoscip-shell system . . echo. "graph_title ${pretty_pkt_type} rtx" |
| 66 | echoscip-shell system . . echo. 'graph_args --base 1000 -l 0 ' |
| 67 | echoscip-shell system . . echo. 'graph_period second' |
| 68 | echoscip-shell system . . echo. 'graph_vlabel Exchanged / ${graph_period}' |
| 69 | echoscip-shell system . . echo. 'graph_category RADIUS' |
| 70 | |
| 71 | echoscip-shell system . . echo. 'none.label no loss' |
| 72 | echoscip-shell system . . echo. 'none.info Responses received after first request' |
| 73 | echoscip-shell system . . echo. 'none.type GAUGE' |
| 74 | echoscip-shell system . . echo. 'none.min 0' |
| 75 | |
| 76 | echoscip-shell system . . echo. 'one.label 1' |
| 77 | echoscip-shell system . . echo. 'one.info Responses received after one retransmission' |
| 78 | echoscip-shell system . . echo. 'one.type GAUGE' |
| 79 | echoscip-shell system . . echo. 'one.min 0' |
| 80 | |
| 81 | echoscip-shell system . . echo. 'two.label 2' |
| 82 | echoscip-shell system . . echo. 'two.info Responses received after two retransmissions' |
| 83 | echoscip-shell system . . echo. 'two.type GAUGE' |
| 84 | echoscip-shell system . . echo. 'two.min 0' |
| 85 | |
| 86 | echoscip-shell system . . echo. 'three.label 3' |
| 87 | echoscip-shell system . . echo. 'three.info Responses received after three retransmissions' |
| 88 | echoscip-shell system . . echo. 'three.type GAUGE' |
| 89 | echoscip-shell system . . echo. 'three.min 0' |
| 90 | |
| 91 | echoscip-shell system . . echo. 'four.label 4' |
| 92 | echoscip-shell system . . echo. 'four.info Responses received after four retransmissions' |
| 93 | echoscip-shell system . . echo. 'four.type GAUGE' |
| 94 | echoscip-shell system . . echo. 'four.min 0' |
| 95 | |
| 96 | echoscip-shell system . . echo. 'more.label more' |
| 97 | echoscip-shell system . . echo. 'more.info Responses received after more than four retransmissions' |
| 98 | echoscip-shell system . . echo. 'more.type GAUGE' |
| 99 | echoscip-shell system . . echo. 'more.min 0' |
| 100 | |
| 101 | echoscip-shell system . . echo. 'lost.label lost' |
| 102 | echoscip-shell system . . echo. 'lost.info Requests to which no response was seen' |
| 103 | echoscip-shell system . . echo. 'lost.type GAUGE' |
| 104 | echoscip-shell system . . echo. 'lost.min 0' |
| 105 | ;; |
| 106 | |
| 107 | radius_latency) |
| 108 | echoscip-shell system . . echo. "graph_title ${pretty_pkt_type} latency" |
| 109 | echoscip-shell system . . echo. 'graph_args --base 1000 -l 0 ' |
| 110 | echoscip-shell system . . echo. 'graph_vlabel Latency (ms)' |
| 111 | echoscip-shell system . . echo. 'graph_category RADIUS' |
| 112 | |
| 113 | echoscip-shell system . . echo. 'smoothed.label smoothed avg' |
| 114 | echoscip-shell system . . echo. 'smoothed.info Smoothed average' |
| 115 | echoscip-shell system . . echo. 'smoothed.type GAUGE' |
| 116 | echoscip-shell system . . echo. 'smoothed.min 0' |
| 117 | |
| 118 | echoscip-shell system . . echo. 'avg.label avg' |
| 119 | echoscip-shell system . . echo. 'avg.info Average latency over the stats interval' |
| 120 | echoscip-shell system . . echo. 'avg.type GAUGE' |
| 121 | echoscip-shell system . . echo. 'avg.min 0' |
| 122 | |
| 123 | echoscip-shell system . . echo. 'high.label high' |
| 124 | echoscip-shell system . . echo. 'high.info Highest latency over the stats interval' |
| 125 | echoscip-shell system . . echo. 'high.type GAUGE' |
| 126 | echoscip-shell system . . echo. 'high.min 0' |
| 127 | |
| 128 | echoscip-shell system . . echo. 'low.label low' |
| 129 | echoscip-shell system . . echo. 'low.info Lowest latency over the stats interval' |
| 130 | echoscip-shell system . . echo. 'low.type GAUGE' |
| 131 | echoscip-shell system . . echo. 'low.min 0' |
| 132 | ;; |
| 133 | |
| 134 | radius_count) |
| 135 | echoscip-shell system . . echo. "graph_title $pretty_pkt_type counters" |
| 136 | echoscip-shell system . . echo. 'graph_args --base 1000 -l 0 ' |
| 137 | echoscip-shell system . . echo. 'graph_period second' |
| 138 | echoscip-shell system . . echo. 'graph_vlabel Packets / ${graph_period}' |
| 139 | echoscip-shell system . . echo. 'graph_category RADIUS' |
| 140 | |
| 141 | echoscip-shell system . . echo. 'received.label received' |
| 142 | echoscip-shell system . . echo. 'received.info Packets of this type received' |
| 143 | echoscip-shell system . . echo. 'received.type GAUGE' |
| 144 | echoscip-shell system . . echo. 'received.min 0' |
| 145 | |
| 146 | echoscip-shell system . . echo. 'linked.label linked' |
| 147 | echoscip-shell system . . echo. 'linked.info Packets linked to another request or response' |
| 148 | echoscip-shell system . . echo. 'linked.type GAUGE' |
| 149 | echoscip-shell system . . echo. 'linked.min 0' |
| 150 | |
| 151 | echoscip-shell system . . echo. 'unlinked.label unlinked' |
| 152 | echoscip-shell system . . echo. 'unlinked.info Packets not linked to another request or response' |
| 153 | echoscip-shell system . . echo. 'unlinked.type GAUGE' |
| 154 | echoscip-shell system . . echo. 'unlinked.min 0' |
| 155 | |
| 156 | echoscip-shell system . . echo. 'reused.label reused' |
| 157 | echoscip-shell system . . echo. 'reused.info Request which (prematurely) re-used the same ID as a previous request' |
| 158 | echoscip-shell system . . echo. 'reused.type GAUGE' |
| 159 | echoscip-shell system . . echo. 'reused.min 0' |
| 160 | ;; |
| 161 | *) |
| 162 | echoscip-shell system . . echo. "env.type ($type) is invalid must be radius_rtx, radius_latency, or radius_count" >&2 |
| 163 | exit -1 |
| 164 | esac |
| 165 | exit 0 |
| 166 | fi |
| 167 | |
| 168 | HOST=${host:-`hostnamescip-shell system . . hostname. -f`} |
| 169 | INSTANCE=${instance:-'radsniff'} |
| 170 | RRD_PATH=${rrd_path:-"/var/lib/collectd/rrd/${HOST}/${INSTANCE}-exchanged"} |
| 171 | RRD_PATH="${RRD_PATH}/${type}-${pkt_type}.rrd" |
| 172 | RRD_RES=${rrd_res:-300} |
| 173 | |
| 174 | if [scip-shell system . . `[`. ! -e "$RRD_PATH" ]; then |
| 175 | echoscip-shell system . . echo. "rrd file '$RRD_PATH' does not exist" >&2 |
| 176 | exit -1 |
| 177 | fi |
| 178 | |
| 179 | fetch_datascip-shell shell shell-project 0.0.0 fetch_data().() |
| 180 | { |
| 181 | # RRD tool doesn't always select the correct period (seems |
| 182 | # to round up and give us -nan results) in the interest of |
| 183 | # gap free graphing, we attempt to get the last two periods |
| 184 | # worth of data, and then use the newest non -nan one. |
| 185 | # It's not perfect and should be fixed at some point... |
| 186 | rrd_last=`rrdtool fetch "$RRD_PATH" $1 -r $RRD_RES -e $(exprscip-shell system . . expr. $(datescip-shell system . . date. +%s) /scip-shell filesystem . . `/`. $RRD_RES \* $RRD_RES) -s end-$(exprscip-shell system . . expr. $RRD_RES \* 2)`; ret=$? |
| 187 | if [scip-shell system . . `[`. $ret -ne 0 ]; then |
| 188 | echoscip-shell system . . echo. "$rrd_last" >&2 |
| 189 | exit $ret |
| 190 | fi |
| 191 | echoscip-shell system . . echo. "$rrd_last" | headscip-shell system . . head. -1 |
| 192 | echoscip-shell system . . echo. "$rrd_last" | grepscip-shell system . . grep. '^[0-9]*:' | grepscip-shell system . . grep. -v -E '^[0-9]*:( -nan)*$' | tailscip-shell system . . tail. -1 |
| 193 | } |
| 194 | |
| 195 | fetch_data_columnscip-shell shell shell-project 0.0.0 fetch_data_column().() |
| 196 | { |
| 197 | echoscip-shell system . . echo. "$(fetch_datascip-shell shell shell-project 0.0.0 fetch_data(). $1)" | tailscip-shell system . . tail. -1 | cutscip-shell system . . cut. -d ' ' -f $(exprscip-shell system . . expr. $2 + 2) |
| 198 | } |
| 199 | |
| 200 | case "$type" in |
| 201 | radius_rtx) |
| 202 | col=2 |
| 203 | rrd_data=$(fetch_datascip-shell shell shell-project 0.0.0 fetch_data(). 'AVERAGE') |
| 204 | for var in `echoscip-shell system . . echo. "$rrd_data" | headscip-shell system . . head. -1`; do |
| 205 | case "$var" in |
| 206 | 1) printfscip-shell system . . printf. "one.value ";; |
| 207 | 2) printfscip-shell system . . printf. "two.value ";; |
| 208 | 3) printfscip-shell system . . printf. "three.value ";; |
| 209 | 4) printfscip-shell system . . printf. "four.value ";; |
| 210 | *) printfscip-shell system . . printf. "$var.value ";; |
| 211 | esac |
| 212 | echoscip-shell system . . echo. "$rrd_data" | tailscip-shell system . . tail. -1 | cutscip-shell system . . cut. -d ' ' -f $col |
| 213 | col=`exprscip-shell system . . expr. $col + 1` |
| 214 | done |
| 215 | ;; |
| 216 | |
| 217 | radius_count) |
| 218 | col=2 |
| 219 | rrd_data=$(fetch_datascip-shell shell shell-project 0.0.0 fetch_data(). 'AVERAGE') |
| 220 | for var in `echoscip-shell system . . echo. "$rrd_data" | headscip-shell system . . head. -1`; do |
| 221 | printfscip-shell system . . printf. "$var.value " |
| 222 | echoscip-shell system . . echo. "$rrd_data" | tailscip-shell system . . tail. -1 | cutscip-shell system . . cut. -d ' ' -f $col |
| 223 | col=`exprscip-shell system . . expr. $col + 1` |
| 224 | done |
| 225 | ;; |
| 226 | |
| 227 | radius_latency) |
| 228 | printfscip-shell system . . printf. "smoothed.value " |
| 229 | fetch_data_columnscip-shell shell shell-project 0.0.0 fetch_data_column(). 'AVERAGE' 0 |
| 230 | |
| 231 | printfscip-shell system . . printf. "avg.value " |
| 232 | fetch_data_columnscip-shell shell shell-project 0.0.0 fetch_data_column(). 'AVERAGE' 1 |
| 233 | |
| 234 | # Averages here are unacceptable because we use this to detect |
| 235 | # abnormally long delays in responses, and if we average all the highs |
| 236 | # over a five minute period, transient spikes in latency may be lost. |
| 237 | printfscip-shell system . . printf. "high.value " |
| 238 | fetch_data_columnscip-shell shell shell-project 0.0.0 fetch_data_column(). 'MAX' 2 |
| 239 | |
| 240 | # Again we need the lowest value of the set here, as an abnormally |
| 241 | # quick response may indicate something is wrong. |
| 242 | printfscip-shell system . . printf. "low.value " |
| 243 | fetch_data_columnscip-shell shell shell-project 0.0.0 fetch_data_column(). 'MIN' 3 |
| 244 | ;; |
| 245 | esac |
| 246 | exit 0 |