metrics: initial commit

This commit is contained in:
Matthew Penner
2021-03-09 08:45:54 -07:00
parent 08a7ccd175
commit dafbbab2ed
8 changed files with 171 additions and 3 deletions

View File

@@ -3,9 +3,11 @@ package middleware
import (
"context"
"crypto/subtle"
"github.com/pterodactyl/wings/metrics"
"io"
"net/http"
"os"
"strconv"
"strings"
"emperror.dev/errors"
@@ -352,3 +354,19 @@ func ExtractManager(c *gin.Context) *server.Manager {
}
panic("middleware/middleware: cannot extract server manager: not present in context")
}
func Metrics() gin.HandlerFunc {
return func(c *gin.Context) {
path := c.Request.URL.Path
rawQuery := c.Request.URL.RawQuery
c.Next()
// Skip over the server websocket endpoint.
if strings.HasSuffix(c.FullPath(), "/ws") {
return
}
metrics.HTTPRequestsTotal.WithLabelValues(c.Request.Method, c.FullPath(), path, rawQuery, strconv.Itoa(c.Writer.Status())).Inc()
}
}

View File

@@ -14,6 +14,7 @@ func Configure(m *server.Manager, client remote.Client) *gin.Engine {
router := gin.New()
router.Use(gin.Recovery())
router.Use(middleware.Metrics())
router.Use(middleware.AttachRequestID(), middleware.CaptureErrors(), middleware.SetAccessControlHeaders())
router.Use(middleware.AttachServerManager(m), middleware.AttachApiClient(client))
// @todo log this into a different file so you can setup IP blocking for abusive requests and such.