storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/admin-server-info.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2019 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  	"context"
    21  	"net/http"
    22  	"runtime"
    23  	"time"
    24  
    25  	"storj.io/minio/cmd/logger"
    26  	"storj.io/minio/pkg/madmin"
    27  )
    28  
    29  // getLocalServerProperty - returns madmin.ServerProperties for only the
    30  // local endpoints from given list of endpoints
    31  func getLocalServerProperty(endpointServerPools EndpointServerPools, r *http.Request) madmin.ServerProperties {
    32  	var localEndpoints Endpoints
    33  	addr := r.Host
    34  	if globalIsDistErasure {
    35  		addr = globalLocalNodeName
    36  	}
    37  	network := make(map[string]string)
    38  	for _, ep := range endpointServerPools {
    39  		for _, endpoint := range ep.Endpoints {
    40  			nodeName := endpoint.Host
    41  			if nodeName == "" {
    42  				nodeName = r.Host
    43  			}
    44  			if endpoint.IsLocal {
    45  				// Only proceed for local endpoints
    46  				network[nodeName] = string(madmin.ItemOnline)
    47  				localEndpoints = append(localEndpoints, endpoint)
    48  				continue
    49  			}
    50  			_, present := network[nodeName]
    51  			if !present {
    52  				if err := isServerResolvable(endpoint, 2*time.Second); err == nil {
    53  					network[nodeName] = string(madmin.ItemOnline)
    54  				} else {
    55  					network[nodeName] = string(madmin.ItemOffline)
    56  					// log once the error
    57  					logger.LogOnceIf(context.Background(), err, nodeName)
    58  				}
    59  			}
    60  		}
    61  	}
    62  
    63  	props := madmin.ServerProperties{
    64  		State:    string(madmin.ItemInitializing),
    65  		Endpoint: addr,
    66  		Uptime:   UTCNow().Unix() - globalBootTime.Unix(),
    67  		Version:  Version,
    68  		CommitID: CommitID,
    69  		Network:  network,
    70  	}
    71  	runtime.ReadMemStats(&props.MemStats)
    72  
    73  	objLayer := newObjectLayerFn()
    74  	if objLayer != nil && !GlobalIsGateway {
    75  		// only need Disks information in server mode.
    76  		storageInfo, _ := objLayer.LocalStorageInfo(GlobalContext)
    77  		props.State = string(madmin.ItemOnline)
    78  		props.Disks = storageInfo.Disks
    79  	}
    80  
    81  	return props
    82  }