speedtest

package
v0.0.0-...-32abf31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2022 License: MIT, MIT Imports: 6 Imported by: 0

README

Speedtest.net Speedtest CLI wrapper package for GoLang

This package requires the appropriate Speedtest CLI binary for your system to function.

Examples

Here's a basic example:

package main

import (
    "fmt"
    "github.com/jrhorner1/ookla-speedtest/pkg/speedtest"
)

func main() {
    retries := 3
    results := speedtest.Run(retries)
    /* the bandwidth results are returned as bytes */
    fmt.Println("Download Speed: ", (results.download.bandwidth * 8)/1000000, "mbps")
    fmt.Println("Upload Speed: ", (results.upload.bandwidth * 8)/1000000, "mbps")
    fmt.Println("Latency: ", results.ping.latency, "ms")
}

Sample output data

This is a sample of the JSON output from the speedtest CLI directly. All of this data is collected for later use in your application.

{
    "type": "result",
    "timestamp": "2020-09-15T22:32:31Z", # RFC3339
    "ping": {
        "jitter": 1.3560000000000001, # milliseconds
        "latency": 9.9130000000000003 # milliseconds
    },
    "download": {
        "bandwidth": 4052019, # bytes per second (Bps)
        "bytes": 34195752,
        "elapsed": 8915 # milliseconds
    },
    "upload": {
        "bandwidth": 1387153, # bytes per second (Bps)
        "bytes": 16350810,
        "elapsed": 10911 # milliseconds
    },
    "packetLoss": 0.69444444444444442,
    "isp": "Example ISP",
    "interface": {
        "internalIp": "192.168.1.100",
        "name": "eth0",
        "macAddr": "FF:FF:FF:FF:FF:FF",
        "isVpn": false,
        "externalIp": "111.1.111.1"
    },
    "server": {
        "id": 00001,
        "host": "speedtest.example.com",
        "port": 8080,
        "name": "Example ISP",
        "location": "Somewhere, DC",
        "country": "United States",
        "ip": "1.111.1.111"
    },
    "result": {
        "id": "f9fcc30a-b2ef-625c-1c0b-957cdef95548",
        "url": "https://www.speedtest.net/result/c/f9fcc30a-b2ef-625c-1c0b-957cdef95548",
        "persisted": true
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Results

type Results struct {
	Type      string
	Timestamp time.Time
	Ping      struct {
		Jitter  float64
		Latency float64
	} `json:"ping"`
	Download struct {
		Bandwidth int
		Bytes     int
		Elapsed   int
	} `json:"download"`
	Upload struct {
		Bandwidth int
		Bytes     int
		Elapsed   int
	} `json:"upload"`
	PacketLoss float64
	Isp        string
	Interface  struct {
		InternalIp string
		Name       string
		MacAddr    string
		IsVpn      bool
		ExternalIp string
	} `json:"interface"`
	Server struct {
		Id       int
		Name     string
		Location string
		Country  string
		Host     string
		Port     int
		Ip       string
	} `json:"server"`
	Result struct {
		Id  string
		Url string
	} `json:"result"`
}

func Run

func Run(retries int) *Results

func RunWithHost

func RunWithHost(host string, retries int) *Results

func RunWithServerId

func RunWithServerId(serverid, retries int) *Results

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL