mirror of
https://github.com/ferdzo/fs.git
synced 2026-04-05 08:26:28 +00:00
Initial metrics endpoint added in Prometheus style
This commit is contained in:
14
api/api.go
14
api/api.go
@@ -10,6 +10,7 @@ import (
|
||||
"fs/auth"
|
||||
"fs/logging"
|
||||
"fs/metadata"
|
||||
"fs/metrics"
|
||||
"fs/models"
|
||||
"fs/service"
|
||||
"io"
|
||||
@@ -70,6 +71,8 @@ func (h *Handler) setupRoutes() {
|
||||
|
||||
h.router.Get("/healthz", h.handleHealth)
|
||||
h.router.Head("/healthz", h.handleHealth)
|
||||
h.router.Get("/metrics", h.handleMetrics)
|
||||
h.router.Head("/metrics", h.handleMetrics)
|
||||
h.router.Get("/", h.handleGetBuckets)
|
||||
|
||||
h.router.Get("/{bucket}/", h.handleGetBucket)
|
||||
@@ -106,6 +109,17 @@ func (h *Handler) handleHealth(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) handleMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
payload := metrics.Default.RenderPrometheus()
|
||||
w.Header().Set("Content-Type", "text/plain; version=0.0.4; charset=utf-8")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(payload)))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if r.Method == http.MethodHead {
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(payload))
|
||||
}
|
||||
|
||||
func validateObjectKey(key string) *s3APIError {
|
||||
if key == "" {
|
||||
err := s3ErrInvalidObjectKey
|
||||
|
||||
Reference in New Issue
Block a user