gnmyt / myspeed

A speed test analysis software that shows your internet speed for up to 30 days
https://myspeed.dev
MIT License
228 stars 16 forks source link

[Feature] Allow api access to trigger speed tests #722

Closed twistedsanity closed 5 days ago

twistedsanity commented 3 weeks ago

General

Your Idea

My plan would be to disable scheduled speed tests as they can often conflict with high traffic times, and use external monitoring to trigger a test. E.g. I monitor the external interface flow at my firewall and once it drops beneath a set level for more than 'x' seconds trigger a speed test (limited to 1 per hour)

To allow for this I need to be able to disable all speed test schedules, and allow the tests to be triggered remotely. Also if possible I would like the results/stats to be also available via an api to allow for my home automation system to query and display results on screens around the house when needed.

gnmyt commented 3 weeks ago

Hi, thanks for your suggestion. MySpeed already has a simple REST-API you can hook into. You can find a complete collection of API endpoints here on Postman.

In order to do what you described, you need to do the following:

  1. Disable speedtests. You can do this by setting the crontab (Settings > Set frequency > Set manually) to a time that never executes or takes a really long time (e.g. 0 0 1 1 * - once a year)
  2. Trigger a POST request to /api/speedtests/run. This is also documented here

I'm not sure what home automation system you are using but if it can integrate with Prometheus, you can use the Prometheus endpoint (see #687).

If not, you can get the speedtest data as JSON. You can either get it raw in a list, by averages or get the statistics. This returns the same data as seen in the UI.

Hope that helps! :)

twistedsanity commented 3 weeks ago

That really does help, I'm just sorry I didn't find this myself. I'm away at the moment but will try this as soon as I return.

I use 'home assistant' so shouldn't have tookmany issues capturing what I need via either method.

Thanks again for the info and pointers.

twistedsanity commented 5 days ago

Using home assistant I set up the following in yaml and call the service in an automation.

rest_command: run_speed_test: method: post url: "http://host:port/api/speedtests/run"

I am working on pulling results into a dashboard, but that is a lower priority for me.

Many thanks for your help.