-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.go
86 lines (72 loc) · 1.92 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
85
86
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/google/subcommands"
"github.com/itzg/go-flagsfiller"
"github.com/itzg/mc-monitor/otel"
"github.com/itzg/zapconfigs"
"go.uber.org/zap"
)
var (
version = ""
commit = ""
date = ""
)
func main() {
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(subcommands.FlagsCommand(), "")
subcommands.Register(&versionCmd{}, "")
subcommands.Register(&statusCmd{}, "status")
subcommands.Register(&statusBedrockCmd{}, "status")
subcommands.Register(&gatherTelegrafCmd{}, "monitoring")
subcommands.Register(&exportPrometheusCmd{}, "monitoring")
subcommands.Register(&otel.CollectOpenTelemetryCmd{}, "monitoring")
var config GlobalConfig
err := flagsfiller.Parse(&config, flagsfiller.WithEnv(""))
if err != nil {
log.Fatal(err)
}
var logger *zap.Logger
if config.Debug {
zapConfig := zap.Config{
Encoding: "console",
EncoderConfig: zapconfigs.NewDebugEncoderConfig(),
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
// output to stderr so that scripts grabbing output don't get logs
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
var err error
logger, err = zapConfig.Build()
if err != nil {
log.Fatal(err)
}
} else {
logger = zapconfigs.NewDefaultLogger()
}
defer logger.Sync()
os.Exit(int(subcommands.Execute(context.Background(), logger)))
}
type GlobalConfig struct {
Debug bool `usage:"enable debug logging"`
}
type versionCmd struct{}
func (c *versionCmd) Name() string {
return "version"
}
func (c *versionCmd) Synopsis() string {
return "Show version and exit"
}
func (c *versionCmd) Usage() string {
return ""
}
func (c *versionCmd) SetFlags(*flag.FlagSet) {
}
func (c *versionCmd) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus {
fmt.Printf("%s commit=%s date=%s\n", version, commit, date)
return subcommands.ExitSuccess
}