downtime

package module
v0.0.0-...-ded3fab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 6 Imported by: 0

README

downtime

Measures downtime by detecting the start and end of ICMP request timeouts (like ping -D -W 0.05 -i 0.1 <target>).

The tool needs sudo and the net raw capability to handle raw ICMP pakets:

sudo setcap cap_net_raw+ep <path to binary>

Quick start

  1. install: go install github.com/RaphaelPour/downtime/cmd/downtime
  2. set capability: sudo setcap cap_net_raw+ep <path to binary>
  3. run: sudo downtime --target <target>

example:

   start: 2023-08-16 10:12:47.197488336 +0200 CEST m=+20.651438246
     end: 2023-08-16 10:13:06.331099665 +0200 CEST m=+39.785050063
duration: 19.133611817s

Usage

Usage of downtime:
      --duration duration   ICMP request interval (default 100ms)
      --target ip           target IP
      --timeout duration    ICMP reply timeout (default 50ms)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultICMPInterface ICMP = new(DefaultICMP)
	DefaultIsDownCheck        = IsDownCheck
	DefaultIsUpCheck          = IsUpCheck
	DefaultTimeout            = time.Millisecond * 50
	DefaultInterval           = time.Millisecond * 100
)

Functions

func IsDownCheck

func IsDownCheck(reply icmp.ICMPReturn) bool

func IsUpCheck

func IsUpCheck(reply icmp.ICMPReturn) bool

Types

type DefaultICMP

type DefaultICMP struct{}

func (DefaultICMP) SendICMP

func (d DefaultICMP) SendICMP(
	localAddr string,
	dst net.Addr,
	target string,
	ttl, id int,
	timeout time.Duration,
	seq int,
) (icmp.ICMPReturn, error)

type ICMP

type ICMP interface {
	SendICMP(localAddr string, dst net.Addr, target string, ttl, id int, timeout time.Duration, seq int) (icmp.ICMPReturn, error)
}

type ReplyChecker

type ReplyChecker func(icmp.ICMPReturn) bool

type TimeSpan

type TimeSpan struct {
	Start time.Time
	End   time.Time
}

func (TimeSpan) Duration

func (span TimeSpan) Duration() time.Duration

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher(target net.IP, options ...WatcherOption) Watcher

func (Watcher) Run

func (w Watcher) Run() TimeSpan

func (Watcher) RunWithCheck

func (w Watcher) RunWithCheck(check ReplyChecker) time.Time

type WatcherOption

type WatcherOption func(*Watcher)

func WithInterval

func WithInterval(interval time.Duration) WatcherOption

func WithIsDownCheck

func WithIsDownCheck(check ReplyChecker) WatcherOption

func WithIsUpCheck

func WithIsUpCheck(check ReplyChecker) WatcherOption

func WithTimeout

func WithTimeout(timeout time.Duration) WatcherOption

func WithVerbosity

func WithVerbosity(verbose bool) WatcherOption

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL