-
Notifications
You must be signed in to change notification settings - Fork 37
/
artifactory_exporter.go
73 lines (68 loc) · 1.76 KB
/
artifactory_exporter.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
package main
import (
"fmt"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
"github.com/peimanja/artifactory_exporter/collector"
"github.com/peimanja/artifactory_exporter/config"
"github.com/peimanja/artifactory_exporter/logger"
)
func main() {
conf, err := config.NewConfig()
if err != nil {
logger.New(logger.EmptyConfig).Error(
"Error creating the config.",
"err", err.Error(),
)
os.Exit(1)
}
exporter, err := collector.NewExporter(conf)
if err != nil {
conf.Logger.Error(
"Error creating an exporter",
"err", err.Error(),
)
os.Exit(1)
}
prometheus.MustRegister(exporter)
conf.Logger.Info(
"Starting artifactory_exporter",
"version", version.Info(),
)
conf.Logger.Info(
"Build context",
"context", version.BuildContext(),
)
conf.Logger.Info(
"Listening on address",
"address", conf.ListenAddress,
)
http.Handle(conf.MetricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>JFrog Artifactory Exporter</title></head>
<body>
<h1>JFrog Exporter</h1>
<p><a href='` + conf.MetricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
http.HandleFunc("/-/healthy", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "OK")
})
http.HandleFunc("/-/ready", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "OK")
})
if err := http.ListenAndServe(conf.ListenAddress, nil); err != nil {
conf.Logger.Error(
"Error starting HTTP server",
"err", err.Error(),
)
os.Exit(1)
}
}