| 
									
										
										
										
											2024-05-23 07:07:14 +08:00
										 |  |  | // Copyright (c) 2015-2024 MinIO, Inc.
 | 
					
						
							| 
									
										
										
										
											2021-04-19 03:41:13 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // 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/>.
 | 
					
						
							| 
									
										
										
										
											2019-09-13 02:06:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2024-03-08 02:24:07 +08:00
										 |  |  | 	"math" | 
					
						
							| 
									
										
										
										
											2019-09-13 02:06:12 +08:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2021-04-08 01:40:51 +08:00
										 |  |  | 	"runtime" | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	"runtime/debug" | 
					
						
							| 
									
										
										
										
											2024-03-08 02:24:07 +08:00
										 |  |  | 	"sort" | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2021-01-26 02:01:27 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2019-09-13 02:06:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-20 08:53:08 +08:00
										 |  |  | 	"github.com/minio/madmin-go/v3" | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	"github.com/minio/minio/internal/config" | 
					
						
							| 
									
										
										
										
											2023-02-22 09:43:01 +08:00
										 |  |  | 	"github.com/minio/minio/internal/kms" | 
					
						
							| 
									
										
										
										
											2024-05-23 07:07:14 +08:00
										 |  |  | 	xnet "github.com/minio/pkg/v2/net" | 
					
						
							| 
									
										
										
										
											2019-09-13 02:06:12 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 10:37:09 +08:00
										 |  |  | // getLocalServerProperty - returns madmin.ServerProperties for only the
 | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | // local endpoints from given list of endpoints
 | 
					
						
							| 
									
										
										
										
											2024-02-09 11:28:46 +08:00
										 |  |  | func getLocalServerProperty(endpointServerPools EndpointServerPools, r *http.Request, metrics bool) madmin.ServerProperties { | 
					
						
							| 
									
										
										
										
											2022-06-07 07:14:52 +08:00
										 |  |  | 	addr := globalLocalNodeName | 
					
						
							|  |  |  | 	if r != nil { | 
					
						
							|  |  |  | 		addr = r.Host | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if globalIsDistErasure { | 
					
						
							| 
									
										
										
										
											2021-03-27 02:37:58 +08:00
										 |  |  | 		addr = globalLocalNodeName | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-03-08 02:24:07 +08:00
										 |  |  | 	poolNumbers := make(map[int]struct{}) | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 	network := make(map[string]string) | 
					
						
							| 
									
										
										
										
											2020-12-02 05:50:33 +08:00
										 |  |  | 	for _, ep := range endpointServerPools { | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 		for _, endpoint := range ep.Endpoints { | 
					
						
							| 
									
										
										
										
											2024-03-08 02:24:07 +08:00
										 |  |  | 			if endpoint.IsLocal { | 
					
						
							|  |  |  | 				poolNumbers[endpoint.PoolIdx+1] = struct{}{} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-02 09:45:29 +08:00
										 |  |  | 			nodeName := endpoint.Host | 
					
						
							|  |  |  | 			if nodeName == "" { | 
					
						
							| 
									
										
										
										
											2022-06-07 07:14:52 +08:00
										 |  |  | 				nodeName = addr | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if endpoint.IsLocal { | 
					
						
							| 
									
										
										
										
											2020-02-02 09:45:29 +08:00
										 |  |  | 				// Only proceed for local endpoints
 | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 				network[nodeName] = string(madmin.ItemOnline) | 
					
						
							| 
									
										
										
										
											2020-07-14 00:51:07 +08:00
										 |  |  | 				continue | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			_, present := network[nodeName] | 
					
						
							|  |  |  | 			if !present { | 
					
						
							| 
									
										
										
										
											2022-03-18 07:20:10 +08:00
										 |  |  | 				if err := isServerResolvable(endpoint, 5*time.Second); err == nil { | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 					network[nodeName] = string(madmin.ItemOnline) | 
					
						
							| 
									
										
										
										
											2020-02-02 09:45:29 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2024-05-23 07:07:14 +08:00
										 |  |  | 					if xnet.IsNetworkOrHostDown(err, false) { | 
					
						
							|  |  |  | 						network[nodeName] = string(madmin.ItemOffline) | 
					
						
							|  |  |  | 					} else if xnet.IsNetworkOrHostDown(err, true) { | 
					
						
							|  |  |  | 						network[nodeName] = "connection attempt timedout" | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-02-02 09:45:29 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	var memstats runtime.MemStats | 
					
						
							|  |  |  | 	runtime.ReadMemStats(&memstats) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	gcStats := debug.GCStats{ | 
					
						
							|  |  |  | 		// If stats.PauseQuantiles is non-empty, ReadGCStats fills
 | 
					
						
							|  |  |  | 		// it with quantiles summarizing the distribution of pause time.
 | 
					
						
							|  |  |  | 		// For example, if len(stats.PauseQuantiles) is 5, it will be
 | 
					
						
							|  |  |  | 		// filled with the minimum, 25%, 50%, 75%, and maximum pause times.
 | 
					
						
							|  |  |  | 		PauseQuantiles: make([]time.Duration, 5), | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	debug.ReadGCStats(&gcStats) | 
					
						
							|  |  |  | 	// Truncate GC stats to max 5 entries.
 | 
					
						
							|  |  |  | 	if len(gcStats.PauseEnd) > 5 { | 
					
						
							|  |  |  | 		gcStats.PauseEnd = gcStats.PauseEnd[len(gcStats.PauseEnd)-5:] | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if len(gcStats.Pause) > 5 { | 
					
						
							|  |  |  | 		gcStats.Pause = gcStats.Pause[len(gcStats.Pause)-5:] | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 	props := madmin.ServerProperties{ | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 		Endpoint: addr, | 
					
						
							| 
									
										
										
										
											2019-12-12 09:56:02 +08:00
										 |  |  | 		Uptime:   UTCNow().Unix() - globalBootTime.Unix(), | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 		Version:  Version, | 
					
						
							|  |  |  | 		CommitID: CommitID, | 
					
						
							|  |  |  | 		Network:  network, | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 		MemStats: madmin.MemStats{ | 
					
						
							|  |  |  | 			Alloc:      memstats.Alloc, | 
					
						
							|  |  |  | 			TotalAlloc: memstats.TotalAlloc, | 
					
						
							|  |  |  | 			Mallocs:    memstats.Mallocs, | 
					
						
							|  |  |  | 			Frees:      memstats.Frees, | 
					
						
							|  |  |  | 			HeapAlloc:  memstats.HeapAlloc, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 		GoMaxProcs:     runtime.GOMAXPROCS(0), | 
					
						
							|  |  |  | 		NumCPU:         runtime.NumCPU(), | 
					
						
							|  |  |  | 		RuntimeVersion: runtime.Version(), | 
					
						
							|  |  |  | 		GCStats: &madmin.GCStats{ | 
					
						
							|  |  |  | 			LastGC:     gcStats.LastGC, | 
					
						
							|  |  |  | 			NumGC:      gcStats.NumGC, | 
					
						
							|  |  |  | 			PauseTotal: gcStats.PauseTotal, | 
					
						
							|  |  |  | 			Pause:      gcStats.Pause, | 
					
						
							|  |  |  | 			PauseEnd:   gcStats.PauseEnd, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		MinioEnvVars: make(map[string]string, 10), | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-08 02:24:07 +08:00
										 |  |  | 	for poolNumber := range poolNumbers { | 
					
						
							|  |  |  | 		props.PoolNumbers = append(props.PoolNumbers, poolNumber) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sort.Ints(props.PoolNumbers) | 
					
						
							|  |  |  | 	props.PoolNumber = func() int { | 
					
						
							|  |  |  | 		if len(props.PoolNumbers) == 1 { | 
					
						
							|  |  |  | 			return props.PoolNumbers[0] | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return math.MaxInt // this indicates that its unset.
 | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	sensitive := map[string]struct{}{ | 
					
						
							|  |  |  | 		config.EnvAccessKey:         {}, | 
					
						
							|  |  |  | 		config.EnvSecretKey:         {}, | 
					
						
							|  |  |  | 		config.EnvRootUser:          {}, | 
					
						
							|  |  |  | 		config.EnvRootPassword:      {}, | 
					
						
							|  |  |  | 		config.EnvMinIOSubnetAPIKey: {}, | 
					
						
							| 
									
										
										
										
											2023-02-22 09:43:01 +08:00
										 |  |  | 		kms.EnvKMSSecretKey:         {}, | 
					
						
							| 
									
										
										
										
											2022-10-12 02:31:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for _, v := range os.Environ() { | 
					
						
							|  |  |  | 		if !strings.HasPrefix(v, "MINIO") && !strings.HasPrefix(v, "_MINIO") { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		split := strings.SplitN(v, "=", 2) | 
					
						
							|  |  |  | 		key := split[0] | 
					
						
							|  |  |  | 		value := "" | 
					
						
							|  |  |  | 		if len(split) > 1 { | 
					
						
							|  |  |  | 			value = split[1] | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Do not send sensitive creds.
 | 
					
						
							|  |  |  | 		if _, ok := sensitive[key]; ok || strings.Contains(strings.ToLower(key), "password") || strings.HasSuffix(strings.ToLower(key), "key") { | 
					
						
							|  |  |  | 			props.MinioEnvVars[key] = "*** EXISTS, REDACTED ***" | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		props.MinioEnvVars[key] = value | 
					
						
							| 
									
										
										
										
											2019-12-12 06:27:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 	objLayer := newObjectLayerFn() | 
					
						
							| 
									
										
										
										
											2022-10-25 08:44:15 +08:00
										 |  |  | 	if objLayer != nil { | 
					
						
							| 
									
										
										
										
											2024-02-09 11:28:46 +08:00
										 |  |  | 		storageInfo := objLayer.LocalStorageInfo(GlobalContext, metrics) | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 		props.State = string(madmin.ItemOnline) | 
					
						
							|  |  |  | 		props.Disks = storageInfo.Disks | 
					
						
							| 
									
										
										
										
											2022-12-02 06:31:35 +08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2023-04-25 00:10:02 +08:00
										 |  |  | 		props.State = string(madmin.ItemInitializing) | 
					
						
							|  |  |  | 		props.Disks = getOfflineDisks("", globalEndpoints) | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-23 05:19:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 	return props | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | } |