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