barrycarey / speedtest-for-influxdb-and-grafana Goto Github PK
View Code? Open in Web Editor NEWA tool to run periodic speedtests and save them in InfluxDB for graphing in Grafana
A tool to run periodic speedtests and save them in InfluxDB for graphing in Grafana
Seems that password containing chars like %
trigger a template rendering error for python. For example my%p4ss%word
will trigger the following error:
Loading Configuration File config.ini
Traceback (most recent call last):
File "/src/influxspeedtest.py", line 3, in <module>
from influxspeedtest.InfluxdbSpeedtest import InfluxdbSpeedtest
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 9, in <module>
from influxspeedtest.common import log
File "/src/influxspeedtest/common/__init__.py", line 1, in <module>
from .utils import log
File "/src/influxspeedtest/common/utils.py", line 5, in <module>
from influxspeedtest.config import config
File "/src/influxspeedtest/config/__init__.py", line 10, in <module>
config = ConfigManager(config)
File "/src/influxspeedtest/config/configmanager.py", line 19, in __init__
self._load_config_values()
File "/src/influxspeedtest/config/configmanager.py", line 32, in _load_config_values
self.influx_password = self.config['INFLUXDB'].get('Password', fallback='')
File "/usr/local/lib/python3.7/configparser.py", line 1301, in get
fallback=fallback, **kwargs)
File "/usr/local/lib/python3.7/configparser.py", line 799, in get
d)
File "/usr/local/lib/python3.7/configparser.py", line 394, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/local/lib/python3.7/configparser.py", line 444, in _interpolate_some
"found: %r" % (rest,))
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%p4ss%5'
my container keeps restarting and the error show is below im not sure if i am missing something in the setup but my understanding the server url is set in the config.ini file so im not sure what im missing.
2020-09-10T18:58:16.842850499Z File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 390, in prepare_url
2020-09-10T18:58:16.843067740Z raise InvalidURL("Invalid URL %r: No host supplied" % url)
2020-09-10T18:58:16.843082493Z requests.exceptions.InvalidURL: Invalid URL 'http://:8086/query': No host supplied
config.ini file
[GENERAL]
Delay = 300
[INFLUXDB]
Address = 10.1.1.24
Port = 8086
Database = speedtest
Username = (i have tried both user with write access to DB and full admin account)
Password =
Verify_SSL = False
[SPEEDTEST]
Server =
[LOGGING]
Level = info
little things that would be great to test. e.g. this issue: https://github.com/sivel/speedtest-cli/issues/571
Currently the speedtest-cli you are using is always in "single" mode as they havent updated master. It IS fixed in devel and is default. Thinks like that. Thoughts on a :devel tag with upstream devel?
Would it possible to change to this Speedtest-cli ? should be much more accurate.
https://github.com/taganaka/SpeedTest
Would be nice because the normal cli don't make sense for me:
vm on this server with win 10 and manually on web page: 398 down and 48 up
this container on same server: 146 down and 4 up.
Hi.
Please can someone help me what the default login (user id and password ) is to Grafana?
The readme.md install to receive raw.githubusercontent.com has a very minor issue (perhaps GitHub URLs have changed since publication). Please remove /blob from the URL in Step 2 and Docker Compose (step 5, option 2)
Issue:
The docker container aborts on failure to get Speettest configuration periodically from different servers.
Occurrence:
Seemingly random. In my use case I have a list of about 8 servers across the US testing. The tool will do it's job over several iterations of those 8 servers. I will log back on some time later and discover the container crashed with the above log.
Cause:
I suspect that for whatever reason, a temporary drop in connectivity between the program and the Speettest server will cause the failure.
Idea:
Instead of the failure to obtain a config aborting the entire program, a failure to connect will initiate a retry/skip timer for that particular server, allowing the program to continue running having dropped a single test rather than all tests from the crash until next reboot.
Temporary Solution:
Adding a docker --restart-always when starting the container
I can't find the SSL config option anywhere in the documentation. It may be possible I've missed it, but I was only able to get influx running over HTTPs after picking through the ConfigManager. Might be worth adding to the Readme?
Hi! When running influxspeedtest.py with python3.4 I get the following errors:
# python3.4 influxspeedtest.py
Loading Configuration File config.ini
Configuration Successfully Loaded
2020-05-10 16:35:36,789 - DEBUG: Testing connection to InfluxDb using provided credentials
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib64/python3.4/http/client.py", line 1227, in getresponse
response.begin()
File "/usr/lib64/python3.4/http/client.py", line 386, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.4/http/client.py", line 368, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3.4/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3.4/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.4/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib64/python3.4/http/client.py", line 1227, in getresponse
response.begin()
File "/usr/lib64/python3.4/http/client.py", line 386, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.4/http/client.py", line 368, in _read_status
raise BadStatusLine(line)
urllib3.exceptions.ProtocolError: ('Connection aborted.', BadStatusLine('\x15\x03\x01\x00\x02\x02\n',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/home/zeek/Speedtest-for-InfluxDB-and-Grafana/influxspeedtest/InfluxdbSpeedtest.py", line 41, in _get_influx_connection
influx.get_list_users() # TODO - Find better way to test connection and permissions
File "/usr/lib/python3.4/site-packages/influxdb/client.py", line 928, in get_list_users
return list(self.query("SHOW USERS").get_points())
File "/usr/lib/python3.4/site-packages/influxdb/client.py", line 518, in query
expected_response_code=expected_response_code
File "/usr/lib/python3.4/site-packages/influxdb/client.py", line 333, in request
timeout=self._timeout
File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('\x15\x03\x01\x00\x02\x02\n',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "influxspeedtest.py", line 7, in <module>
collector = InfluxdbSpeedtest()
File "/opt/home/zeek/Speedtest-for-InfluxDB-and-Grafana/influxspeedtest/InfluxdbSpeedtest.py", line 17, in __init__
self.influx_client = self._get_influx_connection()
File "/opt/home/zeek/Speedtest-for-InfluxDB-and-Grafana/influxspeedtest/InfluxdbSpeedtest.py", line 46, in _get_influx_connection
elif e.code == 401:
AttributeError: 'ConnectionError' object has no attribute 'code'
I would like to leave this running and if it were to encounter an error within the Speedtest (happens about once per day) it will just retry instead of aborting
Hi,
i noticed that the ping is never updated. Would it be possible to ping the server every time?
greets,
Kubax
As you haven't provided a licence, by default no-one is allowed to derive from your code here. Was this the intention? If not, could you please provide a licence, as I would like to use some of this code in a project of mine.
I am running the latest docker container. Results come in at right around 150 Mbps download and 35 Mpbs upload. The upload speed is correct, but the download speed should be closer to 800 Mbps.
Running a test via a browser at https://www.spectrum.com/internet/speedtest-only gets about 800 Mbps hitting a server in Olivette, MO.
I have another Windows VM on the same host where the docker container is running. When I do the same speed test in a browser from that VM, I get close to 800 Mbps so I do not think it is a Hyper-V issues.
If I run the speedtest-cli locally on my machine, it gets 800 Mbps download. Guessing this must be a limitation with Docker.
Hi I am a noob and would like you to please guide me on how I can set it up on grafana. I have already got it running and database is installed in grafana but I cannot see any graphs or speed results.
Thank you.
Table is created in Influxdb, but no data is ever written. Tried both the script and the containerized version and neither writes data to Influx. No errors are generated.
Would it be possible to include support for multiple servers in the python script?
This would be useful to test / report against the current ISP server and another remote server?
The container goes on a continuous reboot loop on start.
The influxdb is on a different host than the docker host machine. I have verified the credentials are working, and both hosts are visible to each other.
Error:
speedtest | Loading Configuration File config.ini
speedtest | Configuration Successfully Loaded
speedtest | 2019-09-18 07:09:07,764 - CRITICAL: Failed to connect to InfluxDB for unknown reason
Screenshot:
The config.ini file is as follows
[GENERAL]
Delay = 300
[INFLUXDB]
Address = 10.10.20.11
Port = 8086
Database = speedtests
Username = influxuser
Password = *******
Verify_SSL = False
[SPEEDTEST]
Server =
[LOGGING]
Level = info
Docker Compose:
#Speedtest
speedtest:
container_name: speedtest
hostname: speedtest
restart: unless-stopped
image: barrycarey/speedtest-for-influxdb-and-grafana
volumes:
- /home/shresth/docker/speedtest/config.ini:/src/config.ini
Starting last night I got intermittent errors in the log and as a result, speedtests are not occurring/recorded.
After a few hours, the intermittent nature went away and failure is consistent.
Here is a sample of the log upon startup
Loading Configuration File config.ini
Configuration Successfully Loaded
2021-04-08 15:11:51,512 - INFO: Starting Speed Test For Server None
Traceback (most recent call last):
File "/src/influxspeedtest.py", line 8, in <module>
collector.run()
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 171, in run
self.run_speed_test()
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 119, in run_speed_test
self.setup_speedtest(server)
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 71, in setup_speedtest
self.speedtest = speedtest.Speedtest()
File "/usr/local/lib/python3.7/site-packages/speedtest.py", line 1091, in __init__
self.get_config()
File "/usr/local/lib/python3.7/site-packages/speedtest.py", line 1174, in get_config
map(int, server_config['ignoreids'].split(','))
ValueError: invalid literal for int() with base 10: ''
Loading Configuration File config.ini
Configuration Successfully Loaded
2021-04-08 15:12:52,124 - INFO: Starting Speed Test For Server None
Traceback (most recent call last):
File "/src/influxspeedtest.py", line 8, in <module>
collector.run()
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 171, in run
self.run_speed_test()
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 119, in run_speed_test
self.setup_speedtest(server)
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 71, in setup_speedtest
self.speedtest = speedtest.Speedtest()
File "/usr/local/lib/python3.7/site-packages/speedtest.py", line 1091, in __init__
self.get_config()
File "/usr/local/lib/python3.7/site-packages/speedtest.py", line 1174, in get_config
map(int, server_config['ignoreids'].split(','))
ValueError: invalid literal for int() with base 10: ''
My system re-clones the repos when the computer restarts, and therefore overwrites the config.ini.
Colud you rename the ini in the repo in such a way that it wont overwrite the live config?
I have a server defined in the config.ini but when I run python3 InfluxdbSpeedtest.py it gets stuck at "Picking the closest server".
config.ini
[GENERAL]
Delay = 300
Output = False
[INFLUXDB]
Address = 192.168.x.x
Port = 8086
Database = speedtest
Username = user
Password = user
Verify_SSL = False
[SPEEDTEST]
#Leave blank to auto pick server
Server = 1752
My speedtest script stopped working on 1/26/19 at 22:30 PM CST. Below is the error in the logs when it tries to run, The server filed in my config.ini is blank. I am running telegraf and data from it is still being inserted into influxDB so I do not believe it is a DB problem.
File "/src/influxspeedtest/config/configmanager.py", line 37, in _load_config_values,
self.logging_level = self.config['LOGGING'].get('Level', fallback='debug'),
File "/usr/local/lib/python3.7/configparser.py", line 958, in getitem,
raise KeyError(key),
KeyError: 'LOGGING',
Loading Configuration File config.ini,
Traceback (most recent call last):,
File "/src/influxspeedtest.py", line 3, in ,
from influxspeedtest.InfluxdbSpeedtest import InfluxdbSpeedtest,
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 9, in ,
from influxspeedtest.common import log,
File "/src/influxspeedtest/common/init.py", line 1, in ,
from .utils import log,
File "/src/influxspeedtest/common/utils.py", line 5, in ,
from influxspeedtest.config import config,
File "/src/influxspeedtest/config/init.py", line 10, in ,
config = ConfigManager(config),
File "/src/influxspeedtest/config/configmanager.py", line 19, in init,
self._load_config_values(),
File "/src/influxspeedtest/config/configmanager.py", line 37, in _load_config_values,
self.logging_level = self.config['LOGGING'].get('Level', fallback='debug'),
File "/usr/local/lib/python3.7/configparser.py", line 958, in getitem,
raise KeyError(key),
I was having issues getting the container to start recently and I notice that if one of the servers listed in the config fails to respond it will crash the container. I have two servers listed and only one is responding atm (other is possibly down due to maintenance).
This is my log:
Loading Configuration File config.ini
Configuration Successfully Loaded
2019-01-29 02:33:53,338 - ERROR: No matched servers: [5780]
Traceback (most recent call last):
File "/src/influxspeedtest.py", line 8, in <module>
collector.run()
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 168, in run
self.run_speed_test(server)
File "/src/influxspeedtest/InfluxdbSpeedtest.py", line 125, in run_speed_test
self.speedtest.download()
File "/usr/local/lib/python3.7/site-packages/speedtest.py", line 1449, in download
(os.path.dirname(self.best['url']), size, size))
File "/usr/local/lib/python3.7/site-packages/speedtest.py", line 1045, in best
'get_best_server not called or not able to determine best '
speedtest.SpeedtestMissingBestServer: get_best_server not called or not able to determine best server
Needs to be fixed so it keeps running and just retries the server (either make it retry the next time interval or every X minutes -- possibly make it configurable).
I've set this up yesterday after the fix from #17 came in with the dashboard example json from this repository. But I'm not sure what to make of the results:
I have 300mbps down and 30mbps up and a regular test on speedtest.net seems to confirm that:
Does anyone have an idea what's going on?
Looks like the ping is recorded at 30 minutes when the speed test fails, the time (30 minutes) is the same as the interval between tests which makes me suspect a bug in the ping changes.
2019-02-01 17:10:46,027 - INFO: Waiting 1800 seconds until next test
2019-02-01 17:40:46,127 - INFO: Starting Speed Test For Server None
2019-02-01 17:40:48,170 - INFO: Selected Server 15815 in London
2019-02-01 17:40:48,171 - INFO: Starting download test
2019-02-01 17:40:48,303 - INFO: Starting upload test
2019-02-01 17:40:50,691 - INFO: Download: 0.0Mbps - Upload: 0.0Mbps - Latency: 1800000.0ms
2019-02-01 17:40:50,692 - INFO: Waiting 1800 seconds until next test
Hi There.
Currently the following fields and tags are written to InfluxDB (InfluxdbSpeedtest.py)...
'fields': {
'download': result_dict['download'],
'upload': result_dict['upload'],
'ping': result_dict['server']['latency'],
'server': result_dict['server']['id'],
'server_name': result_dict['server']['name']
},
'tags': {
'server': result_dict['server']['id'],
'server_name': result_dict['server']['name'],
'server_country': result_dict['server']['country']
}
Could these be extended to include the full list as follows (i.e. these are already stored in the results_dict variable just not written to the influxDB)? There's quite a few extra ones here but some are key including "server_sponsor", "server_lat", "server_lon", "server_country" (as field) and the client details also...
Also - It would be good to be able to specify a "host" string (normally defaulted to "local") in the config.ini file which is written to InfluxDB as an additional tag. This way, multiple docker instances can be run with different "host" tags allowing them all to write to the same InfluxDB database/measurement but also able to be filtered by host tag.
'fields': {
'download': result_dict['download'],
'upload': result_dict['upload'],
'ping': result_dict['server']['latency'],
'server': result_dict['server']['id'],
'server_name': result_dict['server']['name'],
'server_url': result_dict['server']['url'],
'server_lat': result_dict['server']['lat'],
'server_lon': result_dict['server']['lon'],
'server_country': result_dict['server']['country'],
'server_cc': result_dict['server']['cc'],
'server_sponsor': result_dict['server']['sponsor'],
'server_id': result_dict['server']['id'],
'server_host': result_dict['server']['host'],
'server_distance': result_dict['server']['d'],
'bytes_sent': result_dict['bytes_sent'],
'bytes_received': result_dict['bytes_received'],
'share': result_dict['share'],
'client_ip': result_dict['client']['ip'],
'client_lat': result_dict['client']['lat'],
'client_lon': result_dict['client']['lon'],
'client_isp': result_dict['client']['isp'],
'client_isprating': result_dict['client']['isprating'],
'client_rating': result_dict['client']['rating'],
'client_ispdlavg': result_dict['client']['ispdlavg'],
'client_ispulavg': result_dict['client']['ispulavg'],
'client_loggedin': result_dict['client']['loggedin'],
'client_country': result_dict['client']['country'],
},
'tags': {
'server': result_dict['server']['id'],
'server_name': result_dict['server']['name'],
'server_country': result_dict['server']['country'],
'host' <---- This would be a static variable that is read from the config.ini file that allows a specific tag to be able to be added to a specific instance (of the docker) so that grafana can be filtered by the host running the container/service
}
Thanks!
I just updated the atribe/Speedtest-for-InfluxDB-and-Grafana image to the latest version and the container restarts because of the following errors immediately after starting the container - This didn't happen with the previous container/image so not sure what has changed here in this latest build?
Loading Configuration File config.ini
Configuration Successfully Loaded
2019-02-11 01:29:55,627 - DEBUG: Testing connection to InfluxDb using provided credentials
There are no other indicators as to why to container dies and it dies that quickly after starting that I can't seem to get into the container to find out why?
PS: I'm running the docker atribe/Speedtest-for-InfluxDB-and-Grafana:latest on Synology
Thanks!
When setting the server in the config it will not find a server with an ID that is on the list here. Specifically trying to use the one with id 3788, any idea why this would be the case? Have confirmed that the server is online
Is there an easy way to use this without it being in a docker container?
I just want like, a cron job to call a python file and have that put data in the directed InfluxDB database.
my influx db is at https://someserver.somedomain.com:8086
, if I use https://someserver.somedomain.com
in the config it comes out as //someserver.somedomain.com
after parsing.
When running the latest docker image the image fails to run completely, this appears in the logs:
Traceback (most recent call last):
File "/src/InfluxdbSpeedtest.py", line 9, in
from influxspeedtest.common import log
ImportError: No module named 'influxspeedtest'
Traceback (most recent call last):
File "/src/InfluxdbSpeedtest.py", line 9, in
from influxspeedtest.common import log
ImportError: No module named 'influxspeedtest'
Traceback (most recent call last):
File "/src/InfluxdbSpeedtest.py", line 9, in
from influxspeedtest.common import log
ImportError: No module named 'influxspeedtest'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.