count number of volumes and ec shards

This commit is contained in:
Chris Lu 2019-06-16 02:24:15 -07:00
parent ff6a6dd11e
commit 289fd7eb39
5 changed files with 20 additions and 0 deletions

View File

@ -55,6 +55,14 @@ var (
Name: "volumes", Name: "volumes",
Help: "Number of volumes.", Help: "Number of volumes.",
}) })
VolumeServerEcShardCounter = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "SeaweedFS",
Subsystem: "volumeServer",
Name: "ecShards",
Help: "Number of EC shards.",
})
) )
func init() { func init() {
@ -65,6 +73,7 @@ func init() {
VolumeServerGather.MustRegister(VolumeServerRequestCounter) VolumeServerGather.MustRegister(VolumeServerRequestCounter)
VolumeServerGather.MustRegister(VolumeServerRequestHistogram) VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
VolumeServerGather.MustRegister(VolumeServerVolumeCounter) VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
VolumeServerGather.MustRegister(VolumeServerEcShardCounter)
} }

View File

@ -6,6 +6,7 @@ import (
"path" "path"
"strconv" "strconv"
"github.com/chrislusf/seaweedfs/weed/stats"
"github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/needle"
) )
@ -36,6 +37,8 @@ func NewEcVolumeShard(dirname string, collection string, id needle.VolumeId, sha
} }
v.ecdFileSize = ecdFi.Size() v.ecdFileSize = ecdFi.Size()
stats.VolumeServerEcShardCounter.Inc()
return return
} }
@ -78,6 +81,7 @@ func (shard *EcVolumeShard) Close() {
func (shard *EcVolumeShard) Destroy() { func (shard *EcVolumeShard) Destroy() {
os.Remove(shard.FileName() + ToExt(int(shard.ShardId))) os.Remove(shard.FileName() + ToExt(int(shard.ShardId)))
stats.VolumeServerEcShardCounter.Dec()
} }
func (shard *EcVolumeShard) ReadAt(buf []byte, offset int64) (int, error) { func (shard *EcVolumeShard) ReadAt(buf []byte, offset int64) (int, error) {

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"github.com/chrislusf/seaweedfs/weed/stats"
"github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/needle"
"os" "os"
@ -102,6 +103,7 @@ func (v *Volume) Close() {
if v.dataFile != nil { if v.dataFile != nil {
_ = v.dataFile.Close() _ = v.dataFile.Close()
v.dataFile = nil v.dataFile = nil
stats.VolumeServerVolumeCounter.Dec()
} }
} }

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"time" "time"
"github.com/chrislusf/seaweedfs/weed/stats"
"github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/needle"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
@ -116,6 +117,8 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind
} }
} }
stats.VolumeServerVolumeCounter.Inc()
return e return e
} }

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/stats"
idx2 "github.com/chrislusf/seaweedfs/weed/storage/idx" idx2 "github.com/chrislusf/seaweedfs/weed/storage/idx"
"github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/needle"
. "github.com/chrislusf/seaweedfs/weed/storage/types" . "github.com/chrislusf/seaweedfs/weed/storage/types"
@ -52,6 +53,7 @@ func (v *Volume) CommitCompact() error {
glog.V(0).Infof("fail to close volume %d", v.Id) glog.V(0).Infof("fail to close volume %d", v.Id)
} }
v.dataFile = nil v.dataFile = nil
stats.VolumeServerVolumeCounter.Dec()
var e error var e error
if e = v.makeupDiff(v.FileName()+".cpd", v.FileName()+".cpx", v.FileName()+".dat", v.FileName()+".idx"); e != nil { if e = v.makeupDiff(v.FileName()+".cpd", v.FileName()+".cpx", v.FileName()+".dat", v.FileName()+".idx"); e != nil {