Skip to content

Instantly share code, notes, and snippets.

@yzguy
Created March 10, 2020 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yzguy/9ceff32bf5d839cd1fecc9df966f7f64 to your computer and use it in GitHub Desktop.
Save yzguy/9ceff32bf5d839cd1fecc9df966f7f64 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"github.com/sparrc/go-ping"
"github.com/guptarohit/asciigraph"
)
func main() {
endpoints := []string{
"1.1.1.1",
}
data := []float64{}
pinger, err := ping.NewPinger(endpoints[0])
if err != nil {
panic(err)
}
pinger.SetPrivileged(true)
pinger.Count = 100
pinger.Run()
stats := pinger.Statistics()
for _, rtt := range stats.Rtts {
roundTripTime := float64(rtt) / float64(time.Millisecond)
data = append(data, roundTripTime)
}
//fmt.Println(data)
graph := asciigraph.Plot(data)
fmt.Println(graph)
}
yzguy@finack test -> go build . && sudo setcap cap_net_raw=+ep test && ./test
3.45 ┤ ╭╮
2.35 ┤╭──╮ ╭─────╮╭───╮╭─╮╭╮╭╮╭─╮ ╭────╮╭─╮╭╮╭────╮╭╮╭╮ ╭╮╭─╮╭─╮ ╭─╮╭╮╭──╮ ╭╮╭╯╰──╮╭╮ ╭╮ ╭─╮╭╮ ╭╮╭╮
1.25 ┼╯ ╰──╯ ╰╯ ╰╯ ╰╯╰╯╰╯ ╰─╯ ╰╯ ╰╯╰╯ ╰╯╰╯╰─╯╰╯ ╰╯ ╰─╯ ╰╯╰╯ ╰─╯╰╯ ╰╯╰─╯╰─╯ ╰╯╰───╯╰╯╰───
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment