minio/cmd/admin-server-info.go

84 lines
2.4 KiB
Go
Raw Normal View History

// 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/>.
package cmd
import (
"context"
"net/http"
"runtime"
"time"
"github.com/minio/madmin-go"
"github.com/minio/minio/cmd/logger"
)
// getLocalServerProperty - returns madmin.ServerProperties for only the
2019-12-11 17:27:03 -05:00
// local endpoints from given list of endpoints
2020-12-01 16:50:33 -05:00
func getLocalServerProperty(endpointServerPools EndpointServerPools, r *http.Request) madmin.ServerProperties {
var localEndpoints Endpoints
2019-12-11 17:27:03 -05:00
addr := r.Host
if globalIsDistErasure {
addr = globalLocalNodeName
2019-12-11 17:27:03 -05:00
}
network := make(map[string]string)
2020-12-01 16:50:33 -05:00
for _, ep := range endpointServerPools {
2019-12-11 17:27:03 -05:00
for _, endpoint := range ep.Endpoints {
nodeName := endpoint.Host
if nodeName == "" {
nodeName = r.Host
2019-12-11 17:27:03 -05:00
}
if endpoint.IsLocal {
// Only proceed for local endpoints
network[nodeName] = string(madmin.ItemOnline)
localEndpoints = append(localEndpoints, endpoint)
continue
}
_, present := network[nodeName]
if !present {
if err := isServerResolvable(endpoint, 2*time.Second); err == nil {
network[nodeName] = string(madmin.ItemOnline)
} else {
network[nodeName] = string(madmin.ItemOffline)
// log once the error
logger.LogOnceIf(context.Background(), err, nodeName)
}
2019-12-11 17:27:03 -05:00
}
}
}
props := madmin.ServerProperties{
State: string(madmin.ItemInitializing),
2019-12-11 17:27:03 -05:00
Endpoint: addr,
Uptime: UTCNow().Unix() - globalBootTime.Unix(),
2019-12-11 17:27:03 -05:00
Version: Version,
CommitID: CommitID,
Network: network,
}
runtime.ReadMemStats(&props.MemStats)
objLayer := newObjectLayerFn()
if objLayer != nil && !globalIsGateway {
// only need Disks information in server mode.
storageInfo, _ := objLayer.LocalStorageInfo(GlobalContext)
props.State = string(madmin.ItemOnline)
props.Disks = storageInfo.Disks
}
return props
}