mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Add /v3/metrics (get) endpoint to list all known metrics
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/datarhei/core/v16/http/api"
|
||||
@@ -28,6 +29,34 @@ func NewMetrics(config MetricsConfig) *MetricsHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// Describe the known metrics
|
||||
// @Summary List all known metrics with their description and labels
|
||||
// @Description List all known metrics with their description and labels
|
||||
// @ID metrics-3-describe
|
||||
// @Produce json
|
||||
// @Success 200 {array} api.MetricsDescription
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/v3/metrics [get]
|
||||
func (r *MetricsHandler) Describe(c echo.Context) error {
|
||||
response := []api.MetricsDescription{}
|
||||
|
||||
descriptors := r.metrics.Describe()
|
||||
|
||||
for _, d := range descriptors {
|
||||
response = append(response, api.MetricsDescription{
|
||||
Name: d.Name(),
|
||||
Description: d.Description(),
|
||||
Labels: d.Labels(),
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(response, func(i, j int) bool {
|
||||
return response[i].Name < response[j].Name
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// Query the collected metrics
|
||||
// @Summary Query the collected metrics
|
||||
// @Description Query the collected metrics
|
||||
|
Reference in New Issue
Block a user