Make metrics endpoint configurable

This commit is contained in:
Torjus Håkestad 2025-03-20 18:57:31 +01:00
parent 9b54cec29c
commit ed4d970723
Signed by: torjus
SSH Key Fingerprint: SHA256:KjAds8wHfD2mBYK2H815s/+ABcSdcIHUndwHEdSxml4
3 changed files with 8 additions and 2 deletions

View File

@ -35,6 +35,9 @@ ThrottleSpeed = 10240.0
# Must be either "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "NONE"
# Default: "INFO"
LogLevel = "INFO"
# Enable metrics endpoint
# Default: false
MetricsEnable = false
# Enable access logging
# Default: true
AccessLogEnable = true

View File

@ -34,6 +34,7 @@ type HoneypotConfig struct {
type FrontendConfig struct {
ListenAddr string `toml:"ListenAddr"`
LogLevel string `toml:"LogLevel"`
MetricsEnable bool `toml:"MetricsEnable"`
AccessLogEnable bool `toml:"AccessLogEnable"`
AccessLogIgnoreMetrics bool `toml:"AccessLogIgnoreMetrics"`
Autocert FrontendAutocertConfig `toml:"Autocert"`

View File

@ -86,10 +86,12 @@ func NewServer(cfg config.FrontendConfig, hs *ssh.HoneypotServer, store store.Lo
r.Use(middleware.RealIP)
r.Use(middleware.RequestID)
r.Use(s.LoggingMiddleware)
r.Use(NewMetricsMiddleware())
r.Use(middleware.SetHeader("Server", fmt.Sprintf("apiary/%s", apiary.FullVersion())))
r.Handle("/metrics", promhttp.Handler())
if cfg.MetricsEnable {
r.Use(NewMetricsMiddleware())
r.Handle("/metrics", promhttp.Handler())
}
r.Route("/", func(r chi.Router) {
r.Get("/*", s.IndexHandler("web/vue-frontend/dist"))
r.Get("/stream", s.HandlerAttemptStream)