summaryrefslogtreecommitdiff
path: root/datasources/internet_speed.sh
blob: 2b0b85bf7ad786b420c3701ec852eee57d57376d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

. "`dirname \"$0\"`"/datastore-functions.sh

if ! curl --version >/dev/null; then
	echo "missing curl" >&2
	exit 1
fi

measure_speed() {
	curl --write-out "%{speed_download}" \
		--silent \
		--max-time 60 \
		--output /dev/null \
		"http://speedtest.qsc.de/500kB.qsc" \
	| cut -f 1 -d ','
	return $?
}

speed=`measure_speed`
if [ $? = 0 ]; then
	put_value_sensor_now \
		"`hostname`.internet.speed" \
		"$speed"
else
	put_value_sensor_now \
		"`hostname`.internet.speed" \
		"0"
fi
exit $?