Speedtest graph/data template available

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

DLinkOZ
Posts: 7
Joined: Wed Dec 24, 2014 2:37 pm

Re: Speedtest graph/data template available

Post by DLinkOZ »

I had the same problem. First time I didn't have the script created, and the poller error log pointed that out. Putting my speedtest-cli command in /usr/local/share/cacti/scripts/speedtest.sh with appropriate permissions fixed that. I still didn't have data in the graphs. As per a previous post, bumping the script timeout within cacti fixed that and I now have data. I hope that can help someone else.

My bandwidth suffers during prime hours and weekends, but gets the full 100mb during business hours when people are generally at work. This is what drove me to begin this graphing.
Attachments
graph_image.php.png
graph_image.php.png (14.88 KiB) Viewed 7097 times
TrickyTrix
Posts: 9
Joined: Sat Apr 16, 2011 4:22 am

Re: Speedtest graph/data template available

Post by TrickyTrix »

I want to congratulate the author of this great template. Thank you!!!

In CentOS I had to add EPEL repo, install python-pip, install speedtest-cli, put my speedtest-cli command in /usr/local/share/cacti/scripts/speedtest.sh, chmod +x speedtest.sh, install Speedtest templates and in Cacti>Configuration>Settings under Pooler change Script and Script Server Timeout Valuo to 50 seconds.
And thank you all for posting details in this thread.
TrickyTrix
Posts: 9
Joined: Sat Apr 16, 2011 4:22 am

Re: Speedtest graph/data template available

Post by TrickyTrix »

I actually realised that speedtest is bandwidth hog, it downloaded and uploaded 40GB (20GB up, 20 GB down) in last 6 hours.

Can I somehow set the graph not to execute so often?
ursal
Posts: 6
Joined: Thu Aug 20, 2009 6:52 am

Re: Speedtest graph/data template available

Post by ursal »

You can use this modified script and specify custom update interval

Code: Select all

#!/bin/bash
RESFILE="/var/tmp/speedtestresults"
INTERVAL=1200

if  ((`stat -c %Y /var/tmp/speedtestresults`+$INTERVAL<$(date +%s))); then
        # get fresh data
        RES=`/usr/local/bin/speedtest-cli --simple | cut -d" " -f1,2 | sed -e 's/ //g'| tr '\n' ' '`
        echo $RES > $RESFILE
else
        # get fake results from last run
        RES=`cat $RESFILE`
fi

echo $RES
1337seeker
Posts: 2
Joined: Wed Aug 26, 2015 6:57 am

Re: Speedtest graph/data template available

Post by 1337seeker »

Hi guys,

I'm new to Cacti and require some help with the above script as I'm not receiving any data on my Bandwidth measurement: Speedtest.net graph.
I think my issue exists within "Data Input Methods" - "Input String" for SpeedTest script, but I'm not sure why it's not working and what it needs to be.

The setting are as follows:

Code: Select all

Name: SpeedTest script
Input Type: Script/Command
Input String: /usr/local/share/cacti/scripts/speedtest-cli --simple | cut -d" " -f1,2 | sed -e 's/ //g'| tr '\n' ' '
Intput Fields: <blank>
Output Field: Download, Ping, Upload (pre-set)
Cacti.log Output:

Code: Select all

SYSTEM STATS: Time:64.2104 Method:spine Processes:1 Threads:1 Hosts:9 HostsPerProcess:9 DataSources:6 RRDsProcessed:6
SPINE: Poller[0] Host[1] ERROR: Empty result [127.0.0.1]: '/usr/local/share/cacti/scripts/speedtest-cli --simple | cut -d\" \" -f1,2 | sed -e \'s/ //g\'| tr \'\\n\' \' \''
By looking at my log output I can definitely see a difference between what has been set at "Input String" for script and what is being Output by Cacti.

Here is a breakdown of what I have done so far:
  • - Downloaded the script from: https://github.com/sivel/speedtest-cli
    - Copied the script to /usr/local/share/cacti/scripts/
    - Made script executable: Chmod 777 speedtest-cli
    - Tested script from command-line and it works (Provides: Ping, Download and Upload data.)
    - Imported both Templates
    - Created the graph for localhost
    - Updated Poller Settings
    "Poller Type" to spine
    "Script and Script Server Timeout Value" to 300
    - Updated Data Input Methods for SpeedTest script
    Input String: /usr/local/share/cacti/scripts/speedtest-cli --simple | cut -d" " -f1,2 | sed -e 's/ //g'| tr '\n' ' '

Any help would be much appreciated.

Thanks in advance,
Ruan
1337seeker
Posts: 2
Joined: Wed Aug 26, 2015 6:57 am

Re: Speedtest graph/data template available

Post by 1337seeker »

Ignore my previous response, I got it to work following @ursal suggestion.

Thanks @ursal
lightenup
Posts: 19
Joined: Mon Dec 06, 2010 10:09 am

Re: Speedtest graph/data template available

Post by lightenup »

Just a heads up the speedtest-cli does not provide accurate upload speed results. I have installed it on three separate Ubuntu hosts and all of them give a slow upload result, usually slow by a factor of 10x. I wish there was a fix because this really is a cool tool.

For example:

$ speedtest-cli
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from XXX...
Selecting best server based on latency...
Hosted by T-Mobile (Beltsville, MD) [38.30 km]: 6.999 ms
Testing download speed........................................
Download: 366.94 Mbit/s
Testing upload speed..................................................
Upload: 31.62 Mbit/s

Where as in the browser client I get:
Download
477.42Mb/s
Upload
441.65Mb/s
Pep
Posts: 4
Joined: Thu Mar 10, 2016 3:26 am

Re: Speedtest graph/data template available

Post by Pep »

Hey

i use the .sh script from ursal. But in my graphs there are only "NaN"

rrdtool info says:

Code: Select all

root@raspberrypi:~# rrdtool info /var/lib/cacti/rra/hp_switch_ping_118.rrd
filename = "/var/lib/cacti/rra/hp_switch_ping_118.rrd"
rrd_version = "0003"
step = 600
last_update = 1470056042
header_size = 3672
ds[Ping].index = 0
ds[Ping].type = "GAUGE"
ds[Ping].minimal_heartbeat = 120
ds[Ping].min = 0,0000000000e+00
ds[Ping].max = 1,0000000000e+03
ds[Ping].last_ds = "22.781"
ds[Ping].value = NaN
ds[Ping].unknown_sec = 242
ds[Download].index = 1
ds[Download].type = "GAUGE"
ds[Download].minimal_heartbeat = 120
ds[Download].min = 0,0000000000e+00
ds[Download].max = 1,0000000000e+03
ds[Download].last_ds = "25.49"
ds[Download].value = NaN
ds[Download].unknown_sec = 242
ds[Upload].index = 2
ds[Upload].type = "GAUGE"
ds[Upload].minimal_heartbeat = 120
ds[Upload].min = 0,0000000000e+00
ds[Upload].max = 1,0000000000e+03
ds[Upload].last_ds = "5.21"
ds[Upload].value = NaN
ds[Upload].unknown_sec = 242
rra[0].cf = "AVERAGE"
rra[0].rows = 600
rra[0].cur_row = 121
rra[0].pdp_per_row = 1
rra[0].xff = 0,0000000000e+00
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0
rra[0].cdp_prep[1].value = NaN
rra[0].cdp_prep[1].unknown_datapoints = 0
rra[0].cdp_prep[2].value = NaN
rra[0].cdp_prep[2].unknown_datapoints = 0
why are my values NaN?

Can somebody help me?
dogs1005
Posts: 42
Joined: Tue Jul 15, 2014 3:39 am

Re: Speedtest graph/data template available

Post by dogs1005 »

I need to change the interval that it polls but not sure what to do with this snippet of code.
I am using the speedtest-cli that got installed using pip.
Any help greatly aprreciated.
ursal wrote:You can use this modified script and specify custom update interval

Code: Select all

#!/bin/bash
RESFILE="/var/tmp/speedtestresults"
INTERVAL=1200

if  ((`stat -c %Y /var/tmp/speedtestresults`+$INTERVAL<$(date +%s))); then
        # get fresh data
        RES=`/usr/local/bin/speedtest-cli --simple | cut -d" " -f1,2 | sed -e 's/ //g'| tr '\n' ' '`
        echo $RES > $RESFILE
else
        # get fake results from last run
        RES=`cat $RESFILE`
fi

echo $RES
smiles
Cacti User
Posts: 79
Joined: Mon Sep 10, 2012 5:54 pm

Re: Speedtest graph/data template available

Post by smiles »

The interval is in seconds, so I've reduced my script interval to 300 (5 minutes) to match the cacti poller interval.

The interval in your script is separate from cacti's interval and will effectively cache the last results so cacti will see the same results for 20 minutes (4 polling cycles) the way you currently have it set.
dogs1005
Posts: 42
Joined: Tue Jul 15, 2014 3:39 am

Re: Speedtest graph/data template available

Post by dogs1005 »

thank you for your reply smiles but I didn't explain myself properly.

the script I quoted above was from someone else and my question was what do i do with it. I tried replacing my speedtest-cli with it but kept getting errors in the log

SPINE: Poller[0] Host[13] Description[VM Manchester Speedtest Server] ERROR: Empty result [xxx.xxx.xxx.xxx]: '/usr/local/share/cacti/scripts/speedtest.sh/speedtest_cli --simple | cut -d" " -f1,2 | sed -e 's/ //g'| tr '\n' ' ''

below is the speedtest-cli i am using which got created when installing with pip and works fine but the polling time is way too frequent

Code: Select all

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from speedtest import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
dogs1005
Posts: 42
Joined: Tue Jul 15, 2014 3:39 am

Re: Speedtest graph/data template available

Post by dogs1005 »

pilotMsk wrote:
evrenbey wrote:Thanks for templates.

i just want to ask a question,

if i want to draw different graphs for different speedtest servers for example

graph for Turkey and graph for US for servers how can i do that?

check
speedtest-cli --list
then use server that you want....
/usr/bin/speedtest-cli --simple --server 3682|cut -d" " -f1,2 |sed -e 's/ //g'|tr '\n' ' '
I'm scratching my head trying to understand how to graph more than one speedtest because if I add the above in the data input method input string then that will be used for all subsequent graphs won't it?

Also if anyone could post their speedtest-cli script that has a polling interval in it that would be awesome :)
vadya
Posts: 1
Joined: Mon Jan 23, 2017 9:45 pm

Re: Speedtest graph/data template available

Post by vadya »

I can't quite figure out what is going wrong here for me:

The script works perfectly (formatted output, etc) when I call it directly from the terminal:

****@****:/usr/local/share/cacti/scripts$ ./speedtest.sh
Ping:12.212 Download:148.62 Upload:11.17

But when I check poller-error.log for Cacti I see this error:

/usr/local/share/cacti/scripts/speedtest.sh: line 2: speedtest-cli: command not found


I don't think there should be permission issues (I checked carefully to make sure it wasn't a missing +x or something) ... why is the command not found when calling the script from within Cacti but no issues from the terminal? Everything else seems to configured fine and I assume the graph will work as soon as I sort out why the poller cannot call "speedtest-cli" when executing the script.



For reference, here's the contents of speedtest.sh - I kept it exactly as the examples in this thread until I get it up and running:

#!/bin/bash
speedtest-cli --simple | cut -d" " -f1,2 | sed -e 's/ //g' | tr '\n' ' '



-edit -

I just removed #!/bin/bash and kept speedtest.sh as a single line ... and now I get this error from the poller:

/usr/local/share/cacti/scripts/speedtest.sh: 1: /usr/local/share/cacti/scripts/speedtest.sh: speedtest-cli: Permission denied



So maybe it is permissions? Why would it be different error without #!/bin/bash as the first line of the script? I'm now more confused than when I first posted.
tomturner93
Posts: 1
Joined: Thu Feb 20, 2020 2:05 pm

Re: Speedtest graph/data template available

Post by tomturner93 »

Hi all,

I'm brand new at this - I've setup as others prior to this post and I am getting the following in the logs (attached).
Log.PNG
Log.PNG (12.94 KiB) Viewed 3274 times
I would be grateful for any help!

Thanks,

Tom
netniV
Cacti Guru User
Posts: 3440
Joined: Sun Aug 27, 2017 12:05 am

Re: Speedtest graph/data template available

Post by netniV »

Trying using the full path to the cli.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests