File: main.go

package info (click to toggle)
golang-github-satta-ifplugo 0.0~git20200508.ca679be-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 100 kB
  • sloc: makefile: 5
file content (44 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"flag"
	"fmt"
	"os"
	"strings"
	"time"

	"github.com/satta/ifplugo"
	log "github.com/sirupsen/logrus"
)

func main() {
	deltaValPtr := flag.Int("delta", 0, "number of bytes transferred per polling period to mark interface as seeing traffic")
	pollingPtr := flag.Duration("poll", 2*time.Second, "polling period")
	verbPtr := flag.Bool("verbose", false, "verbose logging")
	flag.Parse()

	if len(flag.Args()) < 1 {
		fmt.Println("Usage: ifplugo-status <iface1,iface2,...>")
		os.Exit(1)
	}
	ifaces := strings.Split(flag.Args()[0], ",")

	if *verbPtr {
		log.SetLevel(log.DebugLevel)
	}

	outchan := make(chan ifplugo.LinkStatusSample)
	mon := ifplugo.MakeLinkStatusMonitor(*pollingPtr, ifaces, outchan)
	if *deltaValPtr > 0 {
		mon.CheckIncomingDelta(true, uint64(*deltaValPtr))
	}
	go func() {
		for v := range outchan {
			for k, v := range v.Ifaces {
				fmt.Printf("%s: %s\n", k, v)
			}
		}
	}()
	mon.Run()
	select {}
}