This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
61 lines (52 loc) · 2.91 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
package main
import (
"log"
"github.com/dmaes/nomad-logger/fluentbit"
"github.com/dmaes/nomad-logger/nomad"
"github.com/dmaes/nomad-logger/promtail"
"github.com/alexflint/go-arg"
)
var args struct {
NomadAddress string `arg:"--nomad-addr,env:NOMAD_ADDR" default:"http://localhost:4646" help:"The address of the Nomad API"`
NomadAllocsDir string `arg:"--nomad-allocs-dir,env:NOMAD_ALLOCS_DIR" default:"/var/lib/nomad/alloc" help:"The location of the Nomad allocations data. Used to set the path to the logfiles"`
NomadNodeID string `arg:"--nomad-node-id,env:NOMAD_NODE_ID" default:"" help:"The ID of the Nomad node to collect logs for. If empty, we'll suppose this also runs in as a nomad job, and the available env vars will be used to determine the Node ID"`
NomadMetaPrefix string `arg:"--nomad-meta-prefix,env:NOMAD_META_PREFIX" default:"nomad-logger" help:"Consider meta keys that start with '$prefix.'. See log shippers for more info on meta usage."`
ReloadCmd string `arg:"--reload-cmd,env:RELOAD_CMD" default:"" help:"Optional command to execute after logshipper config has changed. Usefull to signal a service to reload it's config. Valid for fluentbit logshipper."`
LogShipper string `arg:"--log-shipper,env:LOG_SHIPPER" default:"promtail" help:"The logshipper to use. Options: fluentbit, promtail"`
FluentbitConfFile string `arg:"--fluentbit-conf-file,env:FLUENTBIT_CONF_FILE" default:"/etc/fluent-bit/nomad.conf" help:"The file in which we can write our input's and stuff. Will be completely overwritten, should be '@INCLUDE'ed from main config file."`
FluentbitTagPrefix string `arg:"--fluentbit-tag-prefix,env:FLUENTBIT_TAG_PREFIX" default:"nomad" help:"Prefix to use for fluentbit tags. Full tag will be '$prefix.$allocId"`
FluentbitParser string `arg:"--fluentbit-parser,env:FLUENTBIT_PARSER" default:"" help:"Parser to apply on every input. Empty string for none"`
PromtailTargetsFile string `arg:"--promtail-targets-file,env:PROMTAIL_TARGETS_FILE" default:"/etc/promtail/nomad.yaml" help:"The promtail file_sd_config file where the generated config can be written. Will be completely overwritten, so don't put anything else there."`
}
func main() {
arg.MustParse(&args)
nomad := &nomad.Nomad{
Address: args.NomadAddress,
AllocsDir: args.NomadAllocsDir,
MetaPrefix: args.NomadMetaPrefix,
}
if args.NomadNodeID != "" {
nomad.NodeID = args.NomadNodeID
} else {
nomad.SetNodeIDFromEnvs()
}
switch args.LogShipper {
case "fluentbit":
fluentbit := &fluentbit.Fluentbit{
Nomad: nomad,
ConfFile: args.FluentbitConfFile,
TagPrefix: args.FluentbitTagPrefix,
Parser: args.FluentbitParser,
ReloadCmd: args.ReloadCmd,
}
fluentbit.Run()
case "promtail":
promtail := &promtail.Promtail{
Nomad: nomad,
TargetsFile: args.PromtailTargetsFile,
}
promtail.Run()
default:
log.Fatalf("Invalid log shipper type '%s'", args.LogShipper)
}
}