From 9956d93a4023874505eb6e531f930199fa7f3820 Mon Sep 17 00:00:00 2001 From: Dmitry Mishin Date: Mon, 21 Aug 2023 11:37:27 -0700 Subject: [PATCH 1/2] Add disk type to prometheus metrics (#4736) * Add disk type to prometheus metrics * Del metrics * Disk type as readable string --------- Co-authored-by: Dima Mishin --- weed/stats/metrics.go | 8 +++----- weed/storage/erasure_coding/ec_shard.go | 6 ++++-- weed/storage/volume.go | 2 +- weed/storage/volume_loading.go | 2 +- weed/storage/volume_vacuum.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index dda4d95e5..af4f26e4c 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -176,7 +176,7 @@ var ( Subsystem: "volumeServer", Name: "volumes", Help: "Number of volumes or shards.", - }, []string{"collection", "type"}) + }, []string{"collection", "type", "disk"}) VolumeServerReadOnlyVolumeGauge = prometheus.NewGaugeVec( prometheus.GaugeOpts{ @@ -299,7 +299,6 @@ func JoinHostPort(host string, port int) string { return net.JoinHostPort(host, portStr) } - func StartMetricsServer(ip string, port int) { if port == 0 { return @@ -316,11 +315,10 @@ func SourceName(port uint32) string { return net.JoinHostPort(hostname, strconv.Itoa(int(port))) } -// todo - can be changed to DeletePartialMatch when https://github.com/prometheus/client_golang/pull/1013 gets released func DeleteCollectionMetrics(collection string) { VolumeServerDiskSizeGauge.DeleteLabelValues(collection, "normal") for _, volume_type := range readOnlyVolumeTypes { - VolumeServerReadOnlyVolumeGauge.DeleteLabelValues(collection, volume_type) + VolumeServerReadOnlyVolumeGauge.DeletePartialMatch(prometheus.Labels{"collection": collection, "type": volume_type}) } - VolumeServerVolumeCounter.DeleteLabelValues(collection, "volume") + VolumeServerVolumeCounter.DeletePartialMatch(prometheus.Labels{"collection": collection, "type": "volume"}) } diff --git a/weed/storage/erasure_coding/ec_shard.go b/weed/storage/erasure_coding/ec_shard.go index 19ee17636..85694e63b 100644 --- a/weed/storage/erasure_coding/ec_shard.go +++ b/weed/storage/erasure_coding/ec_shard.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" + "github.com/seaweedfs/seaweedfs/weed/storage/types" + "github.com/seaweedfs/seaweedfs/weed/stats" "github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/storage/types" @@ -44,7 +46,7 @@ func NewEcVolumeShard(diskType types.DiskType, dirname string, collection string } v.ecdFileSize = ecdFi.Size() - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "ec_shards").Inc() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "ec_shards", string(v.DiskType)).Inc() return } @@ -88,7 +90,7 @@ func (shard *EcVolumeShard) Close() { func (shard *EcVolumeShard) Destroy() { os.Remove(shard.FileName() + ToExt(int(shard.ShardId))) - stats.VolumeServerVolumeCounter.WithLabelValues(shard.Collection, "ec_shards").Dec() + stats.VolumeServerVolumeCounter.WithLabelValues(shard.Collection, "ec_shards", string(shard.DiskType)).Dec() } func (shard *EcVolumeShard) ReadAt(buf []byte, offset int64) (int, error) { diff --git a/weed/storage/volume.go b/weed/storage/volume.go index 232930b80..8530bc2e7 100644 --- a/weed/storage/volume.go +++ b/weed/storage/volume.go @@ -246,7 +246,7 @@ func (v *Volume) doClose() { glog.Warningf("Volume Close fail to sync volume %d", v.Id) } v.DataBackend = nil - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Dec() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume", v.DiskType().ReadableString()).Dec() } } diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index 78dfa6901..e7018d52c 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -201,7 +201,7 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind } } - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Inc() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume", v.DiskType().ReadableString()).Inc() if err == nil { hasLoadedVolume = true diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index 0eaca5ff4..9e5993a82 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -124,7 +124,7 @@ func (v *Volume) CommitCompact() error { } } v.DataBackend = nil - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Dec() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume", v.DiskType().ReadableString()).Dec() var e error if e = v.makeupDiff(v.FileName(".cpd"), v.FileName(".cpx"), v.FileName(".dat"), v.FileName(".idx")); e != nil { From 9215ba24be0aec0c5804927cc73613560e57cbc0 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 21 Aug 2023 11:38:12 -0700 Subject: [PATCH 2/2] Revert "Add disk type to prometheus metrics" (#4777) Revert "Add disk type to prometheus metrics (#4736)" This reverts commit 9956d93a4023874505eb6e531f930199fa7f3820. --- weed/stats/metrics.go | 8 +++++--- weed/storage/erasure_coding/ec_shard.go | 6 ++---- weed/storage/volume.go | 2 +- weed/storage/volume_loading.go | 2 +- weed/storage/volume_vacuum.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index af4f26e4c..dda4d95e5 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -176,7 +176,7 @@ var ( Subsystem: "volumeServer", Name: "volumes", Help: "Number of volumes or shards.", - }, []string{"collection", "type", "disk"}) + }, []string{"collection", "type"}) VolumeServerReadOnlyVolumeGauge = prometheus.NewGaugeVec( prometheus.GaugeOpts{ @@ -299,6 +299,7 @@ func JoinHostPort(host string, port int) string { return net.JoinHostPort(host, portStr) } + func StartMetricsServer(ip string, port int) { if port == 0 { return @@ -315,10 +316,11 @@ func SourceName(port uint32) string { return net.JoinHostPort(hostname, strconv.Itoa(int(port))) } +// todo - can be changed to DeletePartialMatch when https://github.com/prometheus/client_golang/pull/1013 gets released func DeleteCollectionMetrics(collection string) { VolumeServerDiskSizeGauge.DeleteLabelValues(collection, "normal") for _, volume_type := range readOnlyVolumeTypes { - VolumeServerReadOnlyVolumeGauge.DeletePartialMatch(prometheus.Labels{"collection": collection, "type": volume_type}) + VolumeServerReadOnlyVolumeGauge.DeleteLabelValues(collection, volume_type) } - VolumeServerVolumeCounter.DeletePartialMatch(prometheus.Labels{"collection": collection, "type": "volume"}) + VolumeServerVolumeCounter.DeleteLabelValues(collection, "volume") } diff --git a/weed/storage/erasure_coding/ec_shard.go b/weed/storage/erasure_coding/ec_shard.go index 85694e63b..19ee17636 100644 --- a/weed/storage/erasure_coding/ec_shard.go +++ b/weed/storage/erasure_coding/ec_shard.go @@ -7,8 +7,6 @@ import ( "strconv" "strings" - "github.com/seaweedfs/seaweedfs/weed/storage/types" - "github.com/seaweedfs/seaweedfs/weed/stats" "github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/storage/types" @@ -46,7 +44,7 @@ func NewEcVolumeShard(diskType types.DiskType, dirname string, collection string } v.ecdFileSize = ecdFi.Size() - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "ec_shards", string(v.DiskType)).Inc() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "ec_shards").Inc() return } @@ -90,7 +88,7 @@ func (shard *EcVolumeShard) Close() { func (shard *EcVolumeShard) Destroy() { os.Remove(shard.FileName() + ToExt(int(shard.ShardId))) - stats.VolumeServerVolumeCounter.WithLabelValues(shard.Collection, "ec_shards", string(shard.DiskType)).Dec() + stats.VolumeServerVolumeCounter.WithLabelValues(shard.Collection, "ec_shards").Dec() } func (shard *EcVolumeShard) ReadAt(buf []byte, offset int64) (int, error) { diff --git a/weed/storage/volume.go b/weed/storage/volume.go index 8530bc2e7..232930b80 100644 --- a/weed/storage/volume.go +++ b/weed/storage/volume.go @@ -246,7 +246,7 @@ func (v *Volume) doClose() { glog.Warningf("Volume Close fail to sync volume %d", v.Id) } v.DataBackend = nil - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume", v.DiskType().ReadableString()).Dec() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Dec() } } diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index e7018d52c..78dfa6901 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -201,7 +201,7 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind } } - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume", v.DiskType().ReadableString()).Inc() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Inc() if err == nil { hasLoadedVolume = true diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index 9e5993a82..0eaca5ff4 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -124,7 +124,7 @@ func (v *Volume) CommitCompact() error { } } v.DataBackend = nil - stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume", v.DiskType().ReadableString()).Dec() + stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Dec() var e error if e = v.makeupDiff(v.FileName(".cpd"), v.FileName(".cpx"), v.FileName(".dat"), v.FileName(".idx")); e != nil {