-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.go
77 lines (67 loc) · 1.59 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
// L2met converts a formatted log stream into metrics.
package main
import (
"flag"
"fmt"
"github.com/ryandotsmith/l2met/auth"
"github.com/ryandotsmith/l2met/conf"
"github.com/ryandotsmith/l2met/metchan"
"github.com/ryandotsmith/l2met/outlet"
"github.com/ryandotsmith/l2met/reader"
"github.com/ryandotsmith/l2met/receiver"
"github.com/ryandotsmith/l2met/store"
"log"
"net/http"
"os"
"runtime"
)
// Hold onto the app's global config.
var cfg *conf.D
func init() {
cfg = conf.New()
flag.Parse()
}
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
if cfg.PrintVersion {
fmt.Println(conf.Version)
os.Exit(0)
}
// Can be passed to other modules
// as an internal metrics channel.
mchan := metchan.New(cfg)
mchan.Start()
// The store will be used by receivers and outlets.
var st store.Store
if len(cfg.RedisHost) > 0 {
redisStore := store.NewRedisStore(cfg)
redisStore.Mchan = mchan
st = redisStore
fmt.Printf("at=initialized-redis-store\n")
} else {
st = store.NewMemStore()
fmt.Printf("at=initialized-mem-store\n")
}
if cfg.UseOutlet {
rdr := reader.New(cfg, st)
rdr.Mchan = mchan
outlet := outlet.NewLibratoOutlet(cfg, rdr)
outlet.Mchan = mchan
outlet.Start()
}
if cfg.UsingReciever {
recv := receiver.NewReceiver(cfg, st)
recv.Mchan = mchan
recv.Start()
http.Handle("/logs", recv)
}
http.Handle("/health", st)
http.HandleFunc("/sign", auth.ServeHTTP)
e := http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), nil)
if e != nil {
log.Fatal("Unable to start HTTP server.")
}
fmt.Printf("at=l2met-initialized port=%d\n", cfg.Port)
}