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 (
|
2019-10-04 14:18:59 -04:00
|
|
|
"strings"
|
|
|
|
|
2023-01-23 06:12:47 -05:00
|
|
|
"github.com/minio/mux"
|
2023-09-04 15:57:37 -04:00
|
|
|
"github.com/minio/pkg/v2/env"
|
2018-04-18 19:01:42 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-01-18 23:35:38 -05:00
|
|
|
prometheusMetricsPathLegacy = "/prometheus/metrics"
|
|
|
|
prometheusMetricsV2ClusterPath = "/v2/metrics/cluster"
|
2023-07-19 01:25:12 -04:00
|
|
|
prometheusMetricsV2BucketPath = "/v2/metrics/bucket"
|
2021-01-18 23:35:38 -05:00
|
|
|
prometheusMetricsV2NodePath = "/v2/metrics/node"
|
2018-04-18 19:01:42 -04:00
|
|
|
)
|
|
|
|
|
2019-10-04 14:18:59 -04:00
|
|
|
// Standard env prometheus auth type
|
|
|
|
const (
|
|
|
|
EnvPrometheusAuthType = "MINIO_PROMETHEUS_AUTH_TYPE"
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
2021-06-30 19:08:20 -04:00
|
|
|
authType := strings.ToLower(env.Get(EnvPrometheusAuthType, string(prometheusJWT)))
|
2023-07-19 01:25:12 -04:00
|
|
|
|
|
|
|
auth := AuthMiddleware
|
|
|
|
if prometheusAuthType(authType) == prometheusPublic {
|
|
|
|
auth = NoAuthMiddleware
|
2019-10-04 14:18:59 -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()))
|
2018-04-18 19:01:42 -04:00
|
|
|
}
|