| 
									
										
										
										
											2021-04-19 03:41:13 +08: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-19 07:01:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2019-10-05 02:18:59 +08:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-23 19:12:47 +08:00
										 |  |  | 	"github.com/minio/mux" | 
					
						
							| 
									
										
										
										
											2021-07-01 07:08:20 +08:00
										 |  |  | 	"github.com/minio/pkg/env" | 
					
						
							| 
									
										
										
										
											2018-04-19 07:01:42 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 	prometheusMetricsPathLegacy    = "/prometheus/metrics" | 
					
						
							|  |  |  | 	prometheusMetricsV2ClusterPath = "/v2/metrics/cluster" | 
					
						
							|  |  |  | 	prometheusMetricsV2NodePath    = "/v2/metrics/node" | 
					
						
							| 
									
										
										
										
											2018-04-19 07:01:42 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-05 02:18:59 +08:00
										 |  |  | // Standard env prometheus auth type
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	EnvPrometheusAuthType = "MINIO_PROMETHEUS_AUTH_TYPE" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type prometheusAuthType string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	prometheusJWT    prometheusAuthType = "jwt" | 
					
						
							|  |  |  | 	prometheusPublic prometheusAuthType = "public" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-19 07:01:42 +08:00
										 |  |  | // registerMetricsRouter - add handler functions for metrics.
 | 
					
						
							| 
									
										
										
										
											2018-05-09 11:10:55 +08:00
										 |  |  | func registerMetricsRouter(router *mux.Router) { | 
					
						
							| 
									
										
										
										
											2018-04-19 07:01:42 +08:00
										 |  |  | 	// metrics router
 | 
					
						
							| 
									
										
										
										
											2018-05-09 11:10:55 +08:00
										 |  |  | 	metricsRouter := router.NewRoute().PathPrefix(minioReservedBucketPath).Subrouter() | 
					
						
							| 
									
										
										
										
											2021-07-01 07:08:20 +08:00
										 |  |  | 	authType := strings.ToLower(env.Get(EnvPrometheusAuthType, string(prometheusJWT))) | 
					
						
							| 
									
										
										
										
											2019-10-05 02:18:59 +08:00
										 |  |  | 	switch prometheusAuthType(authType) { | 
					
						
							|  |  |  | 	case prometheusPublic: | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 		metricsRouter.Handle(prometheusMetricsPathLegacy, metricsHandler()) | 
					
						
							|  |  |  | 		metricsRouter.Handle(prometheusMetricsV2ClusterPath, metricsServerHandler()) | 
					
						
							|  |  |  | 		metricsRouter.Handle(prometheusMetricsV2NodePath, metricsNodeHandler()) | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 	case prometheusJWT: | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 		metricsRouter.Handle(prometheusMetricsPathLegacy, AuthMiddleware(metricsHandler())) | 
					
						
							|  |  |  | 		metricsRouter.Handle(prometheusMetricsV2ClusterPath, AuthMiddleware(metricsServerHandler())) | 
					
						
							|  |  |  | 		metricsRouter.Handle(prometheusMetricsV2NodePath, AuthMiddleware(metricsNodeHandler())) | 
					
						
							| 
									
										
										
										
											2019-10-05 02:18:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-19 07:01:42 +08:00
										 |  |  | } |