From ec9e7493b34df5c13462cdaeab5b35f152d0cb68 Mon Sep 17 00:00:00 2001 From: vadimartynov <166398828+vadimartynov@users.noreply.github.com> Date: Fri, 12 Jul 2024 21:56:26 +0400 Subject: [PATCH] -metricsIp cmd flag (#5773) * Added/Updated: - Added metrics ip options for all servers; - Fixed a bug with the selection of the binIp or ip parameter for the metrics handler; * Fixed cmd flags --- weed/command/filer.go | 12 +++++++++++- weed/command/master.go | 12 +++++++++++- weed/command/s3.go | 10 +++++++++- weed/command/server.go | 7 ++++++- weed/command/volume.go | 12 +++++++++++- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/weed/command/filer.go b/weed/command/filer.go index 6478493b6..2554b3477 100644 --- a/weed/command/filer.go +++ b/weed/command/filer.go @@ -57,6 +57,7 @@ type FilerOptions struct { disableHttp *bool cipher *bool metricsHttpPort *int + metricsHttpIp *string saveToFilerLimit *int defaultLevelDbDirectory *string concurrentUploadLimitMB *int @@ -90,6 +91,7 @@ func init() { f.disableHttp = cmdFiler.Flag.Bool("disableHttp", false, "disable http request, only gRpc operations are allowed") f.cipher = cmdFiler.Flag.Bool("encryptVolumeData", false, "encrypt data on volume servers") f.metricsHttpPort = cmdFiler.Flag.Int("metricsPort", 0, "Prometheus metrics listen port") + f.metricsHttpIp = cmdFiler.Flag.String("metricsIp", "", "metrics listen ip. If empty, default to same as -ip.bind option.") f.saveToFilerLimit = cmdFiler.Flag.Int("saveToFilerLimit", 0, "files smaller than this limit will be saved in filer store") f.defaultLevelDbDirectory = cmdFiler.Flag.String("defaultStoreDir", ".", "if filer.toml is empty, use an embedded filer store in the directory") f.concurrentUploadLimitMB = cmdFiler.Flag.Int("concurrentUploadLimitMB", 128, "limit total concurrent upload size") @@ -178,7 +180,15 @@ func runFiler(cmd *Command, args []string) bool { util.LoadConfiguration("security", false) - go stats_collect.StartMetricsServer(*f.bindIp, *f.metricsHttpPort) + switch { + case *f.metricsHttpIp != "": + // noting to do, use f.metricsHttpIp + case *f.bindIp != "": + *f.metricsHttpIp = *f.bindIp + case *f.ip != "": + *f.metricsHttpIp = *f.ip + } + go stats_collect.StartMetricsServer(*f.metricsHttpIp, *f.metricsHttpPort) filerAddress := pb.NewServerAddress(*f.ip, *f.port, *f.portGrpc).String() startDelay := time.Duration(2) diff --git a/weed/command/master.go b/weed/command/master.go index dbd11e60d..7eecdb571 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -53,6 +53,7 @@ type MasterOptions struct { metricsIntervalSec *int raftResumeState *bool metricsHttpPort *int + metricsHttpIp *string heartbeatInterval *time.Duration electionTimeout *time.Duration raftHashicorp *bool @@ -77,6 +78,7 @@ func init() { m.metricsAddress = cmdMaster.Flag.String("metrics.address", "", "Prometheus gateway address :") m.metricsIntervalSec = cmdMaster.Flag.Int("metrics.intervalSeconds", 15, "Prometheus push interval in seconds") m.metricsHttpPort = cmdMaster.Flag.Int("metricsPort", 0, "Prometheus metrics listen port") + m.metricsHttpIp = cmdMaster.Flag.String("metricsIp", "", "metrics listen ip. If empty, default to same as -ip.bind option.") m.raftResumeState = cmdMaster.Flag.Bool("resumeState", false, "resume previous state on start master server") m.heartbeatInterval = cmdMaster.Flag.Duration("heartbeatInterval", 300*time.Millisecond, "heartbeat interval of master servers, and will be randomly multiplied by [1, 1.25)") m.electionTimeout = cmdMaster.Flag.Duration("electionTimeout", 10*time.Second, "election timeout of master servers") @@ -121,7 +123,15 @@ func runMaster(cmd *Command, args []string) bool { glog.Fatalf("volumeSizeLimitMB should be smaller than 30000") } - go stats_collect.StartMetricsServer(*m.ipBind, *m.metricsHttpPort) + switch { + case *m.metricsHttpIp != "": + // noting to do, use m.metricsHttpIp + case *m.ipBind != "": + *m.metricsHttpIp = *m.ipBind + case *m.ip != "": + *m.metricsHttpIp = *m.ip + } + go stats_collect.StartMetricsServer(*m.metricsHttpIp, *m.metricsHttpPort) startMaster(m, masterWhiteList) return true diff --git a/weed/command/s3.go b/weed/command/s3.go index b7bb2a546..f71f2dc93 100644 --- a/weed/command/s3.go +++ b/weed/command/s3.go @@ -49,6 +49,7 @@ type S3Options struct { tlsCACertificate *string tlsVerifyClientCert *bool metricsHttpPort *int + metricsHttpIp *string allowEmptyFolder *bool allowDeleteBucketNotEmpty *bool auditLogConfig *string @@ -75,6 +76,7 @@ func init() { s3StandaloneOptions.tlsCACertificate = cmdS3.Flag.String("cacert.file", "", "path to the TLS CA certificate file") s3StandaloneOptions.tlsVerifyClientCert = cmdS3.Flag.Bool("tlsVerifyClientCert", false, "whether to verify the client's certificate") s3StandaloneOptions.metricsHttpPort = cmdS3.Flag.Int("metricsPort", 0, "Prometheus metrics listen port") + s3StandaloneOptions.metricsHttpIp = cmdS3.Flag.String("metricsIp", "", "metrics listen ip. If empty, default to same as -ip.bind option.") s3StandaloneOptions.allowEmptyFolder = cmdS3.Flag.Bool("allowEmptyFolder", true, "allow empty folders") s3StandaloneOptions.allowDeleteBucketNotEmpty = cmdS3.Flag.Bool("allowDeleteBucketNotEmpty", true, "allow recursive deleting all entries along with bucket") s3StandaloneOptions.localFilerSocket = cmdS3.Flag.String("localFilerSocket", "", "local filer socket path") @@ -165,7 +167,13 @@ func runS3(cmd *Command, args []string) bool { util.LoadConfiguration("security", false) - go stats_collect.StartMetricsServer(*s3StandaloneOptions.bindIp, *s3StandaloneOptions.metricsHttpPort) + switch { + case *s3StandaloneOptions.metricsHttpIp != "": + // noting to do, use s3StandaloneOptions.metricsHttpIp + case *s3StandaloneOptions.bindIp != "": + *s3StandaloneOptions.metricsHttpIp = *s3StandaloneOptions.bindIp + } + go stats_collect.StartMetricsServer(*s3StandaloneOptions.metricsHttpIp, *s3StandaloneOptions.metricsHttpPort) return s3StandaloneOptions.startS3Server() diff --git a/weed/command/server.go b/weed/command/server.go index 87a5defe2..64bd935db 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -66,6 +66,7 @@ var ( volumeMinFreeSpacePercent = cmdServer.Flag.String("volume.minFreeSpacePercent", "1", "minimum free disk space (default to 1%). Low disk space will mark all volumes as ReadOnly (deprecated, use minFreeSpace instead).") volumeMinFreeSpace = cmdServer.Flag.String("volume.minFreeSpace", "", "min free disk space (value<=100 as percentage like 1, other as human readable bytes, like 10GiB). Low disk space will mark all volumes as ReadOnly.") serverMetricsHttpPort = cmdServer.Flag.Int("metricsPort", 0, "Prometheus metrics listen port") + serverMetricsHttpIp = cmdServer.Flag.String("metricsIp", "", "metrics listen ip. If empty, default to same as -ip.bind option.") // pulseSeconds = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats") isStartingMasterServer = cmdServer.Flag.Bool("master", true, "whether to start master server") @@ -206,6 +207,10 @@ func runServer(cmd *Command, args []string) bool { serverBindIp = serverIp } + if *serverMetricsHttpIp == "" { + *serverMetricsHttpIp = *serverBindIp + } + // ip address masterOptions.ip = serverIp masterOptions.ipBind = serverBindIp @@ -244,7 +249,7 @@ func runServer(cmd *Command, args []string) bool { webdavOptions.filer = &filerAddress mqBrokerOptions.filerGroup = filerOptions.filerGroup - go stats_collect.StartMetricsServer(*serverBindIp, *serverMetricsHttpPort) + go stats_collect.StartMetricsServer(*serverMetricsHttpIp, *serverMetricsHttpPort) folders := strings.Split(*volumeDataFolders, ",") diff --git a/weed/command/volume.go b/weed/command/volume.go index 852989d1f..4bd7668d5 100644 --- a/weed/command/volume.go +++ b/weed/command/volume.go @@ -65,6 +65,7 @@ type VolumeServerOptions struct { pprof *bool preStopSeconds *int metricsHttpPort *int + metricsHttpIp *string // pulseSeconds *int inflightUploadDataTimeout *time.Duration hasSlowRead *bool @@ -99,6 +100,7 @@ func init() { v.concurrentDownloadLimitMB = cmdVolume.Flag.Int("concurrentDownloadLimitMB", 256, "limit total concurrent download size") v.pprof = cmdVolume.Flag.Bool("pprof", false, "enable pprof http handlers. precludes --memprofile and --cpuprofile") v.metricsHttpPort = cmdVolume.Flag.Int("metricsPort", 0, "Prometheus metrics listen port") + v.metricsHttpIp = cmdVolume.Flag.String("metricsIp", "", "metrics listen ip. If empty, default to same as -ip.bind option.") v.idxFolder = cmdVolume.Flag.String("dir.idx", "", "directory to store .idx files") v.inflightUploadDataTimeout = cmdVolume.Flag.Duration("inflightUploadDataTimeout", 60*time.Second, "inflight upload data wait timeout of volume servers") v.hasSlowRead = cmdVolume.Flag.Bool("hasSlowRead", true, " if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.") @@ -131,7 +133,15 @@ func runVolume(cmd *Command, args []string) bool { grace.SetupProfiling(*v.cpuProfile, *v.memProfile) } - go stats_collect.StartMetricsServer(*v.bindIp, *v.metricsHttpPort) + switch { + case *v.metricsHttpIp != "": + // noting to do, use v.metricsHttpIp + case *v.bindIp != "": + *v.metricsHttpIp = *v.bindIp + case *v.ip != "": + *v.metricsHttpIp = *v.ip + } + go stats_collect.StartMetricsServer(*v.metricsHttpIp, *v.metricsHttpPort) minFreeSpaces := util.MustParseMinFreeSpace(*minFreeSpace, *minFreeSpacePercent) v.masters = pb.ServerAddresses(*v.mastersString).ToAddresses()