You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

metrics.go 763B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package routers
  5. import (
  6. "github.com/prometheus/client_golang/prometheus/promhttp"
  7. "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/modules/setting"
  9. )
  10. // Metrics validate auth token and render prometheus metrics
  11. func Metrics(ctx *context.Context) {
  12. if setting.Metrics.Token == "" {
  13. promhttp.Handler().ServeHTTP(ctx.Resp, ctx.Req.Request)
  14. return
  15. }
  16. header := ctx.Req.Header.Get("Authorization")
  17. if header == "" {
  18. ctx.Error(401)
  19. return
  20. }
  21. if header != "Bearer "+setting.Metrics.Token {
  22. ctx.Error(401)
  23. return
  24. }
  25. promhttp.Handler().ServeHTTP(ctx.Resp, ctx.Req.Request)
  26. }