Projet

Général

Profil

Révision 4de0ceb0

ID4de0ceb073d0f2e1a49684e7c155a164b5b1b5b4
Parent 265e39e0
Enfant 6cf51e58

Ajouté par Lars Kruse il y a environ 10 ans

new network plugin added: wireless_channel_occupation

This plugin tracks the occupation of the shared medium (wifi channel).
It uses the "iw" tool for extracting the time slices spent by
the wireless driver receiving, transmitting or ignoring (noise) on the
current channel. This ratio is a good indication for the remaining
capacity of the shared communication medium.

Voir les différences:

plugins/network/wireless_channel_occupation_
1
#!/bin/sh
2
#
3
# Monitor the wifi channel occupation (taken from "iw dev wlan0 survey dump").
4
#
5
# Symlink this plugin with the name of the wifi interface added (e.g. "wlan0").
6
#
7
#
8
# Copyright (C) 2015 Lars Kruse <devel@sumpfralle.de>
9
#
10
#    This program is free software: you can redistribute it and/or modify
11
#    it under the terms of the GNU General Public License as published by
12
#    the Free Software Foundation, either version 3 of the License, or
13
#    (at your option) any later version.
14
#
15
#    This program is distributed in the hope that it will be useful,
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
#    GNU General Public License for more details.
19
#
20
#    You should have received a copy of the GNU General Public License
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
#
23
# Magic markers
24
#%# capabilities=autoconf suggest
25
#%# family=auto
26

  
27
set -eu
28

  
29

  
30
SCRIPT_PREFIX="wireless_channel_occupation_"
31

  
32

  
33
clean_fieldname() {
34
	echo "$1" | sed 's/^\([^A-Za-z_]\)/_\1/; s/[^A-Za-z0-9_]/_/g'
35
}
36

  
37

  
38
get_wifi_devices() {
39
	iw dev | grep Interface | awk '{print $2}'
40
}
41

  
42

  
43
get_wifi_device_from_suffix() {
44
	local suffix
45
	local called
46
	called=$(basename "$0")
47
	suffix="${called#$SCRIPT_PREFIX}"
48
	# empty result if the prefix did not match (and was not removed)
49
	[ "$suffix" = "$0" ] && echo "" || echo "$suffix"
50
}
51

  
52

  
53
if [ "${1:-}" = "autoconf" ]; then
54
	if which iw 2>/dev/null; then
55
		if [ -n "$(get_wifi_devices)" ]; then
56
			echo "yes"
57
		else
58
			echo "no (missing wifi devices)"
59
		fi
60
	else
61
		echo "no (missing 'iw' dependency)"
62
	fi
63
elif [ "${1:-}" = "suggest" ]; then
64
	get_wifi_devices
65
elif [ "${1:-}" = "config" ]; then
66
	device=$(get_wifi_device_from_suffix)
67
	[ -z "$device" ] && echo >&2 "Invalid wifi device name given" && exit 1
68
	echo "graph_title Channel Occupation of $device"
69
	echo "graph_vlabel %"
70
	echo "graph_category wireless"
71
	echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100"
72
	dev_field=$(clean_fieldname "$device")
73

  
74
	# active: listening time on this channel (usually: 5 minutes = 300000ms)
75
	echo "${dev_field}_active.label Transmit"
76
	echo "${dev_field}_active.type DERIVE"
77
	echo "${dev_field}_active.graph no"
78

  
79
	# busy = receive + transmit + unknown
80
	echo "${dev_field}_busy.label unknown"
81
	echo "${dev_field}_busy.type DERIVE"
82
	echo "${dev_field}_busy.draw AREA"
83
	echo "${dev_field}_busy.cdef 100,1,${dev_field}_active,${dev_field}_busy,${dev_field}_receive,${dev_field}_transmit,+,-,/,/,*"
84

  
85
	# receive: this radio receives traffic for itself
86
	echo "${dev_field}_receive.label Receive"
87
	echo "${dev_field}_receive.type DERIVE"
88
	echo "${dev_field}_receive.draw STACK"
89
	echo "${dev_field}_receive.cdef 100,${dev_field}_receive,${dev_field}_active,/,*"
90

  
91
	# transmit: this radio transmits traffic
92
	echo "${dev_field}_transmit.label Transmit"
93
	echo "${dev_field}_transmit.type DERIVE"
94
	echo "${dev_field}_transmit.draw STACK"
95
	echo "${dev_field}_transmit.cdef 100,${dev_field}_transmit,${dev_field}_active,/,*"
96
else
97
	device=$(get_wifi_device_from_suffix)
98
	[ -z "$device" ] && echo >&2 "Invalid wifi device name given" && exit 1
99
	iw dev "$device" survey dump \
100
		| grep -F -A 5 "[in use]" \
101
		| grep -E "channel (busy|receive|transmit|active) time:" \
102
		| awk '{print "'${device}_'"$2"'.value'",$4}'
103
fi
104

  
105
exit 0

Formats disponibles : Unified diff