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
supports stats
chrislu9a913457ddbb
diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.goindex 68054667f9..75a509b5c7 100644--- a/weed/mount/weedfs.go+++ b/weed/mount/weedfs.go@@ -55,6 +55,7 @@ type WFS struct {fs.Inodeoption *OptionmetaCache *meta_cache.MetaCache+ stats statsCachesignature int32}diff --git a/weed/mount/weedfs_stats.go b/weed/mount/weedfs_stats.gonew file mode 100644index 0000000000..fc24db0e2b--- /dev/null+++ b/weed/mount/weedfs_stats.go@@ -0,0 +1,85 @@+package mount++import (+ "context"+ "fmt"+ "github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"+ "github.com/hanwen/go-fuse/v2/fs"+ "github.com/hanwen/go-fuse/v2/fuse"+ "math"+ "os"+ "syscall"+ "time"+)++const blockSize = 512++var _ = fs.NodeStatfser(&WFS{})++type statsCache struct {+ filer_pb.StatisticsResponse+ lastChecked int64 // unix time in seconds+}++func (wfs *WFS) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall.Errno {++ glog.V(4).Infof("reading fs stats")++ if wfs.stats.lastChecked < time.Now().Unix()-20 {++ err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {++ request := &filer_pb.StatisticsRequest{+ Collection: wfs.option.Collection,+ Replication: wfs.option.Replication,+ Ttl: fmt.Sprintf("%ds", wfs.option.TtlSec),+ DiskType: string(wfs.option.DiskType),+ }++ glog.V(4).Infof("reading filer stats: %+v", request)+ resp, err := client.Statistics(context.Background(), request)+ if err != nil {+ glog.V(0).Infof("reading filer stats %v: %v", request, err)+ return err+ }+ glog.V(4).Infof("read filer stats: %+v", resp)++ wfs.stats.TotalSize = resp.TotalSize+ wfs.stats.UsedSize = resp.UsedSize+ wfs.stats.FileCount = resp.FileCount+ wfs.stats.lastChecked = time.Now().Unix()++ return nil+ })+ if err != nil {+ glog.V(0).Infof("filer Statistics: %v", err)+ return fs.ToErrno(os.ErrInvalid)+ }+ }++ totalDiskSize := wfs.stats.TotalSize+ usedDiskSize := wfs.stats.UsedSize+ actualFileCount := wfs.stats.FileCount++ // Compute the total number of available blocks+ out.Blocks = totalDiskSize / blockSize++ // Compute the number of used blocks+ numBlocks := uint64(usedDiskSize / blockSize)++ // Report the number of free and available blocks for the block size+ out.Bfree = out.Blocks - numBlocks+ out.Bavail = out.Blocks - numBlocks+ out.Bsize = uint32(blockSize)++ // Report the total number of possible files in the file system (and those free)+ out.Files = math.MaxInt64+ out.Ffree = math.MaxInt64 - actualFileCount++ // Report the maximum length of a name and the minimum fragment size+ out.NameLen = 1024+ out.Frsize = uint32(blockSize)++ return fs.OK+}diff --git a/weed/mount/wfs_filer_client.go b/weed/mount/wfs_filer_client.gonew file mode 100644index 0000000000..e8feb83423--- /dev/null+++ b/weed/mount/wfs_filer_client.go@@ -0,0 +1,51 @@+package mount++import (+ "github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/chrislusf/seaweedfs/weed/util"+ "google.golang.org/grpc"++ "github.com/chrislusf/seaweedfs/weed/pb"+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"+)++var _ = filer_pb.FilerClient(&WFS{})++func (wfs *WFS) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) (err error) {++ return util.Retry("filer grpc", func() error {++ i := wfs.option.filerIndex+ n := len(wfs.option.FilerAddresses)+ for x := 0; x < n; x++ {++ filerGrpcAddress := wfs.option.FilerAddresses[i].ToGrpcAddress()+ err = pb.WithGrpcClient(streamingMode, func(grpcConnection *grpc.ClientConn) error {+ client := filer_pb.NewSeaweedFilerClient(grpcConnection)+ return fn(client)+ }, filerGrpcAddress, wfs.option.GrpcDialOption)++ if err != nil {+ glog.V(0).Infof("WithFilerClient %d %v: %v", x, filerGrpcAddress, err)+ } else {+ wfs.option.filerIndex = i+ return nil+ }++ i+++ if i >= n {+ i = 0+ }++ }+ return err+ })++}++func (wfs *WFS) AdjustedUrl(location *filer_pb.Location) string {+ if wfs.option.VolumeServerAccess == "publicUrl" {+ return location.PublicUrl+ }+ return location.Url+}