diff --git a/weed/command/filer.go b/weed/command/filer.go index 96df0d7dd..7ff9fcd9a 100644 --- a/weed/command/filer.go +++ b/weed/command/filer.go @@ -13,6 +13,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/security" "github.com/chrislusf/seaweedfs/weed/server" + stats_collect "github.com/chrislusf/seaweedfs/weed/stats" "github.com/chrislusf/seaweedfs/weed/util" ) @@ -86,6 +87,8 @@ func runFiler(cmd *Command, args []string) bool { util.LoadConfiguration("security", false) + go stats_collect.StartMetricsServer(*f.metricsHttpPort) + f.startFiler() return true @@ -124,7 +127,6 @@ func (fo *FilerOptions) startFiler() { Port: uint32(*fo.port), Cipher: *fo.cipher, Filers: peers, - MetricsHttpPort: *fo.metricsHttpPort, }) if nfs_err != nil { glog.Fatalf("Filer startup error: %v", nfs_err) diff --git a/weed/command/s3.go b/weed/command/s3.go index fb09731fa..e94decaf3 100644 --- a/weed/command/s3.go +++ b/weed/command/s3.go @@ -115,6 +115,8 @@ func runS3(cmd *Command, args []string) bool { util.LoadConfiguration("security", false) + go stats_collect.StartMetricsServer(*s3StandaloneOptions.metricsHttpPort) + return s3StandaloneOptions.startS3Server() } @@ -155,8 +157,7 @@ func (s3opt *S3Options) startS3Server() bool { } } - go stats_collect.StartMetricsServer(stats_collect.S3Gather, *s3opt.metricsHttpPort) - go stats_collect.LoopPushingMetric("s3", stats_collect.SourceName(uint32(*s3opt.port)), stats_collect.S3Gather, metricsAddress, metricsIntervalSec) + go stats_collect.LoopPushingMetric("s3", stats_collect.SourceName(uint32(*s3opt.port)), metricsAddress, metricsIntervalSec) router := mux.NewRouter().SkipClean(true) diff --git a/weed/command/server.go b/weed/command/server.go index 6f671363c..91d8d22c6 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -2,6 +2,7 @@ package command import ( "fmt" + stats_collect "github.com/chrislusf/seaweedfs/weed/stats" "os" "runtime" "runtime/pprof" @@ -151,11 +152,6 @@ func runServer(cmd *Command, args []string) bool { serverOptions.v.rack = serverRack msgBrokerOptions.ip = serverIp - // metrics port - filerOptions.metricsHttpPort = serverMetricsHttpPort - serverOptions.v.metricsHttpPort = serverMetricsHttpPort - s3Options.metricsHttpPort = serverMetricsHttpPort - // serverOptions.v.pulseSeconds = pulseSeconds // masterOptions.pulseSeconds = pulseSeconds @@ -174,6 +170,7 @@ func runServer(cmd *Command, args []string) bool { } runtime.GOMAXPROCS(runtime.NumCPU()) + go stats_collect.StartMetricsServer(*serverMetricsHttpPort) folders := strings.Split(*volumeDataFolders, ",") diff --git a/weed/command/volume.go b/weed/command/volume.go index 82f2658c3..dfc649ba5 100644 --- a/weed/command/volume.go +++ b/weed/command/volume.go @@ -25,6 +25,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" "github.com/chrislusf/seaweedfs/weed/server" + stats_collect "github.com/chrislusf/seaweedfs/weed/stats" "github.com/chrislusf/seaweedfs/weed/storage" "github.com/chrislusf/seaweedfs/weed/util" ) @@ -111,6 +112,8 @@ func runVolume(cmd *Command, args []string) bool { grace.SetupProfiling(*v.cpuProfile, *v.memProfile) } + go stats_collect.StartMetricsServer(*v.metricsHttpPort) + v.startVolumeServer(*volumeFolders, *maxVolumeCounts, *volumeWhiteListOption, *minFreeSpacePercent) return true @@ -209,7 +212,6 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v *v.fixJpgOrientation, *v.readRedirect, *v.compactionMBPerSecond, *v.fileSizeLimitMB, - *v.metricsHttpPort, ) // starting grpc server grpcS := v.startGrpcService(volumeServer) diff --git a/weed/server/filer_server.go b/weed/server/filer_server.go index de271a483..ec0a4fb3e 100644 --- a/weed/server/filer_server.go +++ b/weed/server/filer_server.go @@ -54,7 +54,6 @@ type FilerOption struct { recursiveDelete bool Cipher bool Filers []string - MetricsHttpPort int } type FilerServer struct { @@ -158,8 +157,7 @@ func (fs *FilerServer) maybeStartMetrics() { } } - go stats.StartMetricsServer(stats.FilerGather, fs.option.MetricsHttpPort) - go stats.LoopPushingMetric("filer", stats.SourceName(fs.option.Port), stats.FilerGather, fs.metricsAddress, fs.metricsIntervalSec) + go stats.LoopPushingMetric("filer", stats.SourceName(fs.option.Port), fs.metricsAddress, fs.metricsIntervalSec) } func readFilerConfiguration(grpcDialOption grpc.DialOption, masterAddress string) (metricsAddress string, metricsIntervalSec int, err error) { diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go index 2a9097f01..83df32fdd 100644 --- a/weed/server/volume_server.go +++ b/weed/server/volume_server.go @@ -46,7 +46,6 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, readRedirect bool, compactionMBPerSecond int, fileSizeLimitMB int, - metricsHttpPort int, ) *VolumeServer { v := util.GetViper() @@ -98,8 +97,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, } go vs.heartbeat() - go stats.StartMetricsServer(stats.VolumeServerGather, metricsHttpPort) - go stats.LoopPushingMetric("volumeServer", fmt.Sprintf("%s:%d", ip, port), stats.VolumeServerGather, vs.metricsAddress, vs.metricsIntervalSec) + go stats.LoopPushingMetric("volumeServer", fmt.Sprintf("%s:%d", ip, port), vs.metricsAddress, vs.metricsIntervalSec) return vs } diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index 5326622bd..d930caf0f 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -16,9 +16,7 @@ import ( ) var ( - FilerGather = prometheus.NewRegistry() - VolumeServerGather = prometheus.NewRegistry() - S3Gather = prometheus.NewRegistry() + Gather = prometheus.NewRegistry() FilerRequestCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -114,23 +112,23 @@ var ( func init() { - FilerGather.MustRegister(FilerRequestCounter) - FilerGather.MustRegister(FilerRequestHistogram) - FilerGather.MustRegister(FilerStoreCounter) - FilerGather.MustRegister(FilerStoreHistogram) - FilerGather.MustRegister(prometheus.NewGoCollector()) + Gather.MustRegister(FilerRequestCounter) + Gather.MustRegister(FilerRequestHistogram) + Gather.MustRegister(FilerStoreCounter) + Gather.MustRegister(FilerStoreHistogram) + Gather.MustRegister(prometheus.NewGoCollector()) - VolumeServerGather.MustRegister(VolumeServerRequestCounter) - VolumeServerGather.MustRegister(VolumeServerRequestHistogram) - VolumeServerGather.MustRegister(VolumeServerVolumeCounter) - VolumeServerGather.MustRegister(VolumeServerMaxVolumeCounter) - VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge) + Gather.MustRegister(VolumeServerRequestCounter) + Gather.MustRegister(VolumeServerRequestHistogram) + Gather.MustRegister(VolumeServerVolumeCounter) + Gather.MustRegister(VolumeServerMaxVolumeCounter) + Gather.MustRegister(VolumeServerDiskSizeGauge) - S3Gather.MustRegister(S3RequestCounter) - S3Gather.MustRegister(S3RequestHistogram) + Gather.MustRegister(S3RequestCounter) + Gather.MustRegister(S3RequestHistogram) } -func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) { +func LoopPushingMetric(name, instance, addr string, intervalSeconds int) { if addr == "" || intervalSeconds == 0 { return @@ -138,7 +136,7 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, add glog.V(0).Infof("%s server sends metrics to %s every %d seconds", name, addr, intervalSeconds) - pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance) + pusher := push.New(addr, name).Gatherer(Gather).Grouping("instance", instance) for { err := pusher.Push() @@ -153,11 +151,11 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, add } } -func StartMetricsServer(gatherer *prometheus.Registry, port int) { +func StartMetricsServer(port int) { if port == 0 { return } - http.Handle("/metrics", promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{})) + http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{})) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) }