-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
92 lines (75 loc) · 2.05 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"time"
_ "net/http/pprof"
_ "github.com/q3k/statusz"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"github.com/exaring/openconfig-streaming-telemetry-exporter/pkg/collector"
"github.com/exaring/openconfig-streaming-telemetry-exporter/pkg/config"
"github.com/exaring/openconfig-streaming-telemetry-exporter/pkg/frontend"
)
const version string = "0.0.0"
var (
showVersion = flag.Bool("version", false, "Print version information.")
configFile = flag.String("config.file", "config.yml", "Path to config file")
)
func init() {
flag.Usage = func() {
fmt.Println("Usage: openconfig-streaming-telemetry-exporter [ ... ]\n\nParameters:")
fmt.Println()
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
if *showVersion {
printVersion()
os.Exit(0)
}
cfg, err := loadConfig()
if err != nil {
log.Fatalf("could not load config file. %v", err)
}
col := collector.New(cfg)
for _, target := range cfg.Targets {
go func(target *config.Target) {
t := col.AddTarget(target, cfg.StringValueMapping, true)
conn, err := grpc.Dial(fmt.Sprintf("%s:%d", target.Hostname, target.Port),
grpc.WithInsecure(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: time.Second * time.Duration(target.KeepaliveS),
Timeout: time.Second * time.Duration(target.TimeoutS),
}),
)
if err != nil {
log.Errorf("Unable to dial: %v", err)
return
}
t.Serve(conn)
}(target)
}
fe := frontend.New(cfg, col)
go fe.Start()
select {}
}
func loadConfig() (*config.Config, error) {
log.Infoln("Loading config from", *configFile)
b, err := ioutil.ReadFile(*configFile)
if err != nil {
return nil, err
}
return config.Load(bytes.NewReader(b))
}
func printVersion() {
fmt.Println("openconfig_streaming_telemetry_exporter")
fmt.Printf("Version: %s\n", version)
fmt.Println("Author(s): Annika Wickert, Oliver Herms")
fmt.Println("Metric exporter for switches and routers via openconfig streaming telemetry")
}