Rename config.yaml to example and add config.yaml to gitignore, make Metrics optional and configurable
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@
|
|||||||
bin/
|
bin/
|
||||||
data.json
|
data.json
|
||||||
*.json
|
*.json
|
||||||
|
config.yaml
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
pipeline.AddMiddleware(metrics)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
return pipeline
|
return pipeline
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +1,61 @@
|
|||||||
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: info
|
||||||
level: trace
|
# Pretty print for human consumption otherwise json
|
||||||
# Pretty print for human consumption otherwise json
|
pretty: true
|
||||||
pretty: true
|
# Log incoming requests
|
||||||
# Log incoming requests
|
requests: true
|
||||||
requests: true
|
# Log to file aswell as stderr
|
||||||
# Log to file aswell as stderr
|
file:
|
||||||
file:
|
enabled: false
|
||||||
enabled: false
|
maxAge: 14
|
||||||
maxAge: 14
|
maxBackups: 10
|
||||||
maxBackups: 10
|
path: ~/logs/router
|
||||||
path: ~/logs/router
|
|
||||||
|
rateLimit:
|
||||||
|
enabled: false
|
||||||
rateLimit:
|
# How many requests per ip adress are allowed
|
||||||
enabled: false
|
bucketSize: 50
|
||||||
# How many requests per ip adress are allowed
|
# How many requests per ip address are refilled
|
||||||
bucketSize: 50
|
refillSize: 50
|
||||||
# How many requests per ip address are refilled
|
# How often requests per ip address are refilled
|
||||||
refillSize: 50
|
refillTime: 30s
|
||||||
# How often requests per ip address are refilled
|
# How often Ip Addresses get cleaned up (only ip addresses with max allowed requests are cleaned up)
|
||||||
refillTime: 30s
|
cleanupTime: 45s
|
||||||
# How often Ip Addresses get cleaned up (only ip addresses with max allowed requests are cleaned up)
|
|
||||||
cleanupTime: 45s
|
# Experimental
|
||||||
|
metrics:
|
||||||
|
enabled: false
|
||||||
hosts:
|
flushInterval: 1h
|
||||||
# Remote address to request
|
bufferSize: 512
|
||||||
- remotes:
|
file: ~/metrics.json
|
||||||
- localhost
|
|
||||||
# Port on which to request
|
hosts:
|
||||||
port: 8181
|
- remotes:
|
||||||
# Domains which get redirected to host
|
- 127.0.0.1
|
||||||
domains:
|
port: 3000
|
||||||
- localhost
|
domains:
|
||||||
- test.localhost
|
- api.hitstar.xyz
|
||||||
|
|
||||||
- remotes:
|
- remotes:
|
||||||
- localhost
|
- 127.0.0.1
|
||||||
port: 8080
|
port: 5173
|
||||||
domains:
|
domains:
|
||||||
- api.hitstar.localhost
|
- localhost
|
||||||
|
- hitstar.xyz
|
||||||
- remotes:
|
rewrite:
|
||||||
- localhost
|
"/api": api.hitstar.xyz
|
||||||
port: 5173
|
|
||||||
domains:
|
|
||||||
- hitstar.localhost
|
|
||||||
- hipstar.localhost
|
|
||||||
rewrite:
|
|
||||||
"/api": api.hitstar.localhost
|
|
||||||
|
|
||||||
- remotes:
|
|
||||||
- 127.0.0.1
|
|
||||||
port: 46009
|
|
||||||
domains:
|
|
||||||
- chat.localhost
|
|
||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user