Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/max-rocket-internet/country-latency-metronomy
Some tools for measuring latency to a country
https://github.com/max-rocket-internet/country-latency-metronomy
Last synced: 21 days ago
JSON representation
Some tools for measuring latency to a country
- Host: GitHub
- URL: https://github.com/max-rocket-internet/country-latency-metronomy
- Owner: max-rocket-internet
- License: gpl-3.0
- Created: 2023-11-02T10:58:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-08T15:00:42.000Z (about 1 year ago)
- Last Synced: 2024-11-12T23:46:12.812Z (3 months ago)
- Language: Go
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# country-latency-metronomy
A golang package for measuring latency to an IP address with a fallback, "best effort" mechanism.
The package is thread safe and includes caching of whois queries so is ideal for running in goroutines for measuring latency to many IP addresses in parallel.
## How it works
The function [GetLatency](pkg/latency/latency.go#L15) will:
1. Use ICMP echo to measure latency to the destination IP
2. If previous step fails:
1. Get country code of the destination IP using [RIPE](https://www.ripe.net/) database (whois)
2. Run a [traceroute](https://en.wikipedia.org/wiki/Traceroute) to the destination IP, record all hops
3. Take latest successful traceroute hop that matches the country code of the destination IP, use this as a substitute destination IP
4. Use ICMP echo to measure latency to substitute destination IPIt will measure:
- Mean Latency
- Median Latency
- P90 Latency
- Packet Loss## CLI tool example
A small example CLI tool is included, [main.go](main.go), to show how the package works:
```console
$ sudo go run main.go -ip-address 82.88.43.13 -debug
DEBU[0000] Ping test successful to '82.88.43.13': 190 avg
DEBU[0000] Starting latancy analysis of '82.88.43.13'Successful: true
Destination: 82.88.43.13
Country code: it
Alternate destination:
Median latency: 185.0ms
```And when the fallback mechanism is used:
```console
$ sudo go run main.go -ip-address 138.120.154.124 -debug
DEBU[0002] Ping failed to '138.120.154.124', no reply
DEBU[0002] Starting traceroute to '138.120.154.124'
DEBU[0026] Traceroute to '138.120.154.124' finished, 16 hops
DEBU[0026] Filtering traceroute results for country code 'us'
DEBU[0026] Found latest good hop '171.102.250.18'
DEBU[0026] Starting latancy analysis of '171.102.250.18'Successful: true
Destination: 138.120.154.124
Country code: us
Alternate destination: 171.102.250.18
Median latency: 200.0ms
```**It is required to run the CLI tool with root permission as it creates raw sockets**
## Package example
```go
package mainimport (
"fmt""github.com/max-rocket-internet/country-latency-metronomy/pkg/latency"
log "github.com/sirupsen/logrus"
)func main() {
log.SetLevel(log.DebugLevel)destination := latency.Destination{Ip: "124.120.154.1"}
result, _ := latency.GetLatency(destination)fmt.Printf("%+v\n", result)
}
```Output:
```console
DEBU[0002] Ping failed to '124.120.154.1', no reply
DEBU[0002] Starting traceroute to '124.120.154.1'
DEBU[0026] Traceroute to '124.120.154.1' finished, 16 hops
DEBU[0026] Filtering traceroute results for country code 'th'
DEBU[0026] Found latest good hop '171.102.249.169'
DEBU[0026] Starting latancy analysis of '171.102.249.169'{Ip:124.120.154.1 CountryCode:th AlternativeIP:171.102.249.169 ErrorMessage: Successful:true Latency:{LatencyMeanMs:214.9 LatencyMedianMs:201 LatencyP90Ms:222 PacketLoss:0}}
```