-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathfile.d.go
108 lines (91 loc) · 3.07 KB
/
file.d.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"os"
"os/signal"
"runtime/debug"
"syscall"
"github.com/alecthomas/kingpin"
"github.com/ozontech/file.d/cfg"
"github.com/ozontech/file.d/fd"
"github.com/ozontech/file.d/logger"
"github.com/ozontech/file.d/longpanic"
"github.com/ozontech/file.d/pipeline"
insaneJSON "github.com/vitkovskii/insane-json"
"go.uber.org/automaxprocs/maxprocs"
_ "github.com/ozontech/file.d/plugin/action/add_host"
_ "github.com/ozontech/file.d/plugin/action/convert_date"
_ "github.com/ozontech/file.d/plugin/action/debug"
_ "github.com/ozontech/file.d/plugin/action/discard"
_ "github.com/ozontech/file.d/plugin/action/flatten"
_ "github.com/ozontech/file.d/plugin/action/join"
_ "github.com/ozontech/file.d/plugin/action/json_decode"
_ "github.com/ozontech/file.d/plugin/action/keep_fields"
_ "github.com/ozontech/file.d/plugin/action/mask"
_ "github.com/ozontech/file.d/plugin/action/modify"
_ "github.com/ozontech/file.d/plugin/action/parse_es"
_ "github.com/ozontech/file.d/plugin/action/parse_re2"
_ "github.com/ozontech/file.d/plugin/action/remove_fields"
_ "github.com/ozontech/file.d/plugin/action/rename"
_ "github.com/ozontech/file.d/plugin/action/throttle"
_ "github.com/ozontech/file.d/plugin/input/dmesg"
_ "github.com/ozontech/file.d/plugin/input/fake"
_ "github.com/ozontech/file.d/plugin/input/file"
_ "github.com/ozontech/file.d/plugin/input/http"
_ "github.com/ozontech/file.d/plugin/input/journalctl"
_ "github.com/ozontech/file.d/plugin/input/k8s"
_ "github.com/ozontech/file.d/plugin/input/kafka"
_ "github.com/ozontech/file.d/plugin/output/devnull"
_ "github.com/ozontech/file.d/plugin/output/elasticsearch"
_ "github.com/ozontech/file.d/plugin/output/file"
_ "github.com/ozontech/file.d/plugin/output/gelf"
_ "github.com/ozontech/file.d/plugin/output/kafka"
_ "github.com/ozontech/file.d/plugin/output/s3"
_ "github.com/ozontech/file.d/plugin/output/splunk"
_ "github.com/ozontech/file.d/plugin/output/stdout"
)
var (
fileD *fd.FileD
exit = make(chan bool)
version = "v0.0.1"
config = kingpin.Flag("config", `config file name`).Required().ExistingFile()
http = kingpin.Flag("http", `http listen addr eg. ":9000", "off" to disable`).Default(":9000").String()
gcPercent = 20
)
func main() {
kingpin.Version(version)
kingpin.Parse()
logger.Infof("hi!")
debug.SetGCPercent(gcPercent)
insaneJSON.DisableBeautifulErrors = true
insaneJSON.StartNodePoolSize = pipeline.DefaultJSONNodePoolSize
_, _ = maxprocs.Set(maxprocs.Logger(logger.Debugf))
go listenSignals()
longpanic.Go(start)
<-exit
logger.Infof("see you soon...")
}
func start() {
cfg := cfg.NewConfigFromFile(*config)
longpanic.SetTimeout(cfg.PanicTimeout)
fileD = fd.New(cfg, *http)
fileD.Start()
}
func listenSignals() {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGHUP, syscall.SIGTERM)
for {
s := <-signalChan
switch s {
case syscall.SIGHUP:
logger.Infof("SIGHUP received")
fileD.Stop()
start()
case syscall.SIGINT:
fallthrough
case syscall.SIGTERM:
logger.Infof("SIGTERM received")
fileD.Stop()
exit <- true
}
}
}