-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
107 lines (95 loc) · 2.86 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2019 Johannes Kohnen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"net/http"
"os"
"os/signal"
"time"
"github.com/sirupsen/logrus"
"github.com/jwkohnen/prometheus_fileage_exporter/exporter"
)
func main() {
// Prepare logging
log := logrus.New()
log.Out = os.Stderr
cfg := configure(log)
xptr := exporter.NewExporterWithLogger(cfg, log)
srv := exporter.NewDefaultServer(xptr)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
go func() {
defer signal.Stop(sig)
<-sig
_ = srv.Close()
}()
err := srv.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
log.Fatal(err)
}
}
func configure(log *logrus.Logger) *exporter.Config {
config := &exporter.Config{}
flag.StringVar(&config.StartFile, "file-start", "",
"the start file",
)
flag.StringVar(&config.EndFile, "file-end", "",
"the end-file",
)
flag.StringVar(&config.Listen, "listen", ":9104",
"host:port to listen at",
)
flag.StringVar(&config.PromEndpoint, "prom", "/metrics",
"publish prometheus metrics on this URL endpoint",
)
flag.StringVar(&config.HealthEndpoint, "health", "/healthz",
"publish health status on this URL endpoint",
)
flag.StringVar(&config.LivenessEndpoint, "liveness", "/liveness",
"publish liveness status on this URL endpoint",
)
flag.StringVar(&config.Namespace, "namespace", "",
"prometheus namespace",
)
flag.StringVar(&config.Subsystem, "subsystem", "",
"prometheus subsystem",
)
flag.DurationVar(&config.HealthTimeout, "health-timeout", 10*time.Minute,
"when should the service be considered unhealthy",
)
flag.DurationVar(&config.LivenessTimeout, "liveness-timeout", 10*time.Minute,
"when should the service be considered un-live",
)
flag.DurationVar(&config.Welpenschutz, "health-welpenschutz", 10*time.Minute,
"how long initially the service is considered healthy.",
)
flag.DurationVar(&config.DirectoryTimeout, "directory-timeout", 10*time.Minute,
"how long to wait for missing directories",
)
flag.BoolVar(&config.Debug, "debug", true,
"enable debug logging (enabled by default)",
)
flag.BoolVar(&config.LogJSON, "log-json", false,
"enable JSON-formatted logging",
)
flag.Parse()
if config.LogJSON {
log.Formatter = new(logrus.JSONFormatter)
}
if flag.NArg() != 0 {
log.Fatalf("Superfluous arguments: %v", flag.Args())
}
return config
}