### Installing pro-bing Library in Go Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This command installs the `pro-bing` Go library using `go get`. It fetches the latest version of the library from its GitHub repository, making it available for use in Go projects. This is the primary way to add `pro-bing` as a dependency. ```Bash go get -u github.com/prometheus-community/pro-bing ``` -------------------------------- ### Installing and Running pro-bing Ping Executable in Go Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This snippet shows how to install the native `ping` executable provided by the `pro-bing` project. The first command fetches all packages, including the `cmd/ping` executable, and the second line indicates how to run the installed binary from your `$GOPATH/bin` directory. ```Bash go get -u github.com/prometheus-community/pro-bing/... $GOPATH/bin/ping ``` -------------------------------- ### Emulating UNIX Ping Command with pro-bing Callbacks in Go Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This example demonstrates how to emulate the traditional UNIX `ping` command using `pro-bing`'s callback functions. It sets up handlers for received packets (`OnRecv`), duplicate packets (`OnDuplicateRecv`), and the completion of the ping operation (`OnFinish`). It also includes signal handling to stop the pinger gracefully on Ctrl-C. ```Go pinger, err := probing.NewPinger("www.google.com") if err != nil { panic(err) } // Listen for Ctrl-C. c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { for _ = range c { pinger.Stop() } }() pinger.OnRecv = func(pkt *probing.Packet) { fmt.Printf("%d bytes from %s: icmp_seq=%d time=%v\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt) } pinger.OnDuplicateRecv = func(pkt *probing.Packet) { fmt.Printf("%d bytes from %s: icmp_seq=%d time=%v ttl=%v (DUP!)\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt, pkt.TTL) } pinger.OnFinish = func(stats *probing.Statistics) { fmt.Printf("\n--- %s ping statistics ---\n", stats.Addr) fmt.Printf("%d packets transmitted, %d packets received, %v%% packet loss\n", stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss) fmt.Printf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n", stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt) } fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr()) err = pinger.Run() if err != nil { panic(err) } ``` -------------------------------- ### Development Workflow - Git Bash Source: https://github.com/prometheus-community/pro-bing/blob/main/CONTRIBUTING.md This sequence of commands outlines the typical development workflow: checking out a new branch, running style checks, static analysis, and tests, adding changed files, committing with a sign-off, and pushing the branch to your fork. `` should be a descriptive name for your feature or fix, and `` refers to your remote fork name (e.g., `origin`). ```bash $ git checkout -b # edit files $ make style vet test $ git add $ git commit -s $ git push ``` -------------------------------- ### Performing a Simple Ping with pro-bing in Go Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This snippet demonstrates how to perform a basic ICMP ping operation using the `pro-bing` library. It initializes a new pinger for "www.google.com", sets the packet count to 3, executes the ping, and then retrieves the statistics. This provides a quick way to check network connectivity and latency. ```Go pinger, err := probing.NewPinger("www.google.com") if err != nil { panic(err) } pinger.Count = 3 err = pinger.Run() // Blocks until finished. if err != nil { panic(err) } stats := pinger.Statistics() // get send/receive/duplicate/rtt stats ``` -------------------------------- ### Cloning Forked Repository - Git Bash Source: https://github.com/prometheus-community/pro-bing/blob/main/CONTRIBUTING.md This command clones your forked `pro-bing` repository from GitHub to your local machine and then navigates into the newly created directory. Replace `YOUR_USERNAME` with your actual GitHub username. ```bash git clone https://github.com/YOUR_USERNAME/pro-bing.git && cd pro-bing ``` -------------------------------- ### Initializing HTTP Prober with pro-bing in Go Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This snippet demonstrates how to initialize an HTTPCaller for HTTP probing using the pro-bing Go library. It configures the target URL, call frequency, and an OnResp callback to print the status code and latency. It also shows how to gracefully stop the caller upon receiving a Ctrl-C signal. ```Go httpCaller := probing.NewHttpCaller("https://www.google.com", probing.WithHTTPCallerCallFrequency(time.Second), probing.WithHTTPCallerOnResp(func(suite *probing.TraceSuite, info *probing.HTTPCallInfo) { fmt.Printf("got resp, status code: %d, latency: %s\n", info.StatusCode, suite.GetGeneralEnd().Sub(suite.GetGeneralStart()), ) }), ) // Listen for Ctrl-C. c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { <-c httpCaller.Stop() }() httpCaller.Run() ``` -------------------------------- ### Granting Raw Socket Capability to pro-bing Binary on Linux Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This command uses `setcap` to grant the `CAP_NET_RAW` capability to a compiled binary. This allows the executable to bind to raw sockets, which is necessary if `pinger.SetPrivileged(true)` is used in the `pro-bing` code and the application is not run as root. ```Bash setcap cap_net_raw=+ep /path/to/your/compiled/binary ``` -------------------------------- ### Enabling Unprivileged Ping on Linux for pro-bing Source: https://github.com/prometheus-community/pro-bing/blob/main/README.md This `sysctl` command configures the Linux kernel to allow unprivileged users to perform ICMP echo (ping) operations via UDP sockets. It sets the `net.ipv4.ping_group_range` to permit all user IDs to send pings, which is required for `pro-bing`'s default unprivileged mode on Linux. ```Bash sudo sysctl -w net.ipv4.ping_group_range="0 2147483647" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.