storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/metrics-router.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "os" 21 "strings" 22 23 "github.com/gorilla/mux" 24 ) 25 26 const ( 27 prometheusMetricsPathLegacy = "/prometheus/metrics" 28 prometheusMetricsV2ClusterPath = "/v2/metrics/cluster" 29 prometheusMetricsV2NodePath = "/v2/metrics/node" 30 ) 31 32 // Standard env prometheus auth type 33 const ( 34 EnvPrometheusAuthType = "MINIO_PROMETHEUS_AUTH_TYPE" 35 ) 36 37 type prometheusAuthType string 38 39 const ( 40 prometheusJWT prometheusAuthType = "jwt" 41 prometheusPublic prometheusAuthType = "public" 42 ) 43 44 // registerMetricsRouter - add handler functions for metrics. 45 func registerMetricsRouter(router *mux.Router) { 46 // metrics router 47 metricsRouter := router.NewRoute().PathPrefix(minioReservedBucketPath).Subrouter() 48 authType := strings.ToLower(os.Getenv(EnvPrometheusAuthType)) 49 switch prometheusAuthType(authType) { 50 case prometheusPublic: 51 metricsRouter.Handle(prometheusMetricsPathLegacy, metricsHandler()) 52 metricsRouter.Handle(prometheusMetricsV2ClusterPath, metricsServerHandler()) 53 metricsRouter.Handle(prometheusMetricsV2NodePath, metricsNodeHandler()) 54 case prometheusJWT: 55 fallthrough 56 default: 57 metricsRouter.Handle(prometheusMetricsPathLegacy, AuthMiddleware(metricsHandler())) 58 metricsRouter.Handle(prometheusMetricsV2ClusterPath, AuthMiddleware(metricsServerHandler())) 59 metricsRouter.Handle(prometheusMetricsV2NodePath, AuthMiddleware(metricsNodeHandler())) 60 } 61 }