forked from ashwinikd/json-log-exporter
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
50 lines (40 loc) · 1.08 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
package main
import (
"flag"
"github.com/ashwinikd/json-log-exporter/collector"
"github.com/ashwinikd/json-log-exporter/config"
"log"
"net"
"net/http"
)
var (
bind, configFile string
)
func main() {
flag.StringVar(&bind, "web.listen-address", ":9321", "Address to listen on for the web interface.")
flag.StringVar(&configFile, "config-file", "json_log_exporter.yml", "Configuration file.")
flag.Parse()
cfg, err := config.LoadFile(configFile)
if err != nil {
log.Fatal(err)
}
collector.InitializeExports(cfg.Exports)
for _, logGroup := range cfg.LogGroups {
log.Printf("Initializing log group '%s'\n", logGroup.Name)
logGroup := collector.NewCollector(&logGroup, cfg.Namespace)
logGroup.Run()
}
for _, export := range cfg.Exports {
log.Printf("Exposing '%s'\n", export.MetricPath)
http.Handle(export.MetricPath, collector.GetExport(export.Name).Handler)
}
l, err := net.Listen("tcp", bind)
if err != nil {
log.Fatal(err)
}
log.Printf("HTTP server listening on %s", bind)
if err := http.Serve(l, nil); err != nil {
log.Fatal(err)
log.Fatal(l.Close())
}
}