Git Product home page Git Product logo

my-internet-speed's Introduction

Tests Coverage Maintainability

My Internet Speed

I wrote this app so I can periodically monitor my internet speed and:

  • Collect data to build a report about the quality of the service provided by my ISP
  • Automatically tweet my ISP when the speed is lower than expected โ€“ surely optional
  • Store speed test results in PostgreSQL
  • Check all speed test results in a web API
  • Monitor all speed test tasks

At home this runs on my Raspberry Pi, but not all services are compatible โ€” check my ideal setup for a suggestion on how to run these services.

Installing

Requirements

It is important to run this app in a computer connected to the internet via ethernet cable, not via wireless โ€“ this is the way to have some accuracy in testing the speed.

Optionally, if you want the Twitter feature to work (it will only tweet when the speed is below the configures threshold):

  • Twitter consumer key and secret
  • Twitter access token and access token secret

You can get these Twitter credentials at the Twitter Application Management dashboard.

Some speed test backends do not provide a URL with the results. In these cases we take a screenshot from the speed test result and upload it to Imgur. If you want to use this feature, you need an account there and a client ID for a registered application.

Settings

Before you get started, copy .env.sample as .env and edit as follows:

  1. Set INTERVAL according to how often (in minutes) you want to run the speed test (e.g.: 20 for 20min)
  2. Set your TIMEZONE accordingly

The default speed test backend is SpeedTest but you can use EAQ (Entidade Aferidora da Qualidade de Banda Larga) certified by ANATEL setting BACKEND to brasil_banda_larga.

If you want the app to post tweets:

  1. Add your Twitter credentials at the top of the file
  2. Set CONTRACT_SPEED to the speed in Mbps you are paying for (e.g.: 60 if you contract says 60Mbps)
  3. Set THRESHOLD to the minimum percentage of the contract speed you contract or local laws enforces your ISP (e.g.: 0.4 for 40%)
  4. Set your tweet message using {contract_speed} where the contract speed in Mbps should be (for example, 60 for 60Mbps), {real_speed} where the measured speed should be, and {percentage} where comparing both should be (feel free to use the Twitter handle of your ISP too)
  5. Add {result_url} in order to add the link to the result provided by the speed test backend

For example, if:

  • the measured speed is 20Mpbs
  • your CONTRACT_SPEED is 60
  • the THRESHOLD is 0.4
  • and TWEET is configures as I pay for {contract_speed}, but now @MyISP is working at {real_speed} โ€“ merely {percentage} of what I'm paying for :( {result_url}

The final tweet would be:

I pay for 60Mbps, but now @MyISP is working at 20Mbps โ€“ merely 33% of what I'm paing for :( http://www.speedtest.net/result/7307126311

If you like this app, add #MyInternetSpeed https://github.com/cuducos/my-internet-speed to your tweets ; )

Database

This docker-compose.yml lefts out the db container from all possible depends_on in order to make it easier to use an external/remote database to persist data (just point POSTGRESs variables and the PGRST ones to somewhere else).

Thus if you are using the Docker database it is useful to start it manually first:

$ docker-compose up -d db

In both cases run this one off command to create the database tables:

$ docker-compose run --rm beat python \
  -c "from my_internet_speed.models import Result; Result.create_table()"

Spinning up the app

$ docker-compose up -d

Services and compatibility

Containers

This spins up different services that might be useful to check the status of the speed tests:

Name URL ARM (RaspberryPi) compatibility Description
beat โœ… Main app that periodically runs the speed tests
dashboard http://localhost:3000/ ๐Ÿšซ Minimalist dashboard with monthly speed test results
api http://localhost:3001/result/ ๐Ÿšซ API to the database with all speed test results (check Postgrest for advanced filtering and exporting formats)
flower http://localhost:5555/ โœ… Flower dashboard for asynchronous tasks
db โœ… Database to store the speed test results
broker โœ… Queue to run the speed tests
chrome ๐Ÿšซ Selenium web driver used for backends that requires a browser
Backends
Name Python path ARM (RaspberryPi) compatibility
SpeedTest my_internet_speed.backends.speed_test_net.SpeedTest โœ…
Barsil Banda Larga my_internet_speed.backends.brasil_banda_larga.SpeedTest ๐Ÿšซ

My ideal setup

Given the ARM processor incompatibilities, I actually use three computers to run these services:

  1. In my RaspberryPi (ARM processor, but it is still the only device with ethernet cable I have) I run beat, broker and flower:
    $ docker-compose up -d beat flower
  2. In my main computer (x86 processor) I run the api and the dashboard so I can check the results:
    $ docker-compose up -d beat dashboard
  3. The database I run in the cloud, a free tier at tiny turtle (free) at ElephantSQL

Troubleshooting

UnixHTTPConnectionPool(host='localhost', port=None): Read timed out.

I was getting this error in my Raspberry Pi when trying to run docker-compose up. This seams to be a workaround:

$ export DOCKER_CLIENT_TIMEOUT=600
$ export COMPOSE_HTTP_TIMEOUT=600

Testing

$ docker-compose run --rm beat py.test

Also we use Black code formatter:

$ docker-compose run --rm beat black . --check

my-internet-speed's People

Contributors

cuducos avatar dependabot[bot] avatar lipemorais avatar nicolastarzia avatar vmesel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

my-internet-speed's Issues

FailedConnectionException2 "github.com" 443 True getProtocolByName: does not exist (no such protocol name: tcp)

After run docker-compose up -d elm package manager is not able to download the package "cuducos/elm-format-number": "6.0.0 <= v < 7.0.0".

โžœ  my-internet-speed git:(master) docker-compose up -d
Building dashboard
Step 1/5 : FROM node:9.11.1-slim
 ---> 175a853f7bb2
Step 2/5 : WORKDIR /code
 ---> Using cache
 ---> 4ccafc0c8680
Step 3/5 : COPY elm-package.json .
 ---> Using cache
 ---> c033f836e391
Step 4/5 : RUN npm install -g npm@latest &&     npm install -g --unsafe-perm [email protected] &&     npm install -g --unsafe-perm [email protected] &&     elm package install --yes
 ---> Running in a6cf00605d9a
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
added 247 packages, removed 41 packages and updated 129 packages in 82.702s
npm WARN deprecated [email protected]: Use uuid module instead
/usr/local/bin/elm -> /usr/local/lib/node_modules/elm/binwrappers/elm
/usr/local/bin/elm-make -> /usr/local/lib/node_modules/elm/binwrappers/elm-make
/usr/local/bin/elm-package -> /usr/local/lib/node_modules/elm/binwrappers/elm-package
/usr/local/bin/elm-reactor -> /usr/local/lib/node_modules/elm/binwrappers/elm-reactor
/usr/local/bin/elm-repl -> /usr/local/lib/node_modules/elm/binwrappers/elm-repl

> [email protected] install /usr/local/lib/node_modules/elm
> node install.js

Downloading Elm binaries from https://dl.bintray.com/elmlang/elm-platform/0.18.0/linux-x64.tar.gz
+ [email protected]
added 94 packages from 69 contributors in 15.664s
npm WARN deprecated [email protected]: Use uuid module instead
/usr/local/bin/elm-app -> /usr/local/lib/node_modules/create-elm-app/bin/elm-app-cli.js
/usr/local/bin/create-elm-app -> /usr/local/lib/node_modules/create-elm-app/bin/create-elm-app-cli.js

> [email protected] install /usr/local/lib/node_modules/create-elm-app/node_modules/elm
> node install.js

Downloading Elm binaries from https://dl.bintray.com/elmlang/elm-platform/0.18.0/linux-x64.tar.gz

> [email protected] install /usr/local/lib/node_modules/create-elm-app/node_modules/elm-test
> node install.js

Downloading binaries from https://dl.bintray.com/elmlang/elm-test/0.18.12/linux-x64.tar.gz
Successfully downloaded and processed https://dl.bintray.com/elmlang/elm-test/0.18.12/linux-x64.tar.gz

> [email protected] postinstall /usr/local/lib/node_modules/create-elm-app/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js

npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/create-elm-app/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/create-elm-app/node_modules/elm-test/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ [email protected]
added 1302 packages from 733 contributors in 88.077s
Error: The following HTTP request failed.
<https://github.com/cuducos/elm-format-number/zipball/6.0.Starting downloads...

  โœ— debois/elm-dom 1.2.3
  โœ— elm-lang/html 2.0.0
  โœ— cuducos/elm-format-number 6.0.0
  โœ— elm-lang/core 5.1.1
  โœ— elm-lang/svg 2.0.0
  โœ— elm-lang/http 1.0.0
  โœ— elm-lang/virtual-dom 2.0.4
  โœ— eskimoblood/elm-color-extra 5.1.0
  โœ— justinmimbs/elm-date-extra 2.1.1
  โœ— mgold/elm-date-format 1.6.0
  โœ— fredcy/elm-parseint 2.0.0
  โœ— myrho/elm-round 1.0.2
  โœ— terezka/line-charts 1.0.0
0/>

FailedConnectionException2 "github.com" 443 True getProtocolByName: does not exist (no such protocol name: tcp)

ERROR: Service 'dashboard' failed to build: The command '/bin/sh -c npm install -g npm@latest &&     npm install -g --unsafe-perm [email protected] &&     npm install -g --unsafe-perm [email protected] &&     elm package install --yes' returned a non-zero code: 1

Problem with Elm in Raspberry Pi

The dashboard container doesn't build on Raspberry Pi.

See the log bellow:

    > node install.js

    Unfortunately, there are currently no Elm Platform binaries available for your operating system and architecture.

    If you would like to build Elm from source, there are instructions at https://github.com/elm-lang/elm-platform#build-from-source

    npm WARN This failure might be due to the use of legacy binary "node"
    npm WARN For further explanations, please read
    /usr/share/doc/nodejs/README.Debian

I saw that Daniel had this problem too, dev.to.

Problem with API container

When I try to execute docker-compose up -d, on my raspberry pi, the API container exit with the error:

standard_init_linux.go:190: exec user process caused "exec format error"

I think it's a problem with postgrest/postgrest image, because it is another architecture.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.