-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
84 lines (70 loc) · 2.44 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
package main
import (
"fmt"
"net/http"
"os"
"time"
marathon "github.com/gambol99/go-marathon"
flag "github.com/spf13/pflag"
)
var marathonURI string
var mesosSlavePort int
var appCheckInterval time.Duration
var taskMaxHeartBeatInterval time.Duration
var workDir string
var rsyslogConfigurationDir string
var rsyslogRestartCommand string
var appMonitor AppMonitor
var taskManager TaskManager
var logManager LogManager
func main() {
os.Args[0] = "marathon-logger"
flag.Parse()
client, err := marathonClient(marathonURI)
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
appMonitor = AppMonitor{
Client: client,
CheckInterval: appCheckInterval,
}
appMonitor.Start()
taskManager = TaskManager{
SlavePort: mesosSlavePort,
InputTasksChannel: appMonitor.TasksChannel,
MaxTasksHeartBeatInterval: taskMaxHeartBeatInterval,
}
taskManager.Start()
loggers := make(map[string]Logger)
loggers["rsyslog"] = &Rsyslog{
WorkDir: workDir,
SyslogConfigLocation: rsyslogConfigurationDir,
RestartCommand: rsyslogRestartCommand,
}
logManager = LogManager{
Add: taskManager.AddLogs,
Remove: taskManager.RemoveLogs,
Loggers: loggers,
DefaultLogger: "rsyslog",
}
logManager.Start()
appMonitor.RunWaitGroup.Wait()
}
func init() {
flag.StringVar(&marathonURI, "uri", "", "Marathon URI to connect")
flag.IntVar(&mesosSlavePort, "slave-port", 5051, "Mesos slave port")
flag.DurationVar(&appCheckInterval, "app-check-interval", 30*time.Second, "Frequency at which we check for new tasks")
flag.DurationVar(&taskMaxHeartBeatInterval, "task-max-heart-beat-interval", 30*time.Minute, "Max heartbeat interval after which the task is considered dead and logger is removed")
flag.StringVar(&workDir, "work-dir", "/tmp/", "Location on the Filesystem where we create symlinks to app location base dir. This is needed to ensure the file paths don't become too long and crashes rsyslog")
flag.StringVar(&rsyslogConfigurationDir, "rsyslog-configuration-dir", "/etc/rsyslog.d", "Location on the Filesystem where the rsyslog configurations needs to be written")
flag.StringVar(&rsyslogRestartCommand, "rsyslog-restart-cmd", "service rsyslog restart", "Restart command for rsyslog backend")
}
func marathonClient(uri string) (marathon.Marathon, error) {
config := marathon.NewDefaultConfig()
config.URL = uri
config.HTTPClient = &http.Client{
Timeout: (30 * time.Second),
}
return marathon.NewClient(config)
}