• Stars
    star
    317
  • Rank 131,466 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated 20 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library for creating continuous probers

pro-bing

PkgGoDev Circle CI

A simple but powerful ICMP echo (ping) library for Go, inspired by go-ping & go-fastping.

Here is a very simple example that sends and receives three packets:

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

Here is an example that emulates the traditional UNIX ping command:

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 *ping.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)
}

It sends ICMP Echo Request packet(s) and waits for an Echo Reply in response. If it receives a response, it calls the OnRecv callback unless a packet with that sequence number has already been received, in which case it calls the OnDuplicateRecv callback. When it's finished, it calls the OnFinish callback.

For a full ping example, see cmd/ping/ping.go.

Installation

go get -u github.com/prometheus-community/pro-bing

To install the native Go ping executable:

go get -u github.com/prometheus-community/pro-bing/...
$GOPATH/bin/ping

Supported Operating Systems

Linux

This library attempts to send an "unprivileged" ping via UDP. On Linux, this must be enabled with the following sysctl command:

sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"

If you do not wish to do this, you can call pinger.SetPrivileged(true) in your code and then use setcap on your binary to allow it to bind to raw sockets (or just run it as root):

setcap cap_net_raw=+ep /path/to/your/compiled/binary

See this blog and the Go x/net/icmp package for more details.

This library supports setting the SO_MARK socket option which is equivalent to the -m mark flag in standard ping binaries on linux. Setting this option requires the CAP_NET_ADMIN capability (via setcap or elevated privileges). You can set a mark (ex: 100) with pinger.SetMark(100) in your code.

Setting the "Don't Fragment" bit is supported under Linux which is equivalent to ping -Mdo. You can enable this with pinger.SetDoNotFragment(true).

Windows

You must use pinger.SetPrivileged(true), otherwise you will receive the following error:

socket: The requested protocol has not been configured into the system, or no implementation for it exists.

Despite the method name, this should work without the need to elevate privileges and has been tested on Windows 10. Please note that accessing packet TTL values is not supported due to limitations in the Go x/net/ipv4 and x/net/ipv6 packages.

Plan 9 from Bell Labs

There is no support for Plan 9. This is because the entire x/net/ipv4 and x/net/ipv6 packages are not implemented by the Go programming language.

Maintainers and Getting Help:

This repo was originally in the personal account of sparrc, but is now maintained by the Prometheus Community.

Contributing

Refer to CONTRIBUTING.md

More Repositories

1

helm-charts

Prometheus community Helm charts
Mustache
4,981
star
2

windows_exporter

Prometheus exporter for Windows machines
Go
2,858
star
3

postgres_exporter

A PostgreSQL metric exporter for Prometheus
Go
2,720
star
4

elasticsearch_exporter

Elasticsearch stats exporter for Prometheus
Go
1,910
star
5

PushProx

Proxy to allow Prometheus to scrape through NAT etc.
Go
715
star
6

json_exporter

A prometheus exporter which scrapes remote JSON by JSONPath
Go
631
star
7

node-exporter-textfile-collector-scripts

Scripts for node-exporter's textfile collector
Python
490
star
8

ipmi_exporter

Remote IPMI exporter for Prometheus
Go
459
star
9

avalanche

Prometheus/OpenMetrics endpoint series generator for load testing.
Go
393
star
10

ansible

Ansible Collection for Prometheus
Python
357
star
11

jiralert

JIRA integration for Prometheus Alertmanager
Go
333
star
12

bind_exporter

Prometheus exporter for BIND
Go
299
star
13

smartctl_exporter

Export smartctl statistics to prometheus
Go
289
star
14

systemd_exporter

Exporter for systemd unit metrics
Go
283
star
15

prom-label-proxy

A proxy that enforces a given label in a given PromQL query.
Go
262
star
16

stackdriver_exporter

Google Stackdriver Prometheus exporter
Go
254
star
17

promql-langserver

PromQL language server
Go
176
star
18

prometheus-playground

Turnkey sandbox projects demonstrating a wide variety of Prometheus use cases
Go
164
star
19

pgbouncer_exporter

Prometheus exporter for PgBouncer
Go
138
star
20

ecs_exporter

Prometheus exporter for Amazon Elastic Container Service (ECS)
Go
78
star
21

vscode-promql

This is supposed to become a PromQL extension for vs code.
TypeScript
52
star
22

monaco-promql

PromQL support for the Monaco code editor
TypeScript
31
star
23

community

Prometheus & The Ecosystem Community Meeting Information
20
star
24

prometheus-community

13
star
25

snmp

Tools and configurations for translating SNMP into Prometheus
11
star
26

kitefactory

Makefile
3
star
27

sublimelsp-promql

PromQL support for Sublime LSP plugin, using promql-langserver
Python
2
star