diff --git a/cmd/globals.go b/cmd/globals.go index 040326b9c..c10bcffe8 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -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. ) diff --git a/cmd/metrics-realtime.go b/cmd/metrics-realtime.go index c751f4306..2b413cd7a 100644 --- a/cmd/metrics-realtime.go +++ b/cmd/metrics-realtime.go @@ -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. diff --git a/cmd/server-main.go b/cmd/server-main.go index b1920fc0c..09b61a1de 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -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. diff --git a/go.mod b/go.mod index b05ff7c7c..640133928 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/minio/dperf v0.5.0 github.com/minio/highwayhash v1.0.2 github.com/minio/kes-go v0.1.0 - github.com/minio/madmin-go/v3 v3.0.6 + github.com/minio/madmin-go/v3 v3.0.7 github.com/minio/minio-go/v7 v7.0.59 github.com/minio/mux v1.9.0 github.com/minio/pkg v1.7.5 diff --git a/go.sum b/go.sum index 083e9ea11..45c0a9fd1 100644 --- a/go.sum +++ b/go.sum @@ -483,8 +483,8 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/minio/kes-go v0.1.0 h1:h201DyOYP5sTqajkxFGxmXz/kPbT8HQNX1uh3Yx2PFc= github.com/minio/kes-go v0.1.0/go.mod h1:VorHLaIYis9/MxAHAtXN4d8PUMNKhIxTIlvFt0hBOEo= -github.com/minio/madmin-go/v3 v3.0.6 h1:rlU0UCwRhi/bI5R9Pg5df88ddqFNFA5mpmxScAanQCA= -github.com/minio/madmin-go/v3 v3.0.6/go.mod h1:lPrMoc1aeiIWmmrxBthkDqzMPQwC/Lu9ByuyM2wenJk= +github.com/minio/madmin-go/v3 v3.0.7 h1:nuRwrqarFrkzbUiA36H/HKAcuNr8J9TjKlWRlua7lNo= +github.com/minio/madmin-go/v3 v3.0.7/go.mod h1:lPrMoc1aeiIWmmrxBthkDqzMPQwC/Lu9ByuyM2wenJk= github.com/minio/mc v0.0.0-20230706154612-72958227ad65 h1:27INveRWSp7yAEy4szNp15DOA2dyOwnxTGt/p0JuTh4= github.com/minio/mc v0.0.0-20230706154612-72958227ad65/go.mod h1:41ndsUBIAA/dRjOQ/0KY4d8vI70gDiKeMo1zusOQRWk= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= diff --git a/internal/net/net.go b/internal/net/net.go new file mode 100644 index 000000000..9443156d5 --- /dev/null +++ b/internal/net/net.go @@ -0,0 +1,35 @@ +// Copyright (c) 2015-2023 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 . + +package net + +import ( + "github.com/prometheus/procfs" +) + +// GetInterfaceNetStats - get procfs.NetDevLine by interfaceName +func GetInterfaceNetStats(interf string) (procfs.NetDevLine, error) { + proc, err := procfs.Self() + if err != nil { + return procfs.NetDevLine{}, err + } + netDev, err := proc.NetDev() + if err != nil { + return procfs.NetDevLine{}, err + } + return netDev[interf], nil +}