2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-04-18 19:01:42 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-03-10 05:15:15 -04:00
|
|
|
"net/http"
|
2019-10-04 14:18:59 -04:00
|
|
|
"strings"
|
|
|
|
|
2023-01-23 06:12:47 -05:00
|
|
|
"github.com/minio/mux"
|
2024-05-24 19:05:23 -04:00
|
|
|
"github.com/minio/pkg/v3/env"
|
2018-04-18 19:01:42 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-09-30 16:40:20 -04:00
|
|
|
prometheusMetricsPathLegacy = "/prometheus/metrics"
|
|
|
|
prometheusMetricsV2ClusterPath = "/v2/metrics/cluster"
|
|
|
|
prometheusMetricsV2BucketPath = "/v2/metrics/bucket"
|
|
|
|
prometheusMetricsV2NodePath = "/v2/metrics/node"
|
|
|
|
prometheusMetricsV2ResourcePath = "/v2/metrics/resource"
|
2024-03-10 05:15:15 -04:00
|
|
|
|
|
|
|
// Metrics v3 endpoints
|
|
|
|
metricsV3Path = "/metrics/v3"
|
2018-04-18 19:01:42 -04:00
|
|
|
)
|
|
|
|
|
2019-10-04 14:18:59 -04:00
|
|
|
// Standard env prometheus auth type
|
|
|
|
const (
|
2024-07-15 12:28:02 -04:00
|
|
|
EnvPrometheusAuthType = "MINIO_PROMETHEUS_AUTH_TYPE"
|
|
|
|
EnvPrometheusOpenMetrics = "MINIO_PROMETHEUS_OPEN_METRICS"
|
2019-10-04 14:18:59 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type prometheusAuthType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
prometheusJWT prometheusAuthType = "jwt"
|
|
|
|
prometheusPublic prometheusAuthType = "public"
|
|
|
|
)
|
|
|
|
|
2018-04-18 19:01:42 -04:00
|
|
|
// registerMetricsRouter - add handler functions for metrics.
|
2018-05-08 23:10:55 -04:00
|
|
|
func registerMetricsRouter(router *mux.Router) {
|
2018-04-18 19:01:42 -04:00
|
|
|
// metrics router
|
2018-05-08 23:10:55 -04:00
|
|
|
metricsRouter := router.NewRoute().PathPrefix(minioReservedBucketPath).Subrouter()
|
2024-03-10 05:15:15 -04:00
|
|
|
authType := prometheusAuthType(strings.ToLower(env.Get(EnvPrometheusAuthType, string(prometheusJWT))))
|
2023-07-19 01:25:12 -04:00
|
|
|
|
|
|
|
auth := AuthMiddleware
|
2024-03-10 05:15:15 -04:00
|
|
|
if authType == prometheusPublic {
|
2023-07-19 01:25:12 -04:00
|
|
|
auth = NoAuthMiddleware
|
2019-10-04 14:18:59 -04:00
|
|
|
}
|
2024-07-15 12:28:02 -04:00
|
|
|
|
2023-07-19 01:25:12 -04:00
|
|
|
metricsRouter.Handle(prometheusMetricsPathLegacy, auth(metricsHandler()))
|
|
|
|
metricsRouter.Handle(prometheusMetricsV2ClusterPath, auth(metricsServerHandler()))
|
|
|
|
metricsRouter.Handle(prometheusMetricsV2BucketPath, auth(metricsBucketHandler()))
|
|
|
|
metricsRouter.Handle(prometheusMetricsV2NodePath, auth(metricsNodeHandler()))
|
2023-09-30 16:40:20 -04:00
|
|
|
metricsRouter.Handle(prometheusMetricsV2ResourcePath, auth(metricsResourceHandler()))
|
2024-03-10 05:15:15 -04:00
|
|
|
|
2024-07-15 12:28:02 -04:00
|
|
|
// Metrics v3
|
|
|
|
metricsV3Server := newMetricsV3Server(auth)
|
2024-03-10 05:15:15 -04:00
|
|
|
|
|
|
|
// Register metrics v3 handler. It also accepts an optional query
|
|
|
|
// parameter `?list` - see handler for details.
|
|
|
|
metricsRouter.Methods(http.MethodGet).Path(metricsV3Path + "{pathComps:.*}").Handler(metricsV3Server)
|
2018-04-18 19:01:42 -04:00
|
|
|
}
|