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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
package main
// This file is part of ifplugo.
//
// ifplugo is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// ifplugo is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ifplugo; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
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 {}
}
|