-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed2
64 lines (49 loc) · 1.98 KB
/
speed2
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
#
# Use speedtest-cli to get connection speeds through the cable modem.
#
use Text::CSV;
use Math::Round;
# Get csv formatted data.
$check = `speedtest-cli --csv`;
### If testing: comment out the command above, uncomment the line below for faked data to keep from using bandwidth.
### Fake data format...
### id,name,location,timestamp,distance,pingtime,download,upload
### ^ km ^ ^ ms ^ ^^^^ bit/s ^^^^
# $check = "8697,Cable One Inc.,Long Beach MS,2016-12-29T11:40:06.862934,16.705806919827555,20.969,229076334.09849033,10617358.019503765";
my $csv = Text::CSV->new();
$status = $csv->parse($check);
@data = $csv->fields();
# The fields that speedtest returns....
$id = @data[0];
$name = @data[1];
$location = @data[2];
$ts = @data[3];
$distance = @data[4];
$ping = @data[5];
$dl = @data[6];
$ul = @data[7];
# Changed speedtest.py to use local time instead of UTC and ISO format
($ts,undef) = split(/\./,$ts);
# Log results for later analysis
$logfile = "/var/log/broadband.log";
open (BBLOG, ">>$logfile");
print BBLOG "$ts icedell $ping $dl $ul ${id}:${name}:${location}\n";
close (BBLOG);
# Distance in kilometers, converted to miles, rounded to tenths
$distance = $distance*0.621371;
$distance = nearest(.1,$distance);
# Ping time, rounded to hundreths
$ping = nearest(.01,$ping);
# Download speed expressed in Mb/s and then rounded to hundreths
$dl = $dl/1048576;
$dl = nearest(.01,$dl);
# Upload speed expressed in Mb/s and then rounded to hundreths
$ul = $ul/1048576;
$ul = nearest(.01,$ul);
# Output for check_mk. Note the warning and critical levels for upload and download,
# and that they have ranges expressed.
# That lets you set an inverted logic, ie: Higher numbers are better.
print "P Cable_ping ping=$ping;100;1000 Ping time to ${id}:${name}/${location} (${distance} miles) ${ping}ms at ${ts}\n";
print "P Cable_down download=$dl;190:9999;150:9999 Download speed ${dl}Mb/s \n";
print "P Cable_up upload=$ul;8:999;5:999 Upload speed ${ul}Mb/s\n";