]> arthur.barton.de Git - netdata.git/blob - charts.d/ap.chart.sh
Merge remote-tracking branch 'upstream/master'
[netdata.git] / charts.d / ap.chart.sh
1 #!/bin/bash
2
3 # _update_every is a special variable - it holds the number of seconds
4 # between the calls of the _update() function
5 ap_update_every=
6 ap_priority=6900
7
8 declare -A ap_devs=()
9
10 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
11
12 # _check is called once, to find out if this chart should be enabled or not
13 ap_check() {
14         local ev=$(iw dev | awk '
15                 BEGIN {
16                         i = "";
17                         ssid = "";
18                         ap = 0;
19                 }
20                 /^[ \t]+Interface / {
21                         if( ap == 1 ) {
22                                 print "ap_devs[" i "]=\"" ssid "\""
23                         }
24
25                         i = $2;
26                         ssid = "";
27                         ap = 0;
28                 }
29                 /^[ \t]+ssid / { ssid = $2; }
30                 /^[ \t]+type AP$/ { ap = 1; }
31                 END {
32                         if( ap == 1 ) {
33                                 print "ap_devs[" i "]=\"" ssid "\""
34                         }
35                 }
36         ')
37         eval "${ev}"
38
39         # this should return:
40         #  - 0 to enable the chart
41         #  - 1 to disable the chart
42
43         [ ${#ap_devs[@]} -gt 0 ] && return 0
44         return 1
45 }
46
47 # _create is called once, to create the charts
48 ap_create() {
49         local ssid dev
50
51         for dev in "${!ap_devs[@]}"
52         do
53                 ssid="${ap_devs[${dev}]}"
54
55                 # create the chart with 3 dimensions
56                 cat <<EOF
57 CHART ap_clients.${dev} '' "Connected clients to ${ssid} on ${dev}" "clients" ${dev} ap.clients line $((ap_priority + 1)) $ap_update_every
58 DIMENSION clients '' absolute 1 1
59
60 CHART ap_bandwidth.${dev} '' "Bandwidth for ${ssid} on ${dev}" "kilobits/s" ${dev} ap.net area $((ap_priority + 2)) $ap_update_every
61 DIMENSION received '' incremental 8 1024
62 DIMENSION sent '' incremental -8 1024
63
64 CHART ap_packets.${dev} '' "Packets for ${ssid} on ${dev}" "packets/s" ${dev} ap.packets line $((ap_priority + 3)) $ap_update_every
65 DIMENSION received '' incremental 1 1
66 DIMENSION sent '' incremental -1 1
67
68 CHART ap_issues.${dev} '' "Transmit Issues for ${ssid} on ${dev}" "issues/s" ${dev} ap.issues line $((ap_priority + 4)) $ap_update_every
69 DIMENSION retries 'tx retries' incremental 1 1
70 DIMENSION failures 'tx failures' incremental -1 1
71
72 CHART ap_signal.${dev} '' "Average Signal for ${ssid} on ${dev}" "dBm" ${dev} ap.signal line $((ap_priority + 5)) $ap_update_every
73 DIMENSION signal 'average signal' absolute 1 1
74
75 CHART ap_bitrate.${dev} '' "Bitrate for ${ssid} on ${dev}" "Mbps" ${dev} ap.bitrate line $((ap_priority + 6)) $ap_update_every
76 DIMENSION receive '' absolute 1 1000
77 DIMENSION transmit '' absolute -1 1000
78 DIMENSION expected 'expected throughput' absolute 1 1000
79 EOF
80
81         done
82
83         return 0
84 }
85
86 # _update is called continiously, to collect the values
87 ap_update() {
88         # the first argument to this function is the microseconds since last update
89         # pass this parameter to the BEGIN statement (see bellow).
90
91         # do all the work to collect / calculate the values
92         # for each dimension
93         # remember: KEEP IT SIMPLE AND SHORT
94
95         for dev in "${!ap_devs[@]}"
96         do
97                 iw ${dev} station dump |\
98                         awk "
99                                 BEGIN {
100                                         c = 0;
101                                         rb = 0;
102                                         tb = 0;
103                                         rp = 0;
104                                         tp = 0;
105                                         tr = 0;
106                                         tf = 0;
107                                         tt = 0;
108                                         rt = 0;
109                                         s = 0;
110                                         g = 0;
111                                         e = 0;
112                                 }
113                                 /^Station/           { c++; }
114                                 /^[ \\t]+rx bytes:/   { rb += \$3 }
115                                 /^[ \\t]+tx bytes:/   { tb += \$3 }
116                                 /^[ \\t]+rx packets:/ { rp += \$3 }
117                                 /^[ \\t]+tx packets:/ { tp += \$3 }
118                                 /^[ \\t]+tx retries:/ { tr += \$3 }
119                                 /^[ \\t]+tx failed:/  { tf += \$3 }
120                                 /^[ \\t]+signal:/     { s  += \$2; }
121                                 /^[ \\t]+rx bitrate:/ { x = \$3; rt += x * 1000; }
122                                 /^[ \\t]+tx bitrate:/ { x = \$3; tt += x * 1000; }
123                                 /^[ \\t]+expected throughput:(.*)Mbps/ {
124                                         x=\$3;
125                                         sub(/Mbps/, \"\", x);
126                                         e += x * 1000;
127                                 }
128                                 END {
129                                         print \"BEGIN ap_clients.${dev}\"
130                                         print \"SET clients = \" c;
131                                         print \"END\"
132                                         print \"BEGIN ap_bandwidth.${dev}\"
133                                         print \"SET received = \" rb;
134                                         print \"SET sent = \" tb;
135                                         print \"END\"
136                                         print \"BEGIN ap_packets.${dev}\"
137                                         print \"SET received = \" rp;
138                                         print \"SET sent = \" tp;
139                                         print \"END\"
140                                         print \"BEGIN ap_issues.${dev}\"
141                                         print \"SET retries = \" tr;
142                                         print \"SET failures = \" tf;
143                                         print \"END\"
144                                         print \"BEGIN ap_signal.${dev}\"
145                                         print \"SET signal = \" s / c;
146                                         print \"END\"
147
148                                         if( c == 0 ) c = 1;
149                                         print \"BEGIN ap_bitrate.${dev}\"
150                                         print \"SET receive = \" rt / c;
151                                         print \"SET transmit = \" tt / c;
152                                         print \"SET expected = \" e / c;
153                                         print \"END\"
154                                 }
155                                 "
156         done
157
158         return 0
159 }
160