Rename config.yaml to example and add config.yaml to gitignore, make Metrics optional and configurable

This commit is contained in:
Pablu23
2025-10-15 13:15:56 +02:00
parent 28d9c58a66
commit f4ca559a26
5 changed files with 79 additions and 77 deletions

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@
bin/ bin/
data.json data.json
*.json *.json
config.yaml

View File

@@ -61,11 +61,11 @@ func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done()
<-sigs <-sigs
log.Info().Msg("Stopping server") log.Info().Msg("Stopping server")
server.Shutdown(context.Background()) server.Shutdown(context.Background())
pipeline.Stop() pipeline.Stop()
wg.Done()
}() }()
if config.Server.Ssl.Enabled { if config.Server.Ssl.Enabled {
@@ -127,8 +127,14 @@ func configureMiddleware(config *domainrouter.Config) *middleware.Pipeline {
pipeline.AddMiddleware(&middleware.RequestLogger{}) pipeline.AddMiddleware(&middleware.RequestLogger{})
} }
metrics := middleware.NewMetrics(512, 1*time.Minute, "tmp_metrics.json") if config.Metrics.Enabled {
flushInterval, err := time.ParseDuration(config.Metrics.FlushInterval)
if err != nil {
log.Fatal().Err(err).Str("flush_interval", config.Metrics.FlushInterval).Msg("Could not parse FlushInterval")
}
metrics := middleware.NewMetrics(config.Metrics.BufferSize, flushInterval, config.Metrics.File)
pipeline.AddMiddleware(metrics) pipeline.AddMiddleware(metrics)
}
return pipeline return pipeline
} }

View File

@@ -43,4 +43,10 @@ type Config struct {
MaxBackups int `yamls:"maxBackups"` MaxBackups int `yamls:"maxBackups"`
} `yaml:"file"` } `yaml:"file"`
} `yaml:"logging"` } `yaml:"logging"`
Metrics struct {
Enabled bool `yaml:"enabled"`
File string `yaml:"file"`
BufferSize int `yaml:"bufferSize"`
FlushInterval string `yaml:"flushInterval"`
} `yaml:"metrics"`
} }

View File

@@ -1,21 +1,20 @@
server: server:
port: 443 port: 80
ssl: ssl:
enabled: true enabled: false
certFile: server.crt certFile: server.crt
keyFile: server.key keyFile: server.key
acme: acme:
enabled: false enabled: false
email: me@pablu.de email: user@host.dev
keyFile: userKey.key keyFile: userKey.key
caDirUrl: https://192.168.2.154:14000/dir caDirUrl: https://localhost:14000/dir
tlsAlpn01Port: 5001 tlsAlpn01Port: 5001
http01Port: 5002 http01Port: 5002
renewTime: 30s renewTime: 30s
logging: logging:
level: trace level: info
# Pretty print for human consumption otherwise json # Pretty print for human consumption otherwise json
pretty: true pretty: true
# Log incoming requests # Log incoming requests
@@ -27,7 +26,6 @@ logging:
maxBackups: 10 maxBackups: 10
path: ~/logs/router path: ~/logs/router
rateLimit: rateLimit:
enabled: false enabled: false
# How many requests per ip adress are allowed # How many requests per ip adress are allowed
@@ -39,35 +37,25 @@ rateLimit:
# How often Ip Addresses get cleaned up (only ip addresses with max allowed requests are cleaned up) # How often Ip Addresses get cleaned up (only ip addresses with max allowed requests are cleaned up)
cleanupTime: 45s cleanupTime: 45s
# Experimental
metrics:
enabled: false
flushInterval: 1h
bufferSize: 512
file: ~/metrics.json
hosts: hosts:
# Remote address to request
- remotes: - remotes:
- localhost - 127.0.0.1
# Port on which to request port: 3000
port: 8181
# Domains which get redirected to host
domains: domains:
- localhost - api.hitstar.xyz
- test.localhost
- remotes:
- localhost
port: 8080
domains:
- api.hitstar.localhost
- remotes:
- localhost
port: 5173
domains:
- hitstar.localhost
- hipstar.localhost
rewrite:
"/api": api.hitstar.localhost
- remotes: - remotes:
- 127.0.0.1 - 127.0.0.1
port: 46009 port: 5173
domains: domains:
- chat.localhost - localhost
- hitstar.xyz
rewrite:
"/api": api.hitstar.xyz

View File

@@ -130,7 +130,7 @@ func (m *Metrics) Flush() {
return return
} }
log.Info().Str("file", m.file).Int("count", len(a)).Msg("Completed Metrics flush") log.Debug().Str("file", m.file).Int("count", len(a)).Msg("Completed Metrics flush")
} }
func (m *Metrics) Stop() { func (m *Metrics) Stop() {