1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
9 # _update_every is a special variable - it holds the number of seconds
10 # between the calls of the _update() function
16 # _check is called once, to find out if this chart should be enabled or not
18 require_cmd iw || return 1
20 local ev=$(run iw dev | awk '
28 print "ap_devs[" i "]=\"" ssid "\""
35 /^[ \t]+ssid / { ssid = $2; }
36 /^[ \t]+type AP$/ { ap = 1; }
39 print "ap_devs[" i "]=\"" ssid "\""
46 # - 0 to enable the chart
47 # - 1 to disable the chart
49 [ ${#ap_devs[@]} -gt 0 ] && return 0
50 error "no devices found in AP mode, with 'iw dev'"
54 # _create is called once, to create the charts
58 for dev in "${!ap_devs[@]}"
60 ssid="${ap_devs[${dev}]}"
62 # create the chart with 3 dimensions
64 CHART ap_clients.${dev} '' "Connected clients to ${ssid} on ${dev}" "clients" ${dev} ap.clients line $((ap_priority + 1)) $ap_update_every
65 DIMENSION clients '' absolute 1 1
67 CHART ap_bandwidth.${dev} '' "Bandwidth for ${ssid} on ${dev}" "kilobits/s" ${dev} ap.net area $((ap_priority + 2)) $ap_update_every
68 DIMENSION received '' incremental 8 1024
69 DIMENSION sent '' incremental -8 1024
71 CHART ap_packets.${dev} '' "Packets for ${ssid} on ${dev}" "packets/s" ${dev} ap.packets line $((ap_priority + 3)) $ap_update_every
72 DIMENSION received '' incremental 1 1
73 DIMENSION sent '' incremental -1 1
75 CHART ap_issues.${dev} '' "Transmit Issues for ${ssid} on ${dev}" "issues/s" ${dev} ap.issues line $((ap_priority + 4)) $ap_update_every
76 DIMENSION retries 'tx retries' incremental 1 1
77 DIMENSION failures 'tx failures' incremental -1 1
79 CHART ap_signal.${dev} '' "Average Signal for ${ssid} on ${dev}" "dBm" ${dev} ap.signal line $((ap_priority + 5)) $ap_update_every
80 DIMENSION signal 'average signal' absolute 1 1
82 CHART ap_bitrate.${dev} '' "Bitrate for ${ssid} on ${dev}" "Mbps" ${dev} ap.bitrate line $((ap_priority + 6)) $ap_update_every
83 DIMENSION receive '' absolute 1 1000
84 DIMENSION transmit '' absolute -1 1000
85 DIMENSION expected 'expected throughput' absolute 1 1000
93 # _update is called continiously, to collect the values
95 # the first argument to this function is the microseconds since last update
96 # pass this parameter to the BEGIN statement (see bellow).
98 # do all the work to collect / calculate the values
100 # remember: KEEP IT SIMPLE AND SHORT
102 for dev in "${!ap_devs[@]}"
104 iw ${dev} station dump |\
121 /^[ \\t]+rx bytes:/ { rb += \$3 }
122 /^[ \\t]+tx bytes:/ { tb += \$3 }
123 /^[ \\t]+rx packets:/ { rp += \$3 }
124 /^[ \\t]+tx packets:/ { tp += \$3 }
125 /^[ \\t]+tx retries:/ { tr += \$3 }
126 /^[ \\t]+tx failed:/ { tf += \$3 }
127 /^[ \\t]+signal:/ { s += \$2; }
128 /^[ \\t]+rx bitrate:/ { x = \$3; rt += x * 1000; }
129 /^[ \\t]+tx bitrate:/ { x = \$3; tt += x * 1000; }
130 /^[ \\t]+expected throughput:(.*)Mbps/ {
132 sub(/Mbps/, \"\", x);
136 print \"BEGIN ap_clients.${dev}\"
137 print \"SET clients = \" c;
139 print \"BEGIN ap_bandwidth.${dev}\"
140 print \"SET received = \" rb;
141 print \"SET sent = \" tb;
143 print \"BEGIN ap_packets.${dev}\"
144 print \"SET received = \" rp;
145 print \"SET sent = \" tp;
147 print \"BEGIN ap_issues.${dev}\"
148 print \"SET retries = \" tr;
149 print \"SET failures = \" tf;
151 print \"BEGIN ap_signal.${dev}\"
152 print \"SET signal = \" s / c;
156 print \"BEGIN ap_bitrate.${dev}\"
157 print \"SET receive = \" rt / c;
158 print \"SET transmit = \" tt / c;
159 print \"SET expected = \" e / c;