This project is twofold -- periodically test and store internet speed metrics in InfluxDB, and tweet the average measurements out daily. Cron is used to schedule the 2 separate jobs. Specdumb twitter account.
For the speed tests a Python library called speedtest-cli is used to calculate download (Mbit/s), upload (Mbit/s), and ping (ms)
- Python 3.X.X + pip3
- Local InfluxDB
- Twitter dev account
After cloning the repository:
-
Create
config.ini
and add twitter API credentials + Influx client data[twitter] API_KEY = {API_KEY} API_SECRET = {API_SECRET} ACCESS_KEY = {ACCESS_KEY} ACCESS_SECRET = {ACCESS_SECRET} [influxdb] ORG = {INFLUX ORG} HOST = localhost PORT = 8086 USER = {INFLUX USER} TOKEN = {INFLUX TOKEN} BUCKET = internet_speed
-
$ pip3 install requirements.txt
Install Python requirements
-
python3 main.py --speedtest
Executes
speedtest-cli
and storesdownload, upload, ping
data to configured InfluxDB -
python3 main.py --tweet
Queries InfluxDB and tweets the average for each metric (download, upload, ping) for measurements within passed 24 hours
You'll need data throughout the day which is why we'll use cron jobs to run our script every 15 minutes. You can add your own using sudo crontab -e
or run the following command:
> (crontab -u <user> -l; echo "*/15 * * * * python3 /<path/to>/main.py --speedtest" ) | crontab -u <user> -
You can schedule the tweet to be sent at 8 PM using this command:
> (crontab -u <user> -l; echo "0 20 * * * python3 /<path/to>/main.py --tweet" ) | crontab -u <user> -`