From 8a4014f933d2bd752aa29538f983a213b3d8bf4d Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Wed, 3 Aug 2022 13:05:06 +0300 Subject: [PATCH] Initial commit --- .gitignore | 2 + LICENSE | 7 ++ README.md | 62 +++++++++++ config.go | 29 +++++ go.mod | 10 ++ go.sum | 61 ++++++++++ main.go | 92 +++++++++++++++ ping.go | 83 ++++++++++++++ providers.go | 308 +++++++++++++++++++++++++++++++++++++++++++++++++++ type.go | 20 ++++ util.go | 14 +++ 11 files changed, 688 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 config.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 ping.go create mode 100644 providers.go create mode 100644 type.go create mode 100644 util.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d747dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cloudping +*.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..da834b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Nomadic + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e1d4cb4 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# cloudping + +This util performs a ping to measure the network latency from your location to the various cloud data centers around the world. + +### Supported providers + +- Alibaba Cloud +- Amazon Web Services +- Digital Ocean +- Google Cloud Platform +- Hetzner Cloud +- IBM Cloud +- Linode +- Microsoft Azure +- Oracle Cloud +- OVH Cloud +- Scaleway +- Vultr + +## Install + +``` +go install github.com/n0madic/cloudping@latest +``` + +## Usage + +``` +Usage: cloudping [--all] [--count COUNT] [--region REGION] [--location LOCATION] [--provider PROVIDER] [--timeout TIMEOUT] + +Options: + --all, -a Scan all providers + --count COUNT, -c COUNT + Number of pings to send [default: 4] + --region REGION, -r REGION + Filter by regions, can be specified multiple times + --location LOCATION, -l LOCATION + Filter by location, can be specified multiple times + --provider PROVIDER, -p PROVIDER + Choose provider for ping [default: aws] + --timeout TIMEOUT, -t TIMEOUT + Timeout before ping ends [default: 5s] + --help, -h display this help and exit + ``` + + ``` + $ cloudping --provider vultr --region us --region ca ++----+-------+-----------+--------------------+-----------+--------+ +| | CLOUD | REGION | LOCATION | RTT | STATUS | ++----+-------+-----------+--------------------+-----------+--------+ +| 1 | Vultr | nj-us | New Jersey, US | 123.422ms | OK | +| 2 | Vultr | tor-ca | Toronto, CA | 134.604ms | OK | +| 3 | Vultr | ga-us | Atlanta, US | 137.333ms | OK | +| 4 | Vultr | fl-us | Miami, US | 145.317ms | OK | +| 5 | Vultr | il-us | Chicago, US | 149.162ms | OK | +| 6 | Vultr | tx-us | Dallas, US | 161.395ms | OK | +| 7 | Vultr | lax-ca-us | Los Angeles, US | 185.347ms | OK | +| 8 | Vultr | wa-us | Seattle, US | 185.407ms | OK | +| 9 | Vultr | sjo-ca-us | Silicon Valley, US | 185.909ms | OK | +| 10 | Vultr | hon-hi-us | Honolulu, US | 238.706ms | OK | ++----+-------+-----------+--------------------+-----------+--------+ +``` diff --git a/config.go b/config.go new file mode 100644 index 0000000..04e4ea1 --- /dev/null +++ b/config.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "sort" + "time" +) + +type config struct { + All bool `arg:"--all,-a" help:"Scan all providers"` + Count int `arg:"--count,-c" default:"4" help:"Number of pings to send"` + FilterRegion []string `arg:"--region,-r,separate" help:"Filter by regions, can be specified multiple times"` + FilterLocation []string `arg:"--location,-l,separate" help:"Filter by location, can be specified multiple times"` + Provider string `arg:"--provider,-p" default:"aws" help:"Choose provider for ping"` + Timeout time.Duration `arg:"--timeout,-t" default:"5s" help:"Timeout before ping ends"` +} + +func (c *config) Description() string { + keys := make([]string, 0, len(providers)) + for k := range providers { + keys = append(keys, k) + } + sort.Strings(keys) + desc := "Supported providers for cloud ping:\n" + for _, k := range keys { + desc += fmt.Sprintf("%s - %s\n", k, providers[k].name) + } + return desc +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ad0073d --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/n0madic/cloudping + +go 1.16 + +require ( + github.com/alexflint/go-arg v1.4.3 + github.com/go-ping/ping v1.1.0 + github.com/jedib0t/go-pretty/v6 v6.3.6 + github.com/valyala/fasthttp v1.38.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..669a7d6 --- /dev/null +++ b/go.sum @@ -0,0 +1,61 @@ +github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo= +github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA= +github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM= +github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= +github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-ping/ping v1.1.0 h1:3MCGhVX4fyEUuhsfwPrsEdQw6xspHkv5zHsiSoDFZYw= +github.com/go-ping/ping v1.1.0/go.mod h1:xIFjORFzTxqIV/tDVGO4eDy/bLuSyawEeojSm3GfRGk= +github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/jedib0t/go-pretty/v6 v6.3.6 h1:A6w2BuyPMtf7M82BGRBys9bAba2C26ZX9lrlrZ7uH6U= +github.com/jedib0t/go-pretty/v6 v6.3.6/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI= +github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= +github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM= +github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.38.0 h1:yTjSSNjuDi2PPvXY2836bIwLmiTS2T4T9p1coQshpco= +github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs= +golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..bdf243a --- /dev/null +++ b/main.go @@ -0,0 +1,92 @@ +package main + +import ( + "fmt" + "os" + "sort" + "strings" + "sync" + "time" + + "github.com/alexflint/go-arg" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/jedib0t/go-pretty/v6/text" +) + +var ( + args config + wg sync.WaitGroup +) + +func main() { + arg.MustParse(&args) + + for key, provider := range providers { + if args.All || key == args.Provider { + for _, region := range provider.regions { + if (len(args.FilterRegion) > 0 && !isFiltered(region.name, args.FilterRegion)) || + (len(args.FilterLocation) > 0 && !isFiltered(region.location, args.FilterLocation)) { + continue + } + wg.Add(1) + go endpointPing(provider.hostTemplate, region) + } + } + } + wg.Wait() + + results := []*region{} + for key, provider := range providers { + if args.All || key == args.Provider { + for _, region := range provider.regions { + region.code = provider.name + results = append(results, region) + } + } + } + if len(results) == 0 { + fmt.Printf("Provider %s not found\n", args.Provider) + os.Exit(1) + } + sort.Slice(results, func(i, j int) bool { + return results[i].rtt < results[j].rtt + }) + + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.SetAutoIndex(true) + t.AppendHeader(table.Row{"Cloud", "Region", "Location", "RTT", "Status"}) + for _, region := range results { + status := "OK" + if region.err != nil { + status = fmt.Sprintf("ERROR: %s", region.err) + } else if region.rtt == 0 { + continue + } + rtt := region.rtt.Round(time.Microsecond) + if rtt > time.Second { + rtt = rtt.Round(time.Millisecond) + } + t.AppendRow(table.Row{region.code, region.name, region.location, rtt, status}) + } + t.SetColumnConfigs([]table.ColumnConfig{ + { + Name: "Status", + Transformer: text.Transformer(func(val interface{}) string { + color := text.FgGreen + str := val.(string) + if strings.Contains(str, "ERROR") { + color = text.FgRed + } + return color.Sprintf("%s", val) + }), + WidthMax: 55, + }, + }) + if t.Length() > 0 { + t.Render() + } else { + fmt.Println("No results found") + os.Exit(2) + } +} diff --git a/ping.go b/ping.go new file mode 100644 index 0000000..9736a67 --- /dev/null +++ b/ping.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "strings" + "time" + + "github.com/go-ping/ping" + "github.com/valyala/fasthttp" +) + +func endpointPing(template string, region *region) { + defer wg.Done() + + if region.host == "" { + code := region.name + if region.code != "" { + code = region.code + } + region.host = fmt.Sprintf(template, code) + } + + if strings.HasPrefix(region.host, "http") { + var err error + region.rtt, err = httpPing(region.host, args.Count, args.Timeout) + if err != nil { + region.err = err + } + } else { + pinger, err := ping.NewPinger(region.host) + if err != nil { + region.err = err + return + } + defer pinger.Stop() + + pinger.Count = args.Count + pinger.Timeout = args.Timeout + + resolve_count := 0 + for { + err = pinger.Resolve() + if err == nil || resolve_count > 3 { + break + } + resolve_count++ + } + + err = pinger.Run() + if err != nil { + region.err = err + return + } + + region.rtt = pinger.Statistics().AvgRtt + } + + if region.rtt == 0 && region.err == nil { + region.err = fmt.Errorf("timeout") + } +} + +func httpPing(url string, count int, timeout time.Duration) (time.Duration, error) { + var rtt time.Duration + client := fasthttp.Client{ + ReadTimeout: timeout, + } + req := fasthttp.AcquireRequest() + req.SetRequestURI(url) + req.Header.SetMethod(fasthttp.MethodGet) + defer fasthttp.ReleaseRequest(req) + for i := 0; i < count; i++ { + start := time.Now() + resp := fasthttp.AcquireResponse() + err := client.Do(req, resp) + fasthttp.ReleaseResponse(resp) + if err != nil { + return 0, err + } + rtt += time.Since(start) + } + return rtt / time.Duration(count), nil +} diff --git a/providers.go b/providers.go new file mode 100644 index 0000000..6953d19 --- /dev/null +++ b/providers.go @@ -0,0 +1,308 @@ +package main + +import "time" + +var timestamp = time.Now().Format("20060102150405") + +var providers = provider{ + "aws": { + name: "Amazon Web Services", + hostTemplate: "s3.%s.amazonaws.com", + regions: []*region{ + {name: "af-south-1", location: "Cape Town, ZA"}, + {name: "ap-east-1", location: "Hong Kong, CN"}, + {name: "ap-northeast-1", location: "Tokyo, JP"}, + {name: "ap-northeast-2", location: "Seoul, KR"}, + {name: "ap-northeast-3", location: "Osaka, JP"}, + {name: "ap-south-1", location: "Mumbai, IN"}, + {name: "ap-southeast-1", location: "Singapore, SG"}, + {name: "ap-southeast-2", location: "Sydney, AU"}, + {name: "ap-southeast-3", location: "Jakarta, ID"}, + {name: "ca-central-1", location: "Montreal, CA"}, + {name: "eu-central-1", location: "Frankfurt, DE"}, + {name: "eu-north-1", location: "Stockholm, SE"}, + {name: "eu-south-1", location: "Milan, IT"}, + {name: "eu-west-1", location: "Dublin, IE"}, + {name: "eu-west-2", location: "London, UK"}, + {name: "eu-west-3", location: "Paris, FR"}, + {name: "me-south-1", location: "Bahrain, BH"}, + {name: "sa-east-1", location: "Sao Paulo, BR"}, + {name: "us-east-1", location: "North Virginia, US"}, + {name: "us-east-2", location: "Ohio, US"}, + {name: "us-west-1", location: "North California, US"}, + {name: "us-west-2", location: "Oregon, US"}, + }, + }, + "alibaba": { + name: "Alibaba Cloud", + hostTemplate: "oss-%s.aliyuncs.com", + regions: []*region{ + {name: "ap-southeast-1", location: "Singapore, SG"}, + {name: "ap-southeast-2", location: "Sydney, AU"}, + {name: "ap-southeast-3", location: "Kuala Lumpur, MY"}, + {name: "ap-southeast-5", location: "Jakarta, ID"}, + {name: "ap-southeast-6", location: "Manila, PH"}, + {name: "ap-southeast-7", location: "Bangkok, TH"}, + {name: "ap-northeast-1", location: "Tokyo, JP"}, + {name: "ap-northeast-2", location: "Seoul, KR"}, + {name: "ap-south-1", location: "Mumbai, IN"}, + {name: "cn-beijing", location: "Beijing, CN"}, + {name: "cn-chengdu", location: "Chengdu, CN"}, + {name: "cn-guangzhou", location: "Guangzhou, CN"}, + {name: "cn-hangzhou", location: "Hangzhou, CN"}, + {name: "cn-heyuan", location: "Heyuan, CN"}, + {name: "cn-hongkong", location: "Hong Kong, CN"}, + {name: "cn-huhehaote", location: "Huhehaote, CN"}, + {name: "cn-qingdao", location: "Qingdao, CN"}, + {name: "cn-shanghai", location: "Shanghai, CN"}, + {name: "cn-shenzhen", location: "Shenzhen, CN"}, + {name: "cn-wulanchabu", location: "Ulanqab, CN"}, + {name: "cn-zhangjiakou", location: "Zhangjiakou, CN"}, + {name: "eu-central-1", location: "Frankfurt, DE"}, + {name: "eu-west-1", location: "London, UK"}, + {name: "me-east-1", location: "Dubai, AE"}, + {name: "us-east-1", location: "Virginia, US"}, + {name: "us-west-1", location: "California, US"}, + }, + }, + "azure": { + name: "Microsoft Azure", + hostTemplate: "https://av%s.blob.core.windows.net/probe/ping.js?" + timestamp, + regions: []*region{ + {name: "eastasia", location: "Hong Kong, CN"}, + {name: "southeastasia", location: "Singapore, SG"}, + {name: "australiaeast", location: "New South Wales, AU"}, + {name: "australiasoutheast", location: "Victoria, AU"}, + {name: "australiacentral", location: "Canberra, AU"}, + {name: "australiacentral2", location: "Canberra, AU"}, + {name: "centralindia", location: "Pune, IN"}, + {name: "westindia", location: "Mumbai, IN", code: "indiawest9835"}, + {name: "southindia", location: "Chennai, IN"}, + {name: "japaneast", location: "Tokyo, JP"}, + {name: "japanwest", location: "Osaka, JP"}, + {name: "koreacentral", location: "Seoul, KR"}, + {name: "koreasouth", location: "Busan, KR"}, + {name: "northeurope", location: "Dublin, IE"}, + {name: "westeurope", location: "Amsterdam, NL"}, + {name: "francecentral", location: "Paris, FR"}, + {name: "francesouth", location: "Marseille, FR"}, + {name: "ukwest", location: "Cardiff, UK"}, + {name: "uksouth", location: "London, UK"}, + {name: "germanywestcentral", location: "Frankfurt, DE"}, + {name: "germanynorth", location: "Berlin, DE"}, + {name: "eastus", location: "Virginia, US"}, + {name: "eastus2", location: "Virginia, US"}, + {name: "centralus", location: "Iowa, US"}, + {name: "northcentralus", location: "Illinois, US"}, + {name: "southcentralus", location: "Texas, US"}, + {name: "westcentralus", location: "Wyoming, US"}, + {name: "westus", location: "California, US"}, + {name: "westus2", location: "Washington, US"}, + {name: "canadaeast", location: "Quebec City, CA"}, + {name: "canadacentral", location: "Toronto, CA"}, + {name: "brazilsouth", location: "Sao Paulo, BR"}, + {name: "brazilsoutheast", location: "Rio de Janeiro, BR"}, + {name: "southafricanorth", location: "Johannesburg, ZA"}, + {name: "southafricawest", location: "Cape Town, ZA"}, + {name: "norwayeast", location: "Oslo, Norway"}, + {name: "switzerlandwest", location: "Geneva, CH"}, + {name: "switzerlandnorth", location: "Zurich, CH"}, + {name: "uaecentral", location: "Abu Dhabi, AE"}, + {name: "uaenorth", location: "Dubai, AE"}, + }, + }, + "digitalocean": { + name: "Digital Ocean", + hostTemplate: "speedtest-%s.digitalocean.com", + regions: []*region{ + {name: "ams2", location: "Amsterdam, NL"}, + {name: "ams3", location: "Amsterdam, NL"}, + {name: "blr1", location: "Bangalore, IN"}, + {name: "fra1", location: "Frankfurt, DE"}, + {name: "lon1", location: "London, UK"}, + {name: "nyc1", location: "New York, US"}, + {name: "nyc2", location: "New York, US"}, + {name: "nyc3", location: "New York, US"}, + {name: "sfo1", location: "San Francisco, US"}, + {name: "sfo2", location: "San Francisco, US"}, + {name: "sfo3", location: "San Francisco, US"}, + {name: "sgp1", location: "Singapore, SG"}, + {name: "tor1", location: "Toronto, CA"}, + }, + }, + "gcp": { + name: "Google Cloud Platform", + regions: []*region{ + {name: "asia-east1", location: "Changhua County, TW", host: "https://asia-east1-5tkroniexa-de.a.run.app/api/ping"}, + {name: "asia-east2", location: "Hong Kong, CN", host: "https://asia-east2-5tkroniexa-df.a.run.app/api/ping"}, + {name: "asia-northeast1", location: "Tokyo, JP", host: "https://asia-northeast1-5tkroniexa-an.a.run.app/api/ping"}, + {name: "asia-northeast2", location: "Osaka, JP", host: "https://asia-northeast2-5tkroniexa-dt.a.run.app/api/ping"}, + {name: "asia-northeast3", location: "Seoul, KR", host: "https://asia-northeast3-5tkroniexa-du.a.run.app/api/ping"}, + {name: "asia-south1", location: "Mumbai, IN", host: "https://asia-south1-5tkroniexa-el.a.run.app/api/ping"}, + {name: "asia-south2", location: "Delhi, IN", host: "https://asia-south2-5tkroniexa-em.a.run.app/api/ping"}, + {name: "asia-southeast1", location: "Singapore, SG", host: "https://asia-southeast1-5tkroniexa-as.a.run.app/api/ping"}, + {name: "asia-southeast2", location: "Jakarta, ID", host: "https://asia-southeast2-5tkroniexa-et.a.run.app/api/ping"}, + {name: "australia-southeast1", location: "Sydney, AU", host: "https://australia-southeast1-5tkroniexa-ts.a.run.app/api/ping"}, + {name: "australia-southeast2", location: "Melbourne, AU", host: "https://australia-southeast2-5tkroniexa-km.a.run.app/api/ping"}, + {name: "europe-central2", location: "Warsaw, PL", host: "https://europe-central2-5tkroniexa-lm.a.run.app/api/ping"}, + {name: "europe-north1", location: "Hamina, FI", host: "https://europe-north1-5tkroniexa-lz.a.run.app/api/ping"}, + {name: "europe-southwest1", location: "Madrid, ES", host: "https://europe-southwest1-5tkroniexa-no.a.run.app/api/ping"}, + {name: "europe-west1", location: "St. Ghislain, BE", host: "https://europe-west1-5tkroniexa-ew.a.run.app/api/ping"}, + {name: "europe-west2", location: "London, UK", host: "https://europe-west2-5tkroniexa-nw.a.run.app/api/ping"}, + {name: "europe-west3", location: "Frankfurt, DE", host: "https://europe-west3-5tkroniexa-ey.a.run.app/api/ping"}, + {name: "europe-west4", location: "Eemshaven, NL", host: "https://europe-west4-5tkroniexa-ez.a.run.app/api/ping"}, + {name: "europe-west6", location: "Zurich, CH", host: "https://europe-west6-5tkroniexa-oa.a.run.app/api/ping"}, + {name: "europe-west8", location: "Milan, IT", host: "https://europe-west8-5tkroniexa-oc.a.run.app/api/ping"}, + {name: "europe-west9", location: "Paris, FR", host: "https://europe-west9-5tkroniexa-od.a.run.app/api/ping"}, + {name: "northamerica-northeast1", location: "Montreal, CA", host: "https://northamerica-northeast1-5tkroniexa-nn.a.run.app/api/ping"}, + {name: "northamerica-northeast2", location: "Toronto, CA", host: "https://northamerica-northeast2-5tkroniexa-pd.a.run.app/api/ping"}, + {name: "southamerica-east1", location: "Osasco, BR", host: "https://southamerica-east1-5tkroniexa-rj.a.run.app/api/ping"}, + {name: "southamerica-west1", location: "Santiago, CL", host: "https://southamerica-west1-5tkroniexa-tl.a.run.app/api/ping"}, + {name: "us-central1", location: "Council Bluffs, US", host: "https://us-central1-5tkroniexa-uc.a.run.app/api/ping"}, + {name: "us-east1", location: "Moncks Corner, US", host: "https://us-east1-5tkroniexa-ue.a.run.app/api/ping"}, + {name: "us-east4", location: "Ashburn, US", host: "https://us-east4-5tkroniexa-uk.a.run.app/api/ping"}, + {name: "us-east5", location: "Columbus, US", host: "https://us-east5-5tkroniexa-ul.a.run.app/api/ping"}, + {name: "us-south1", location: "Dallas, US", host: "https://us-south1-5tkroniexa-vp.a.run.app/api/ping"}, + {name: "us-west1", location: "The Dalles, US", host: "https://us-west1-5tkroniexa-uw.a.run.app/api/ping"}, + {name: "us-west2", location: "Los Angeles, US", host: "https://us-west2-5tkroniexa-wl.a.run.app/api/ping"}, + {name: "us-west3", location: "Salt Lake City, US", host: "https://us-west3-5tkroniexa-wm.a.run.app/api/ping"}, + {name: "us-west4", location: "Las Vegas, US", host: "https://us-west4-5tkroniexa-wn.a.run.app/api/ping"}, + }, + }, + "hetzner": { + name: "Hetzner Cloud", + hostTemplate: "%s.icmp.hetzner.com", + regions: []*region{ + {name: "ash", location: "Ashburn, US"}, + {name: "fsn", location: "Frankfurt, DE"}, + {name: "hel", location: "Helsinki, FI"}, + {name: "nbg", location: "Nurnberg, DE"}, + }, + }, + "ibm": { + name: "IBM Cloud", + hostTemplate: "s3.%s.cloud-object-storage.appdomain.cloud", + regions: []*region{ + {name: "ams03", location: "Amsterdam, NL"}, + {name: "au-syd", location: "Sydney, AU"}, + {name: "che01", location: "Chennai, IN"}, + {name: "eu-de", location: "Frankfurt, DE"}, + {name: "eu-gb", location: "London, UK"}, + {name: "hkg02", location: "Hong Kong, CN"}, + {name: "jp-osa", location: "Osaka, JP"}, + {name: "jp-tok", location: "Tokyo, JP"}, + {name: "mex01", location: "Mexico City, MX"}, + {name: "mil01", location: "Milan, IT"}, + {name: "mon01", location: "Montreal, CA"}, + {name: "par01", location: "Paris, FR"}, + {name: "sao01", location: "Sao Paulo, BR"}, + {name: "seo01", location: "Seoul, KR"}, + {name: "sjc04", location: "San Jose, US"}, + {name: "sng01", location: "Singapore, SG"}, + {name: "tor01", location: "Toronto, CA"}, + {name: "us-east", location: "Washington, US"}, + {name: "us-south", location: "Dallas, US"}, + }, + }, + "linode": { + name: "Linode", + hostTemplate: "speedtest.%s.linode.com", + regions: []*region{ + {name: "atlanta", location: "Atlanta, US"}, + {name: "dallas", location: "Dallas, US"}, + {name: "fremont", location: "Fremont, US"}, + {name: "frankfurt", location: "Frankfurt, DE"}, + {name: "london", location: "London, UK"}, + {name: "mumbai", location: "Mumbai, IN", code: "mumbai1"}, + {name: "newark", location: "Newark, US"}, + {name: "singapore", location: "Singapore, SG"}, + {name: "sydney", location: "Sydney, AU", code: "syd1"}, + {name: "tokyo", location: "Tokyo, JP", code: "tokyo2"}, + {name: "toronto", location: "Toronto, CA", code: "toronto1"}, + }, + }, + "oracle": { + name: "Oracle Cloud", + hostTemplate: "objectstorage.%s.oraclecloud.com", + regions: []*region{ + {name: "ap-chuncheon-1", location: "Chuncheon, KR"}, + {name: "ap-hyderabad-1", location: "Hyderabad, IN"}, + {name: "ap-melbourne-1", location: "Melbourne, AU"}, + {name: "ap-mumbai-1", location: "Mumbai, IN"}, + {name: "ap-osaka-1", location: "Osaka, JP"}, + {name: "ap-seoul-1", location: "Seoul, KR"}, + {name: "ap-sydney-1", location: "Sydney, AU"}, + {name: "ap-tokyo-1", location: "Tokyo, JP"}, + {name: "ca-montreal-1", location: "Montreal, CA"}, + {name: "ca-toronto-1", location: "Toronto, CA"}, + {name: "eu-amsterdam-1", location: "Amsterdam, NL"}, + {name: "eu-frankfurt-1", location: "Frankfurt, DE"}, + {name: "eu-zurich-1", location: "Zurich, CH"}, + {name: "me-dubai-1", location: "Dubai, AE"}, + {name: "me-jeddah-1", location: "Jeddah, SA"}, + {name: "sa-santiago-1", location: "Santiago, CL"}, + {name: "sa-saopaulo-1", location: "Sao Paulo, BR"}, + {name: "uk-cardiff-1", location: "Newport, UK"}, + {name: "uk-london-1", location: "London, UK"}, + {name: "us-ashburn-1", location: "Ashburn, US"}, + {name: "us-phoenix-1", location: "Phoenix, US"}, + {name: "us-sanjose-1", location: "San Jose, US"}, + }, + }, + "ovh": { + name: "OVH Cloud", + hostTemplate: "s3.%s.cloud.ovh.net", + regions: []*region{ + {name: "bhs", location: "Beauharnois, CA"}, + {name: "de", location: "Franckfurt, DE"}, + {name: "gra", location: "Gravelines, FR"}, + {name: "hil", location: "Hilsboro, US", host: "hil.proof.ovh.us"}, + {name: "sbg", location: "Strasbourg, FR"}, + {name: "sgp", location: "Singapore, SG"}, + {name: "syd", location: "Sidney, AU"}, + {name: "uk", location: "Erith, UK"}, + {name: "vin", location: "Vint Hill, US", host: "vin.proof.ovh.us"}, + {name: "waw", location: "Warsaw, PL"}, + }, + }, + "scaleway": { + name: "Scaleway", + hostTemplate: "s3.%s.scw.cloud", + regions: []*region{ + {name: "fr-par", location: "Paris, FR"}, + {name: "nl-ams", location: "Amsterdam, NL"}, + {name: "pl-waw", location: "Warsaw, PL"}, + }, + }, + "vultr": { + name: "Vultr", + hostTemplate: "%s-ping.vultr.com", + regions: []*region{ + {name: "ams-nl", location: "Amsterdam, NL"}, + {name: "bom-in", location: "Mumbai, IN"}, + {name: "fl-us", location: "Miami, US"}, + {name: "fra-de", location: "Frankfurt, DE"}, + {name: "ga-us", location: "Atlanta, US"}, + {name: "hnd-jp", location: "Tokyo, JP"}, + {name: "hon-hi-us", location: "Honolulu, US"}, + {name: "il-us", location: "Chicago, US"}, + {name: "lax-ca-us", location: "Los Angeles, US"}, + {name: "lon-gb", location: "London, UK"}, + {name: "mad-es", location: "Madrid, ES"}, + {name: "mel-au", location: "Melbourne, AU"}, + {name: "mex-mx", location: "Mexico City, MX"}, + {name: "nj-us", location: "New Jersey, US"}, + {name: "par-fr", location: "Paris, FR"}, + {name: "sao-br", location: "Sao Paulo, BR"}, + {name: "sel-kor", location: "Seoul, KR"}, + {name: "sgp", location: "Singapore, SG"}, + {name: "sjo-ca-us", location: "Silicon Valley, US"}, + {name: "sto-se", location: "Stockholm, SE"}, + {name: "syd-au", location: "Sydney, AU"}, + {name: "tor-ca", location: "Toronto, CA"}, + {name: "tx-us", location: "Dallas, US"}, + {name: "wa-us", location: "Seattle, US"}, + {name: "waw-pl", location: "Warsaw, PL"}, + }, + }, +} diff --git a/type.go b/type.go new file mode 100644 index 0000000..caf4eaa --- /dev/null +++ b/type.go @@ -0,0 +1,20 @@ +package main + +import "time" + +type ( + region struct { + name string + location string + host string + code string + rtt time.Duration + err error + } + + provider map[string]struct { + name string + hostTemplate string + regions []*region + } +) diff --git a/util.go b/util.go new file mode 100644 index 0000000..5afe15c --- /dev/null +++ b/util.go @@ -0,0 +1,14 @@ +package main + +import ( + "strings" +) + +func isFiltered(needle string, filters []string) bool { + for _, filter := range filters { + if strings.Contains(strings.ToLower(needle), strings.ToLower(filter)) { + return true + } + } + return false +}