Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Speedtest CLI. Run speedtest on pfSense box

    pfSense Packages
    52
    167
    136.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      doktornotor Banned
      last edited by

      Or just use 2.2.5; python is already there.

      
      $ file /usr/local/bin/python2.7
      /usr/local/bin/python2.7: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 10.1, stripped
      
      
      1 Reply Last reply Reply Quote 0
      • A
        ariyako
        last edited by

        curl -Lo speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest_cli.py
        chmod +x speedtest-cli

        nano speedtest-cli

        change

        #!/usr/bin/env python
        

        to

        #!/usr/local/bin/python2.7
        

        ;)

        1 Reply Last reply Reply Quote 0
        • M
          mdmogren
          last edited by

          Just wanted to post this update here for others who use this tool - it is now a package and can be installed using

          
          pkg install py27-speedtest-cli
          
          

          Then just run

          ./usr/local/bin/speedtest-cli
          
          1 Reply Last reply Reply Quote 0
          • S
            Smoothrunnings
            last edited by

            Is there no GUI version of this?

            My ubnt USG Pro has a speed tester app on it's firewall GUI. I don't see how it's anymore complicated to get one for Pfsense.

            Thanks,

            1 Reply Last reply Reply Quote 0
            • jimpJ
              jimp Rebel Alliance Developer Netgate
              last edited by

              @Smoothrunnings:

              Is there no GUI version of this?

              My ubnt USG Pro has a speed tester app on it's firewall GUI. I don't see how it's anymore complicated to get one for Pfsense.

              Thanks,

              No, because speed testing from the firewall itself is inaccurate and unreliable. We don't want to encourage people to rely on bad data. See my previous response on this thread.

              Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

              Need help fast? Netgate Global Support!

              Do not Chat/PM for help!

              1 Reply Last reply Reply Quote 0
              • A
                authenticx
                last edited by

                Actually this is a good thing to use if you suspect your switch or cabling may be contributing to a loss of bandwidth.  This would narrow the points of failure to your firewall, the connection between your firewall and gateway and the gateway itself.  If you have a large difference between what this cli test reports and what you see in a speed test from your pc you just gained valuable troubleshooting information.

                1 Reply Last reply Reply Quote 1
                • luckman212L
                  luckman212 LAYER 8
                  last edited by

                  I agree. It can have the standard YMMV/caveat attached, but I have gotten a ton of useful information from having the speedtest_cli pkg installed on my remote units. In my testing, a C2xxxx CPU is more than capable of pulling 400-500Mbps directly with this tool. Very useful!

                  1 Reply Last reply Reply Quote 0
                  • I
                    icewraithuk
                    last edited by

                    I use this to keep my ISP honest, which is a trick in itself :) For those that are interested here's my hack:

                    Go to www.thingspeak.com and register for a free account, create a channel with three fields (I only care about ping, DL and UL, you may want more), go to the API page and make a note of your write API.

                    Do the stuff to get speedtest on your firewall, run a speedtest and note which server it decides is your local/fastest - I use the one hosted by my ISP, for example. Then run a speedtest –list | grep <your chosen="" server="" name="">to get the ID (eg. speedtest --list | grep Virgin in my case)

                    Run a speedtest --server <the id="" you="" found="">--csv to test

                    Edit the speedtest.py file and add these bits - note, this isn't clean or clever, I've gone with functional!

                    • Under the other import lines at the top:
                    import urllib2
                    
                    myAPI="<your api="" key="" goes="" here,="" in="" the="" quotes="">"
                    baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
                    print baseURL</your>
                    

                    Then go down to around line 700 and look for the CSV output section, add the lines with -> below

                    def csv(self, delimiter=','):
                            """Return data in CSV format"""
                    
                            data = self.dict()
                            out = StringIO()
                            writer = csv.writer(out, delimiter=delimiter, lineterminator='')
                            row = [data['server']['id'], data['server']['sponsor'],
                                   data['server']['name'], data['timestamp'],
                                   data['server']['d'], data['ping'], data['download'],
                                   data['upload']]
                            writer.writerow([to_utf8(v) for v in row])
                    ->      f = urllib2.urlopen(baseURL + "&field1=%s&field2=%s&field3=%s" % (self.ping, self.download, self.upload))
                    ->      print f.read()
                    ->      f.close ()
                            return out.getvalue()
                    

                    Now run speedtest.py –server 1234 --csv and wait for it to finish, now check on ThingSpeak and check your three fields now have data.

                    I then put the command in my crontab:

                    */30 * * * * /usr/local/bin/python2.7 speedtest.py --server 1234 --csv >/dev/null 2>&1
                    
                    

                    and now every 30 minutes my firewall does a speed test and updates ThingSpeak, which I can check the lovely graphs and make sure I'm relatively consistently getting decent metrics.</the></your>

                    cukalC provelsP K P 4 Replies Last reply Reply Quote 4
                    • S
                      Sergestux
                      last edited by

                      @mdmogren:

                      Just wanted to post this update here for others who use this tool - it is now a package and can be installed using

                      
                      pkg install py27-speedtest-cli
                      
                      

                      Then just run

                      ./usr/local/bin/speedtest-cli
                      

                      Gracias era lo que buscaba

                      1 Reply Last reply Reply Quote 0
                      • cukalC
                        cukal @icewraithuk
                        last edited by

                        @icewraithuk What a great hack & thanks for letting me discover ThingSpeak!

                        I changed the output from bits/sec to Mbit/sec:

                        f = urllib2.urlopen(baseURL + "&field1=%s&field2=%s&field3=%s" % (self.ping, int(self.download) / 1048576, int(self.upload) / 1048576))
                        
                        1 Reply Last reply Reply Quote 2
                        • S
                          S762
                          last edited by

                          Sorry, I know this is an old topic but how to I uninstall this package? I used the following to install but don't see it listed under the package manager and would like to remove it.

                          pkg install py27-speedtest-cli
                          
                          1 Reply Last reply Reply Quote 1
                          • R
                            RaidArray
                            last edited by

                            You should be able to do a "pkg remove <package name>" from the cli via ssh

                            S 1 Reply Last reply Reply Quote 1
                            • S
                              S762 @RaidArray
                              last edited by

                              @raidarray said in Speedtest CLI. Run speedtest on pfSense box:

                              You should be able to do a "pkg remove <package name>" from the cli via ssh

                              Thank you!

                              1 Reply Last reply Reply Quote 0
                              • R
                                RaidArray
                                last edited by RaidArray

                                Hi all

                                Not sure if this is still actively being requested but as a learning exercise for myself i've created a small widget that runs a speedtest from the dashboard happy to share. I'm not really a CLI guy so went down the GUI/Widget route.

                                1 of 2 speed test options

                                Full how to can be found @ https://www.spacejunk-inc.com/pfsense/widget/speedtest/2019/03/10/Speed-Test-Widget.html

                                please let me know what you think, is it useful? how can i improve it?

                                1 Reply Last reply Reply Quote 3
                                • GertjanG
                                  Gertjan
                                  last edited by

                                  Nice !

                                  But keep in mind :

                                  @jimp said in Speedtest CLI. Run speedtest on pfSense box:

                                  No, because speed testing from the firewall itself is inaccurate and unreliable. We don't want to encourage people to rely on bad data. See my previous response on this thread.

                                  @raidarray said in Speedtest CLI. Run speedtest on pfSense box:

                                  how can i improve it?

                                  By adding the option to select the server being used to test ?
                                  Default, speed-test used the closed server on "the list".

                                  No "help me" PM's please. Use the forum, the community will thank you.
                                  Edit : and where are the logs ??

                                  1 Reply Last reply Reply Quote 0
                                  • provelsP
                                    provels @icewraithuk
                                    last edited by provels

                                    @icewraithuk said in Speedtest CLI. Run speedtest on pfSense box:

                                    I use this to keep my ISP honest, which is a trick in itself :) For those that are interested here's my hack:

                                    Very cool. Greetings from the Future!

                                    EDIT - What fun! I was able to combine instructions from both @icewraithuk and @raidarray and throw this chart into the Dashboard using the dark theme. It runs the CLI speedtest against the lowest ping server every 10 minutes, posts to Thingspeak and the Dashboard reads back the Public feed.

                                    Screenshot_1.png

                                    Live Chart

                                    Peder

                                    MAIN - pfSense+ 24.11-RELEASE - Adlink MXE-5401, i7, 16 GB RAM, 64 GB SSD. 500 GB HDD for SyslogNG
                                    BACKUP - pfSense+ 23.01-RELEASE - Hyper-V Virtual Machine, Gen 1, 2 v-CPUs, 3 GB RAM, 8GB VHDX (Dynamic)

                                    0daymaster0 1 Reply Last reply Reply Quote 2
                                    • K
                                      kcallis @icewraithuk
                                      last edited by

                                      @icewraithuk Am I missing something or does one have to have a university or company email account? It definitely did not seem to like the gmail account!

                                      provelsP 1 Reply Last reply Reply Quote 0
                                      • provelsP
                                        provels @kcallis
                                        last edited by provels

                                        @kcallis I just used an Outlook.com account. BTW, the post above from @icewraithuk was posted 2 years ago and it was his only post ever on the forum.

                                        PS - I found a cool chart in the ThingSpeak forums with a chart template that consolidates the CSV data produced by @icewraithuk 's method that I managed to modify to show my upload/download/ping data all in one chart, but you'll need to muddle through the edits manually. There are notes in the .html file that tell you where to put your info. Not saying it's the best data set, but a fun excercise anyway.
                                        https://community.thingspeak.com/forum/announcements/thingspeak-live-chart-multi-channel-second-axis-historical-data-csv-export/

                                        Screenshot_1.png

                                        Peder

                                        MAIN - pfSense+ 24.11-RELEASE - Adlink MXE-5401, i7, 16 GB RAM, 64 GB SSD. 500 GB HDD for SyslogNG
                                        BACKUP - pfSense+ 23.01-RELEASE - Hyper-V Virtual Machine, Gen 1, 2 v-CPUs, 3 GB RAM, 8GB VHDX (Dynamic)

                                        1 Reply Last reply Reply Quote 0
                                        • 0daymaster0
                                          0daymaster @provels
                                          last edited by

                                          @provels That is rad but it seems like running speedtest every ten minutes would be quite a burden on your WAN connection. Can you post the PHP you used for the widget? Thanks.

                                          provelsP 1 Reply Last reply Reply Quote 0
                                          • provelsP
                                            provels @0daymaster
                                            last edited by provels

                                            @0daymaster I run the speedtest every 30 minutes now, but it's just me, so who cares? You pretty much need everything in this thread to do what I did.
                                            1 - Install speedtest-cli on the FW. Run some tests from the shell to get a feel for it.
                                            2 - Setup a Thinkspeak.com account and do the @icewraithuk edits to the speedtest.py file (make @cukal 's edits for Mbps instead of MB if you wish).
                                            3 - Now you should be able to send the data to Thinkspeak to generate the graphs. Format them in the style/colors as you wish. You'll use the
                                            Read API Key to post the data you'll add to the widget.
                                            4 - Then just use @RaidArray 's instruction to add the URL for your chosen Thingspeak graphs and to create the widget you can load from the FW homepage.
                                            5- You can DL the html file from the Thingspeak forum post and edit it in a text editor to make it useful for your data. I didn't incorporate it into the FW homepage, though. I now also use a Windows version of speedtest-cli (Google) running as a scheduled task on an inside server so the tests actually run through the FW rather than from it
                                            All credit goes to everyone else. I just managed to screw some parts together, in spite of myself.

                                            Peder

                                            MAIN - pfSense+ 24.11-RELEASE - Adlink MXE-5401, i7, 16 GB RAM, 64 GB SSD. 500 GB HDD for SyslogNG
                                            BACKUP - pfSense+ 23.01-RELEASE - Hyper-V Virtual Machine, Gen 1, 2 v-CPUs, 3 GB RAM, 8GB VHDX (Dynamic)

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.