SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
refactoring
Chris Lu5336008dcd29
diff --git a/weed/server/filer_server.go b/weed/server/filer_server.goindex 9cd425981b..1670d70b3f 100644--- a/weed/server/filer_server.go+++ b/weed/server/filer_server.go@@ -3,11 +3,8 @@ package weed_serverimport ("net/http""os"- "time""github.com/chrislusf/seaweedfs/weed/util"- "github.com/prometheus/client_golang/prometheus"- "github.com/prometheus/client_golang/prometheus/push""google.golang.org/grpc""github.com/chrislusf/seaweedfs/weed/filer2"@@ -93,24 +90,3 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)return fs, nil}-func startPushingMetric(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {- if intervalSeconds == 0 || addr == "" {- glog.V(0).Info("disable metrics reporting")- return- }- glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)- go loopPushMetrics(name, gatherer, addr, intervalSeconds)-}--func loopPushMetrics(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {-- pusher := push.New(addr, name).Gatherer(gatherer)-- for {- err := pusher.Push()- if err != nil {- glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)- }- time.Sleep(time.Duration(intervalSeconds) * time.Second)- }-}diff --git a/weed/server/metrics.go b/weed/server/metrics.goindex 0bee27d22f..3f4be1a7d8 100644--- a/weed/server/metrics.go+++ b/weed/server/metrics.go@@ -1,6 +1,12 @@package weed_server-import "github.com/prometheus/client_golang/prometheus"+import (+ "time"++ "github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/prometheus/client_golang/prometheus"+ "github.com/prometheus/client_golang/prometheus/push"+)var (filerGather = prometheus.NewRegistry()@@ -31,7 +37,7 @@ var (Help: "Counter of filer requests.",}, []string{"type"})- volumeServerHistogram = prometheus.NewHistogramVec(+ volumeServerRequestHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{Namespace: "SeaweedFS",Subsystem: "volumeServer",@@ -39,6 +45,15 @@ var (Help: "Bucketed histogram of filer request processing time.",Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),}, []string{"type"})++ volumeServerVolumeCounter = prometheus.NewGauge(+ prometheus.GaugeOpts{+ Namespace: "SeaweedFS",+ Subsystem: "volumeServer",+ Name: "volumes",+ Help: "Number of volumes.",+ })+)func init() {@@ -47,6 +62,28 @@ func init() {filerGather.MustRegister(filerRequestHistogram)volumeServerGather.MustRegister(volumeServerRequestCounter)- volumeServerGather.MustRegister(volumeServerHistogram)+ volumeServerGather.MustRegister(volumeServerRequestHistogram)++}++func startPushingMetric(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {+ if intervalSeconds == 0 || addr == "" {+ glog.V(0).Info("disable metrics reporting")+ return+ }+ glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)+ go loopPushMetrics(name, gatherer, addr, intervalSeconds)+}++func loopPushMetrics(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {++ pusher := push.New(addr, name).Gatherer(gatherer)+ for {+ err := pusher.Push()+ if err != nil {+ glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)+ }+ time.Sleep(time.Duration(intervalSeconds) * time.Second)+ }}diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.goindex 5e8bc74690..18c3152572 100644--- a/weed/server/volume_server_handlers_read.go+++ b/weed/server/volume_server_handlers_read.go@@ -29,7 +29,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)volumeServerRequestCounter.WithLabelValues("get").Inc()start := time.Now()- defer func() { volumeServerHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds()) }()+ defer func() { volumeServerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds()) }()n := new(needle.Needle)vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)diff --git a/weed/server/volume_server_handlers_write.go b/weed/server/volume_server_handlers_write.goindex b53defd26e..eb76e44148 100644--- a/weed/server/volume_server_handlers_write.go+++ b/weed/server/volume_server_handlers_write.go@@ -18,7 +18,7 @@ func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {volumeServerRequestCounter.WithLabelValues("post").Inc()start := time.Now()- defer func() { volumeServerHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds()) }()+ defer func() { volumeServerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds()) }()if e := r.ParseForm(); e != nil {glog.V(0).Infoln("form parse error:", e)@@ -68,7 +68,7 @@ func (vs *VolumeServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {volumeServerRequestCounter.WithLabelValues("delete").Inc()start := time.Now()- defer func() { volumeServerHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds()) }()+ defer func() { volumeServerRequestHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds()) }()n := new(needle.Needle)vid, fid, _, _, _ := parseURLPath(r.URL.Path)