louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
56.81k stars 5.11k forks source link

`iPerf3` / `speedtest` / network speed monitor #744

Open MichelBaie opened 2 years ago

MichelBaie commented 2 years ago

Check every hour a speedtest using iperf. If its lower than xxmbps then down.

markdesilva commented 2 years ago

Speedtest using iperf from where to where? From the UK server to your own server? Not practical if the UK server is not on your own network I think? Especially if the UK server is not on your network (ideal case).

If UK server is on your network, then it can be accomplished by running your iperf in daemon mode on the UK server and then setting up a push monitor for the server you are monitoring to execute iperf client connections to the UK server, scrape the bandwidth from the results and check if its acceptable and if acceptable then notify the UK server via the push URL. Cron this for every hour and set your monitor time to 3600 seconds.

-- On UK server, run iperf in daemon mode --

iperf -D -s -w 64k

-- On server you want to check, create this shell script --

#!/bin/sh

acceptable="900"

mbps=`iperf -c uptime.kuma.server -w 64k -i 1 -t 1 | tail -1 |cut -d" " -f14`

if [ $mbps -ge $acceptable ]; then
   curl -k -s "https:/uptime.kuma.server/api/push/alkdsfjasd?msg=OK&ping=$mbps"
fi

and save it as iperfcheck.sh

Then set your crontab to this

0 * * * * /<path to>/iperfcheck.sh

Replace "https:/uptime.kuma.server/api/push/alkdsfjasd?msg=OK&ping=" with the push URL from your UK monitor push settings and replace the "900" with what ever is your acceptable bandwidth.

deefdragon commented 2 years ago

I think this is too niche, and out of scope for UK itself.

@markdesilva's solution is a good example for odd monitoring situations like these. It may be worth adding it or something similar to the wiki for future reference.

markdesilva commented 2 years ago

@markdesilva's solution is a good example for odd monitoring situations like these. It may be worth adding it or something similar to the wiki for future reference.

Speaking of which. how do I add wiki pages? The wiki says its editable but I don't see how to add to it?

I want to add info on how to do push for odd monitoring situation as mentioned.

louislam commented 2 years ago

@markdesilva's solution is a good example for odd monitoring situations like these. It may be worth adding it or something similar to the wiki for future reference.

Speaking of which. how do I add wiki pages? The wiki says its editable but I don't see how to add to it?

I want to add info on how to do push for odd monitoring situation as mentioned.

I disabled edit for public, as bad guys could able to modify the installation guide and inject some bad things.

It seems that wiki's git repo do not support pull request feature, so I don't have a good approach here now.

markdesilva commented 2 years ago

I disabled edit for public, as bad guys could able to modify the installation guide and inject some bad things.

It seems that wiki's git repo do not support pull request feature, so I don't have a good approach here now.

Thanks Louis. Maybe I will clone the wiki then just submit the examples to you.

MichelBaie commented 2 years ago

Thanks for your script ! It would be interesting to monitor iperf natively, with my server i've specified. If it will not be integrated, you wan close this issue.

chakflying commented 2 years ago

Also agree that this is very niche. Bandwidth is usually strongly correlated with latency anyway. This also depends on you implementing security in your network, like I'm not sure if having a public iperf daemon would invite DOS on your server.

2-click commented 11 months ago

Natively monitoring network and internet speeds would sound awsome.

Prisoner2-6-7 commented 6 months ago

If user wanted to monitor their internet speed then they can fast --upload --json. but they have to install https://github.com/sindresorhus/fast-cli

#!/bin/bash
# Filename: index.sh
PUSH_URL_DOWNLOAD="https://example.com/api/push/key1"
PUSH_URL_UPLOAD="https://example.com/api/push/key2"
INTERVAL=60

while true; do
    json_output=$(fast --upload --json)

    download_speed=$(echo "$json_output" | jq -r '.downloadSpeed')
    curl -k -s  $PUSH_URL_DOWNLOAD/api/push/UOGeajXQqr\?status\=up\&msg\=OK\&ping\=$download_speed
    echo "Pushed the download speed of $download_speed!"

    upload_speed=$(echo "$json_output" | jq -r '.uploadSpeed')
    curl -s -o /dev/null $PUSH_URL_UPLOAD\?status\=up\&msg\=OK\&ping\=$upload_speed    
    echo "Pushed the upload speed of $upload_speed!"

    sleep $INTERVAL
done

edit(CommanderStorm): made sure that the script does conform to the "calling itsself in a loop"-convention from the examples

hadifarnoud commented 3 months ago

iperf check would be awesome and useful. let the user set up iperf server and Uptime Kuma use iperf as client only