add handler error metrics

This commit is contained in:
ginuerzh
2022-03-05 16:37:45 +08:00
parent e587b4df7c
commit ee72cea036
31 changed files with 404 additions and 293 deletions

View File

@ -10,7 +10,6 @@ import (
"github.com/go-gost/gost/pkg/listener"
"github.com/go-gost/gost/pkg/logger"
"github.com/go-gost/gost/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type options struct {
@ -105,11 +104,14 @@ func (s *service) Serve() error {
metrics.RequestsInFlight(s.name).Inc()
defer metrics.RequestsInFlight(s.name).Dec()
timer := prometheus.NewTimer(
metrics.RequestSeconds(s.name))
defer timer.ObserveDuration()
start := time.Now()
defer func() {
metrics.RequestSeconds(s.name).Observe(time.Since(start).Seconds())
}()
s.handler.Handle(context.Background(), conn)
if err := s.handler.Handle(context.Background(), conn); err != nil {
metrics.HandlerErrors(s.name).Inc()
}
}()
}
}