Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with influxdbv2 #11

Open
nodiaque opened this issue Jun 24, 2023 · 4 comments
Open

Incompatible with influxdbv2 #11

nodiaque opened this issue Jun 24, 2023 · 4 comments

Comments

@nodiaque
Copy link

Hello,

Looking at the configuration file, it seems to be only for influxdb 1. Is there a way to update it so it's compatible with influxdb2?

Thank you

@robinmanuelthiel
Copy link
Owner

Sure, would you like to try yourself and send in a Pull Request?

@nodiaque
Copy link
Author

I honestly have no idea how to do any of that. I should learn it, I'm just too lazy

@skoona
Copy link

skoona commented Sep 13, 2023

To support InfluxDB V2, the Environment Vars change and the speedtest.sh script. I have rebuilt my copy using the following:

#!/bin/env sh
# file: speedtest.sh

# These values can be overwritten with env variables
LOOP="${LOOP:-false}"
LOOP_DELAY="${LOOP_DELAY:-300}"
DB_SAVE="${DB_SAVE:-false}"

# These values are all that's required for InfluxDB V2, add/replace in Docker
DB_HOST="${DB_HOST:-http://localhost:8086}"
DB_ADMIN_TOKEN="${DB_ADMIN_TOKEN:-uuid-like-val-from-influxdb2}"
DB_ORG="${DB_ORG:-domain.com}"
DB_BUCKET="${DB_BUCKET:-speedtest}"
	  
run_speedtest()
{
    DATE=$(date +%s)
    HOSTNAME=$(hostname)

    # Start speed test
    echo "Running a Speed Test..."
    JSON=$(./speedtest --accept-license --accept-gdpr -f json)
    DOWNLOAD="$(echo $JSON | jq -r '.download.bandwidth')"
    UPLOAD="$(echo $JSON | jq -r '.upload.bandwidth')"
    PING="$(echo $JSON | jq -r '.ping.latency')"
    echo "Your download speed is $(($DOWNLOAD  / 125000 )) Mbps ($DOWNLOAD Bytes/s)."
    echo "Your upload speed is $(($UPLOAD  / 125000 )) Mbps ($UPLOAD Bytes/s)."
    echo "Your ping is $PING ms."

    # Save results in the database
    if $DB_SAVE; 
    then
		echo " "
        echo "Saving values to database..."
		echo " "
        
	curl -v -s -S POST  "$DB_HOST/api/v2/write?org=$DB_ORG&bucket=$DB_BUCKET&precision=s" \
			--header "Authorization: Token $DB_ADMIN_TOKEN" \
			--header "Content-Type: text/plain; charset=utf-8" \
  		    --header "Accept: application/json" \
            --data-binary "download,host=$HOSTNAME value=$DOWNLOAD $DATE"
		
        curl -s -S  POST  "$DB_HOST/api/v2/write?org=$DB_ORG&bucket=$DB_BUCKET&precision=s" \
			--header "Authorization: Token $DB_ADMIN_TOKEN" \
			--header "Content-Type: text/plain; charset=utf-8" \
  		    --header "Accept: application/json" \
            --data-binary "upload,host=$HOSTNAME value=$UPLOAD $DATE"
		
        curl -s -S  POST  "$DB_HOST/api/v2/write?org=$DB_ORG&bucket=$DB_BUCKET&precision=s" \
			--header "Authorization: Token $DB_ADMIN_TOKEN" \
			--header "Content-Type: text/plain; charset=utf-8" \
  		    --header "Accept: application/json" \
            --data-binary "ping,host=$HOSTNAME value=$PING $DATE"

		echo " "
        echo "Values saved."
    fi
}

if $LOOP;
then
    while :
    do
        run_speedtest
        echo "Running next test in ${LOOP_DELAY}s..."
        echo ""
        sleep $LOOP_DELAY
    done
else
    run_speedtest   
fi

@oharewhy84
Copy link

When running in a docker container using the original Dockerfile I had to make a few changes to the above, but many thanks to @skoona for working on this. Pasting my speedtest.sh incase it helps anyone.

#!/bin/sh
# file: speedtest.sh

# These values can be overwritten with env variables
LOOP="${LOOP:-false}"
LOOP_DELAY="${LOOP_DELAY:-300}"
DB_SAVE="${DB_SAVE:-false}"

# These values are all that's required for InfluxDB V2, add/replace in Docker
DB_HOST="${DB_HOST:-http://localhost:8086}"
DB_ADMIN_TOKEN="${DB_ADMIN_TOKEN:-uuid-like-val-from-influxdb2}"
DB_ORG="${DB_ORG:-domain.com}"
DB_BUCKET="${DB_BUCKET:-speedtest}"
	  
run_speedtest()
{
    DATE=$(date +%s)
    HOSTNAME=$(hostname)

    # Start speed test
    echo "Running a Speed Test..."
    JSON=$(speedtest --accept-license --accept-gdpr -f json)
    DOWNLOAD="$(echo $JSON | jq -r '.download.bandwidth')"
    UPLOAD="$(echo $JSON | jq -r '.upload.bandwidth')"
    PING="$(echo $JSON | jq -r '.ping.latency')"
    echo "Your download speed is $(($DOWNLOAD  / 125000 )) Mbps ($DOWNLOAD Bytes/s)."
    echo "Your upload speed is $(($UPLOAD  / 125000 )) Mbps ($UPLOAD Bytes/s)."
    echo "Your ping is $PING ms."

    # Save results in the database
    if $DB_SAVE; 
    then
		echo " "
        echo "Saving values to database..."
		echo " "
        
	curl -v -s -S --request POST  "$DB_HOST/api/v2/write?org=$DB_ORG&bucket=$DB_BUCKET&precision=s" \
			--header "Authorization: Token $DB_ADMIN_TOKEN" \
			--header "Content-Type: text/plain; charset=utf-8" \
  		    --header "Accept: application/json" \
            --data-binary "download,host=$HOSTNAME value=$DOWNLOAD $DATE"
		
        curl -s -S --request POST  "$DB_HOST/api/v2/write?org=$DB_ORG&bucket=$DB_BUCKET&precision=s" \
			--header "Authorization: Token $DB_ADMIN_TOKEN" \
			--header "Content-Type: text/plain; charset=utf-8" \
  		    --header "Accept: application/json" \
            --data-binary "upload,host=$HOSTNAME value=$UPLOAD $DATE"
		
        curl -s -S --request POST  "$DB_HOST/api/v2/write?org=$DB_ORG&bucket=$DB_BUCKET&precision=s" \
			--header "Authorization: Token $DB_ADMIN_TOKEN" \
			--header "Content-Type: text/plain; charset=utf-8" \
  		    --header "Accept: application/json" \
            --data-binary "ping,host=$HOSTNAME value=$PING $DATE"

		echo " "
        echo "Values saved."
    fi
}

if $LOOP;
then
    while :
    do
        run_speedtest
        echo "Running next test in ${LOOP_DELAY}s..."
        echo ""
        sleep $LOOP_DELAY
    done
else
    run_speedtest   
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants