What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Advanced powershell sensor to get data from speedtest by ookla

Votes:

0

Your Vote:

Up

Down

Here is the script to get data from ookla. Script is running speedtest cli version and generates xml output with four channels as one sensor. You will get Download, Upload, ping and distance to server.

All you need is to get speedtest installed from: https://www.speedtest.net/pl/apps/cli

function Get-Data {
    $result = speedtest --csv --bytes
    return $result
    }


function Parse-Data {
   param(
   [string]$DataString
   ) 
    $csvheader = @('Server ID','Sponsor','Server Name','Timestamp','Distance','Ping','Download','Upload','Share','IP Address')
    $csvunits = @('','','','','km','ms','Mbit/s','Mbit/s','','')

    # $DataString = $result
    $ValueArray = $DataString.split(',')
    $ValueArray[4] = ([math]::Round(([double]($ValueArray[4]) / 1))).tostring()
    $ValueArray[5] = ([math]::Round(([double]($ValueArray[5]) / 1))).tostring()
    $ValueArray[6] = ([math]::Round(([double]($ValueArray[6]) / 1000000))).tostring()
    $ValueArray[7] = ([math]::Round(([double]($ValueArray[7]) / 1000000))).tostring()

    if (($csvheader.count) -eq ($ValueArray.count)) {$max = $csvheader.count}
        $result = for ($i = 0; $i -lt $max; $i++) {
            if ($csvunits[$i]) {
                [PSCustomObject]@{
                channel = $csvheader[$i]
                value   = $ValueArray[$i]
                unit    = $csvunits[$i]
                }
            }
        }
Return $result    
    }

function Get-XML {
   param(
   $Table
   ) 

$prtg = '<?xml version="1.0" encoding="Windows-1252" ?> 
<prtg>'

#$prtg = '<prtg>'

foreach ($row in $Table) { 
    $channel = $row.channel
    $value = $row.value
    $unit = $row.unit
    
    if ($value.Contains('.')) {$float = 1} else {$float = 0}
    if ($channel) {
        $prtg +="
            <result> 
                <channel>$channel</channel>
                <value>$value</value>
                <unit>Custom</unit>
                <customUnit>$unit</customUnit>
                <float>$float</float>
            </result>"
        }
    } 

$prtg +="</prtg>" 
return $prtg 
}


$Speedtest_csv = Get-Data
$Table = Parse-Data $Speedtest_csv
[xml]$xml = Get-XML $Table

write-host ($xml.innerxml)

advanced bandwidth-speed custom-script-exe custom-sensor prtg speedtest

Created on Oct 28, 2020 10:36:05 AM by  solonka (0) 1

Last change on Oct 28, 2020 3:26:43 PM by  Florian Lesage [Paessler Support]



7 Replies

Votes:

0

Your Vote:

Up

Down

Hello,

Thank you very much for providing this script to the community. We always appreciate when users share their scripts to make PRTG better.

Kind regards.

Created on Oct 28, 2020 3:26:09 PM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello,

I checked your Powershell script, it doesn't give any results. I integrated your script in EXEXML in order to run it via "Script / EXE Advanced".

The result is: Non response XML.

From my side, the speedtest.exe file is in a root folder "C: /speedtest/speedtest.exe".

Can you clarify this for me?

Thank you!

Created on Nov 30, 2020 12:16:10 PM by  Mickael DA SILVA (0) 1



Votes:

0

Your Vote:

Up

Down

(Sorry, the result is a french)

When I run the Powershell file on the server that hosts the "speedtest.exe" file, I get several errors.

speedtest : Le terme «speedtest» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est correct et réessayez. Au caractère Ligne:2 : 15 + $result = speedtest --csv --bytes + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (speedtest:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

L'index se trouve en dehors des limites du tableau. Au caractère Ligne:16 : 5 + $ValueArray[4] = ([math]::Round(([double]($ValueArray[4]) / 1))). ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

L'index se trouve en dehors des limites du tableau. Au caractère Ligne:17 : 5 + $ValueArray[5] = ([math]::Round(([double]($ValueArray[5]) / 1))). ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

L'index se trouve en dehors des limites du tableau. Au caractère Ligne:18 : 5 + $ValueArray[6] = ([math]::Round(([double]($ValueArray[6]) / 10000 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

L'index se trouve en dehors des limites du tableau. Au caractère Ligne:19 : 5 + $ValueArray[7] = ([math]::Round(([double]($ValueArray[7]) / 10000 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

In order to fix the problem of the speedtest command "The term" speedtest "is not recognized as the cmdlet name", I modified the result "$ result = C: \ speedtest \ speedtest.exe" and deleted the --csv --bytes options. For other errors, I commented out the following lines:

$ ValueArray [4] = ([math] :: Round (([double] ($ ValueArray [4]) / 1))). Tostring () $ ValueArray [5] = ([math] :: Round (([double] ($ ValueArray [5]) / 1))). Tostring () $ ValueArray [6] = ([math] :: Round (([double] ($ ValueArray [6]) / 1000000))). Tostring () $ ValueArray [7] = ([math] :: Round (([double] ($ ValueArray [7]) / 1000000))). Tostring ()

Created on Nov 30, 2020 12:23:04 PM by  Mickael DA SILVA (0) 1



Votes:

0

Your Vote:

Up

Down

just run in command line: "speedtest --csv --bytes" and paste here your output

Created on Nov 30, 2020 3:02:41 PM by  solonka (0) 1



Votes:

0

Your Vote:

Up

Down

speedtest : Le terme «speedtest» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est correct et réessayez. Au caractère Ligne:1 : 1 + \speedtest --csv --bytes + + CategoryInfo : ObjectNotFound: (\speedtest:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Suggestion [3,General]: La commande speedtest est introuvable, mais elle existe à l''emplacement actuel. Par défaut, Windows PowerShell ne charge aucune commande à partir de l''emplacement actuel. Si vous approuvez cette commande, tapez « .\speedtest » à la place. Pour en savoir plus, voir "get-help about_Command_Precedence".

PS C:\Speedtest> ".
speedtest --csv --bytes"

Impossible de convertir la valeur «"0"» en type «System.Double». Erreur: «Le format de la chaîne d'entrée est
incorrect.»
Au caractère C:\Speedtest\speedtest.ps1:16 : 5
+     $ValueArray[4] = ([math]::Round(([double]($ValueArray[4]) / 1))). ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle

Impossible de convertir la valeur «"59662460"» en type «System.Double». Erreur: «Le format de la chaîne d'entrée est
incorrect.»
Au caractère C:\Speedtest\speedtest.ps1:17 : 5
+     $ValueArray[5] = ([math]::Round(([double]($ValueArray[5]) / 1))). ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle

Impossible de convertir la valeur «"87830622"» en type «System.Double». Erreur: «Le format de la chaîne d'entrée est
incorrect.»
Au caractère C:\Speedtest\speedtest.ps1:18 : 5
+     $ValueArray[6] = ([math]::Round(([double]($ValueArray[6]) / 10000 ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle

Impossible de convertir la valeur «"710486699"» en type «System.Double». Erreur: «Le format de la chaîne d'entrée est
incorrect.»
Au caractère C:\Speedtest\speedtest.ps1:19 : 5
+     $ValueArray[7] = ([math]::Round(([double]($ValueArray[7]) / 10000 ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle

<?xml version="1.0" encoding="Windows-1252"?><prtg><result><channel>Distance</channel><value>"0"</value><unit>Custom</unit><customUnit>km</customUnit><float>0</float></result><result><channel>Ping</channel><value>"84376351"</value><unit>Custom</unit><customUnit>ms</customUnit><float>0</float></result><result><channel>Download</channel><value>"95754090"</value><unit>Custom</unit><customUnit>Mbit/s</customUnit><float>0</float></result><result><channel>Upload</channel><value>"756043964"</value><unit>Custom</unit><customUnit>Mbit/s</customUnit><float>0</float></result></prtg>

I changed the path to "$ result =.
speedtest --csv --bytes", now the query no longer shows an error. I found another one that also worked "$ result = c:\speedtest\speedtest.exe -s" 16676 "-f csv"

But, I did not find a solution for the other errors ...

As well as the following information:

L'index se trouve en dehors des limites du tableau. Au caractère C:\Speedtest\speedtest2.ps1:16 : 5 + $ValueArray[4] = ([math]::Round(([double]($ValueArray[4]) / 0))). ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

L'index se trouve en dehors des limites du tableau. Au caractère C:\Speedtest\speedtest2.ps1:17 : 5 + $ValueArray[5] = ([math]::Round(([double]($ValueArray[5]) / 0))). ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

L'index se trouve en dehors des limites du tableau. Au caractère C:\Speedtest\speedtest2.ps1:18 : 5 + $ValueArray[6] = ([math]::Round(([double]($ValueArray[6]) / 10000 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

L'index se trouve en dehors des limites du tableau. Au caractère C:\Speedtest\speedtest2.ps1:19 : 5 + $ValueArray[7] = ([math]::Round(([double]($ValueArray[7]) / 10000 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException

<?xml version="1.0" encoding="Windows-1252"?><prtg></prtg>

Created on Nov 30, 2020 3:41:37 PM by  Mickael DA SILVA (0) 1

Last change on Dec 1, 2020 7:15:23 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Run following Powershell commands to install speedtest in folder C:\speedtest

$uri = "https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-win64.zip"
$outfile = "ookla-speedtest-1.0.0-win64.zip"
New-Item -Path "c:\" -Name "speedtest" -ItemType "directory" -Force # this will create folder
Invoke-WebRequest -Uri $uri -OutFile "C:\speedtest\$outfile" # this will download file
Expand-Archive -Path $outfile -DestinationPath C:\speedtest #this will unpack archive
cd "C:\speedtest"
#this will run test
speedtest --csv --bytes

You should get output similiar to this:
PS C:\speedtest> speedtest --csv --bytes 7202,Orange Polska S.A.,Poznan,2020-11-30T17:53:34.516251Z,15.717598124341714,12.102,112290119.8598626,13033991.084799679,,85.221.192.228

then put script from 1st post in same folder then try again

Created on Nov 30, 2020 6:02:50 PM by  solonka (0) 1

Last change on Dec 1, 2020 7:16:53 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I couldn't use your script, it didn't work after several modifications. I turned to another script which is located "https://github.com/greiginsydney/New-OoklaSpeedTest.ps1"

This one works perfectly!

Sorry I couldn't get yours to work.

Created on Nov 30, 2020 10:29:36 PM by  Mickael DA SILVA (0) 1



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.