Refactor StatsRecorder

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-12-06 15:44:25 +01:00
parent 6adb346cee
commit 3ebfd729cf
No known key found for this signature in database
GPG key ID: D808B4C167352E59
3 changed files with 11 additions and 6 deletions

View file

@ -1,4 +1,4 @@
package main
package middlewares
import (
"net/http"
@ -16,6 +16,13 @@ type StatsRecorder struct {
recentErrors []*statsError
}
// NewStatsRecorder returns a new StatsRecorder
func NewStatsRecorder(numRecentErrors int) *StatsRecorder {
return &StatsRecorder{
numRecentErrors: numRecentErrors,
}
}
// Stats includes all of the stats gathered by the recorder.
type Stats struct {
RecentErrors []*statsError `json:"recent_errors"`

View file

@ -169,9 +169,7 @@ func (server *Server) startHTTPServers() {
for newServerEntryPointName, newServerEntryPoint := range server.serverEntryPoints {
serverMiddlewares := []negroni.Handler{server.loggerMiddleware, metrics}
if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Statistics != nil {
statsRecorder = &StatsRecorder{
numRecentErrors: server.globalConfiguration.Web.Statistics.RecentErrors,
}
statsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors)
serverMiddlewares = append(serverMiddlewares, statsRecorder)
}
if server.globalConfiguration.EntryPoints[newServerEntryPointName].Auth != nil {

4
web.go
View file

@ -23,7 +23,7 @@ import (
var (
metrics = thoas_stats.New()
statsRecorder *StatsRecorder
statsRecorder *middlewares.StatsRecorder
)
// WebProvider is a provider.Provider implementation that provides the UI.
@ -141,7 +141,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag
// they are enabled).
type healthResponse struct {
*thoas_stats.Data
*Stats
*middlewares.Stats
}
func (provider *WebProvider) getHealthHandler(response http.ResponseWriter, request *http.Request) {