Forum Discussion

mnagel's avatar
mnagel
Icon for Professor rankProfessor
6 years ago

Ookla Speedtest

After a few failed attempts to get this working on Windows via Powershell (works, but too inaccurate), I punted and used speedtest-cli.  If I can replicate that into Groovy, then perhaps it could be universal, but Linux-only for now.

4CN9AA

This will be held for code review, but it is very simple code :).

6 Replies

Replies have been turned off for this discussion
  • mnagel… would you mind if I took a peek at your powershell?  Second set of eyes and all that.

  • @Cole McDonald Sure, no problem -- see below.  The Ookla one is not much better in reality because the web method is not as accurate as the application socket method, but at least it tried to do bidirectional testing.

    I can't claim credit for this, I found it and modified a bit to work in LM.  I set the mirror site as a property since auto-selection does not work with testmy.net.

    Mark

     

    $size = 50;
    $mirror = "##speedtest.testmy.mirror##";
    if ($site -eq "") {
        $url = "https://testmy.net/dl-${size}MB"
    }
    else {
        $url = "https://${mirror}.testmy.net/dl-${size}MB"
    }
    $path = "Out-Null"
    $WebClient = New-Object System.Net.WebClient 
    $mbps = "{0:N2}" -f (($size/(Measure-Command {$Request=Get-Date; $WebClient.DownloadFile( $url, $path )}).TotalSeconds) * ?
    Write-Host "Mbps="$mbps

  • I wonder if I could dig up some powershell/.net to implement a socket we could push the test through... let me search through my saved favorites, I think I've used something like that to instantiate remote listeners for port route verification... https://stackoverflow.com/questions/29759854/how-to-connect-to-tcp-socket-with-powershell-to-send-and-receive-data

    I'm also testing invoke-webrequest -URI $URL right now as well using the URI from your code against dallas7.  I'll see what it returns and if I can get that parsed to the value you're looking for.

  • $stats = Measure-Command {$return = Invoke-WebRequest -Uri "https://dallas7.testmy.net/dl-10MB"}

    Seems to work to get the same data as the .net web client the other is implementing.  This both implements the download test and retrieves the returned code to be parsed for any tokens that would allow it to perform the push... just have to figure out the request they're building to piece the next URL or REST request together.

  • 1 hour ago, mnagel said:
    
    $size          = 50
    $mirror        = "##speedtest.testmy.mirror##"
    
    if ( $mirror -eq "" ) {
        $url       = "https://testmy.net/dl-${ $size }MB"
    } else {
        $url       = "https://${ mirror }.testmy.net/dl-${ $size }MB"
    }
    
    $timer         = Measure-Command { $response = invoke-webrequest -uri $url }
    $result        = ( $size / ( $timer ).TotalSeconds ) * B
    $mbps          = "{0:N2}" -f ( $result )
    
    Write-Host "Mbps=$mbps"

     

     

    I changed the first If () {} to test the correct variable (was $site, which isn't represented anywhere else in the script).  Then I cleaned the code up a bit and lined everything up... OCD is both great and horrible for programming.