mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
fear: Implement 'mc support top net' (#17598)
This commit is contained in:
@@ -393,6 +393,10 @@ var (
|
||||
// Is _MINIO_DISABLE_API_FREEZE_ON_BOOT set?
|
||||
globalDisableFreezeOnBoot bool
|
||||
|
||||
// Contains NIC interface name used for internode communication
|
||||
globalInternodeInterface string
|
||||
globalInternodeInterfaceOnce sync.Once
|
||||
|
||||
// Add new variable global values here.
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/minio/internal/disk"
|
||||
"github.com/minio/minio/internal/net"
|
||||
)
|
||||
|
||||
type collectMetricsOpts struct {
|
||||
@@ -69,6 +70,18 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
||||
if types.Contains(madmin.MetricsSiteResync) {
|
||||
m.Aggregated.SiteResync = globalSiteResyncMetrics.report(opts.depID)
|
||||
}
|
||||
if types.Contains(madmin.MetricNet) {
|
||||
m.Aggregated.Net = &madmin.NetMetrics{
|
||||
CollectedAt: UTCNow(),
|
||||
InterfaceName: globalInternodeInterface,
|
||||
}
|
||||
netStats, err := net.GetInterfaceNetStats(globalInternodeInterface)
|
||||
if err != nil {
|
||||
m.Errors = append(m.Errors, err.Error())
|
||||
} else {
|
||||
m.Aggregated.Net.NetStats = netStats
|
||||
}
|
||||
}
|
||||
// Add types...
|
||||
|
||||
// ByHost is a shallow reference, so careful about sharing.
|
||||
|
||||
@@ -248,6 +248,9 @@ func serverHandleCmdArgs(ctx *cli.Context) {
|
||||
logger.FatalIf(err, "Invalid command line arguments")
|
||||
globalNodes = globalEndpoints.GetNodes()
|
||||
|
||||
// Initialize, see which NIC the service is running on, and save it as global
|
||||
_ = getGlobalInternodeInterface(ctx.String("interface"))
|
||||
|
||||
globalLocalNodeName = GetLocalPeer(globalEndpoints, globalMinioHost, globalMinioPort)
|
||||
nodeNameSum := sha256.Sum256([]byte(globalLocalNodeName))
|
||||
globalLocalNodeNameHex = hex.EncodeToString(nodeNameSum[:])
|
||||
@@ -461,6 +464,33 @@ func initConfigSubsystem(ctx context.Context, newObject ObjectLayer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getGlobalInternodeInterface(interfs ...string) string {
|
||||
globalInternodeInterfaceOnce.Do(func() {
|
||||
if len(interfs) != 0 && strings.TrimSpace(interfs[0]) != "" {
|
||||
globalInternodeInterface = interfs[0]
|
||||
return
|
||||
}
|
||||
ip := "127.0.0.1"
|
||||
host, _ := mustSplitHostPort(globalMinioAddr)
|
||||
if host != "" {
|
||||
ip = host
|
||||
}
|
||||
globalInternodeInterface = ip
|
||||
ifs, _ := net.Interfaces()
|
||||
for _, interf := range ifs {
|
||||
addrs, err := interf.Addrs()
|
||||
if err == nil {
|
||||
for _, addr := range addrs {
|
||||
if strings.SplitN(addr.String(), "/", 2)[0] == ip {
|
||||
globalInternodeInterface = interf.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return globalInternodeInterface
|
||||
}
|
||||
|
||||
// Return the list of address that MinIO server needs to listen on:
|
||||
// - Returning 127.0.0.1 is necessary so Console will be able to send
|
||||
// requests to the local S3 API.
|
||||
|
||||
Reference in New Issue
Block a user