This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
84 lines (71 loc) · 2.88 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"
"strings"
"github.com/go-kit/kit/log/level"
"github.com/hostinger/litespeed_exporter/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
// Version set during build
Version string
// Date set during build
Date string
// Revision set during build
Revision string
)
func main() {
var (
exporter = "litespeed_exporter"
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9777").String()
litespeedScrapePattern = kingpin.Flag("litespeed.scrape-pattern", "Pattern of files to scrape LiteSpeed metrics from.").Default("/tmp/lshttpd/.rtreport*").String()
litespeedExcludedMetrics = kingpin.Flag("litespeed.exclude-metrics", "Comma-separated list of metrics to exclude. Available options: ["+collector.LitespeedMetrics.String()+"]").Default("").String()
litespeedReqRatesByHost = kingpin.Flag("litespeed.req-rates-by-host", "Export Request Rates by host.").Bool()
litespeedMetricsByCore = kingpin.Flag("litespeed.metrics-by-core", "Export metrics by core filename.").Bool()
litespeedExcludeExtapp = kingpin.Flag("litespeed.exclude-extapp", "Exclude EXTAPP metrics altogether.").Bool()
)
promlogConfig := &promlog.Config{}
logger := promlog.New(promlogConfig)
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.HelpFlag.Short('h')
kingpin.Version(fmt.Sprintf("%s v%s (%s %s)", exporter, Version, Date, Revision))
kingpin.Parse()
excludedMetricFlags := strings.Split(*litespeedExcludedMetrics, ",")
collector := collector.NewLitespeedCollector(
collector.LitespeedCollectorOpts{
FilePattern: *litespeedScrapePattern,
ReqRatesByHost: *litespeedReqRatesByHost,
MetricsByCore: *litespeedMetricsByCore,
ExcludeExtapp: *litespeedExcludeExtapp,
ExcludedMetrics: collector.ParseFlagsToMap(excludedMetricFlags),
},
logger,
)
prometheus.MustRegister(collector)
level.Info(logger).Log("build", version.Info())
level.Info(logger).Log("address", *listenAddress)
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
<html>
<head><title>LiteSpeed Exporter</title></head>
<body>
<h1>LiteSpeed Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>
`))
})
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
level.Error(logger).Log("msg", "Could not start HTTP server", "err", err)
os.Exit(1)
}
}