-
Notifications
You must be signed in to change notification settings - Fork 72
/
main.go
69 lines (57 loc) · 1.49 KB
/
main.go
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
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"fmt"
"log"
"netmon/config"
"netmon/poller"
"os"
"time"
"code.cloudfoundry.org/lager"
"github.com/cloudfoundry/dropsonde"
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"
)
var (
logPrefix = "cfnetworking"
)
func main() {
configFilePath := flag.String("config-file", "", "path to config file")
flag.Parse()
conf, err := config.New(*configFilePath)
if err != nil {
log.Fatalf("%s.netmon: reading config: %s", logPrefix, err)
}
if conf.LogPrefix != "" {
logPrefix = conf.LogPrefix
}
logger := lager.NewLogger(fmt.Sprintf("%s.netmon", logPrefix))
sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), lager.DEBUG)
logger.RegisterSink(sink)
logger.Info("parsed-config", lager.Data{"config": conf})
logLevel, err := conf.ParseLogLevel()
if err != nil {
logger.Fatal("parsing-log-level", err)
}
sink.SetMinLevel(logLevel)
pollInterval := time.Duration(conf.PollInterval) * time.Second
if pollInterval == 0 {
pollInterval = time.Second
}
dropsonde.Initialize(conf.MetronAddress, "netmon")
systemMetrics := &poller.SystemMetrics{
Logger: logger,
PollInterval: pollInterval,
InterfaceName: conf.InterfaceName,
}
members := grouper.Members{
{"metric_poller", systemMetrics},
}
monitor := ifrit.Invoke(sigmon.New(grouper.NewOrdered(os.Interrupt, members)))
logger.Info("starting")
err = <-monitor.Wait()
if err != nil {
logger.Fatal("ifrit monitor", err)
}
}