mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(flashnode): code check#23131609
Signed-off-by: clinx <chenlin1@oppo.com>
This commit is contained in:
parent
19e4fdc075
commit
c3b9145631
@ -26,7 +26,6 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/flashnode"
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/util"
|
||||
"github.com/cubefs/cubefs/util/auditlog"
|
||||
@ -579,8 +578,8 @@ func (cb *CacheBlock) InitForCacheRead(sources []*proto.DataSource, readDataNode
|
||||
return e
|
||||
}
|
||||
offset += size
|
||||
flashnode.UpdateWriteBytesMetric(uint64(size), cb.GetRootPath())
|
||||
flashnode.UpdateWriteCountMetric(cb.GetRootPath())
|
||||
updateWriteBytesMetric(uint64(size), cb.GetRootPath())
|
||||
updateWriteCountMetric(cb.GetRootPath())
|
||||
return nil
|
||||
}
|
||||
logPrefix := func() string {
|
||||
|
||||
24
flashnode/cachengine/stat.go
Normal file
24
flashnode/cachengine/stat.go
Normal file
@ -0,0 +1,24 @@
|
||||
package cachengine
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
var StatMap = make(map[string]*MetricStat)
|
||||
|
||||
type MetricStat struct {
|
||||
ReadBytes uint64
|
||||
ReadCount uint64
|
||||
WriteBytes uint64
|
||||
WriteCount uint64
|
||||
}
|
||||
|
||||
func updateWriteBytesMetric(size uint64, d string) {
|
||||
if stat, ok := StatMap[d]; ok {
|
||||
atomic.AddUint64(&stat.WriteBytes, size)
|
||||
}
|
||||
}
|
||||
|
||||
func updateWriteCountMetric(d string) {
|
||||
if stat, ok := StatMap[d]; ok {
|
||||
atomic.AddUint64(&stat.WriteCount, 1)
|
||||
}
|
||||
}
|
||||
@ -224,8 +224,8 @@ func (f *FlashNode) doStreamReadRequest(ctx context.Context, conn net.Conn, req
|
||||
if err != nil {
|
||||
log.LogWarnf("%s cache block(%v) err:%v", action, block.String(), err)
|
||||
} else {
|
||||
UpdateReadCountMetric(block.GetRootPath())
|
||||
UpdateReadBytesMetric(req.Size_, block.GetRootPath())
|
||||
f.metrics.updateReadCountMetric(block.GetRootPath())
|
||||
f.metrics.updateReadBytesMetric(req.Size_, block.GetRootPath())
|
||||
}
|
||||
}()
|
||||
for needReplySize > 0 {
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package flashnode
|
||||
|
||||
import (
|
||||
"github.com/cubefs/cubefs/flashnode/cachengine"
|
||||
"path"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/flashnode/cachengine"
|
||||
"github.com/cubefs/cubefs/util/exporter"
|
||||
"github.com/cubefs/cubefs/util/log"
|
||||
)
|
||||
@ -20,15 +20,6 @@ const (
|
||||
MetricFlashNodeEvictCount = "flashNodeEvictCount"
|
||||
)
|
||||
|
||||
var StatMap = make(map[string]*MetricStat)
|
||||
|
||||
type MetricStat struct {
|
||||
ReadBytes uint64
|
||||
ReadCount uint64
|
||||
WriteBytes uint64
|
||||
WriteCount uint64
|
||||
}
|
||||
|
||||
type FlashNodeMetrics struct {
|
||||
flashNode *FlashNode
|
||||
stopC chan struct{}
|
||||
@ -53,7 +44,7 @@ func (f *FlashNode) registerMetrics(disks []*cachengine.Disk) {
|
||||
f.metrics.MetricEvictCount = exporter.NewGauge(MetricFlashNodeEvictCount)
|
||||
f.metrics.MetricHitRate = exporter.NewGauge(MetricFlashNodeHitRate)
|
||||
for _, d := range disks {
|
||||
StatMap[path.Join(d.Path, cachengine.DefaultCacheDirName)] = new(MetricStat)
|
||||
cachengine.StatMap[path.Join(d.Path, cachengine.DefaultCacheDirName)] = new(cachengine.MetricStat)
|
||||
}
|
||||
|
||||
log.LogInfof("registerMetrics")
|
||||
@ -90,28 +81,28 @@ func (fm *FlashNodeMetrics) doStat() {
|
||||
}
|
||||
|
||||
func (fm *FlashNodeMetrics) setReadBytesMetric() {
|
||||
for d, stat := range StatMap {
|
||||
for d, stat := range cachengine.StatMap {
|
||||
readBytes := atomic.SwapUint64(&stat.ReadBytes, 0)
|
||||
fm.MetricReadBytes.SetWithLabels(float64(readBytes), map[string]string{"cluster": fm.flashNode.clusterID, exporter.FlashNode: fm.flashNode.localAddr, exporter.Disk: d})
|
||||
}
|
||||
}
|
||||
|
||||
func (fm *FlashNodeMetrics) setReadCountMetric() {
|
||||
for d, stat := range StatMap {
|
||||
for d, stat := range cachengine.StatMap {
|
||||
readCount := atomic.SwapUint64(&stat.ReadCount, 0)
|
||||
fm.MetricReadCount.SetWithLabels(float64(readCount), map[string]string{"cluster": fm.flashNode.clusterID, exporter.FlashNode: fm.flashNode.localAddr, exporter.Disk: d})
|
||||
}
|
||||
}
|
||||
|
||||
func (fm *FlashNodeMetrics) setWriteBytesMetric() {
|
||||
for d, stat := range StatMap {
|
||||
for d, stat := range cachengine.StatMap {
|
||||
writeBytes := atomic.SwapUint64(&stat.WriteBytes, 0)
|
||||
fm.MetricWriteBytes.SetWithLabels(float64(writeBytes), map[string]string{"cluster": fm.flashNode.clusterID, exporter.FlashNode: fm.flashNode.localAddr, exporter.Disk: d})
|
||||
}
|
||||
}
|
||||
|
||||
func (fm *FlashNodeMetrics) setWriteCountMetric() {
|
||||
for d, stat := range StatMap {
|
||||
for d, stat := range cachengine.StatMap {
|
||||
writeCount := atomic.SwapUint64(&stat.WriteCount, 0)
|
||||
fm.MetricWriteCount.SetWithLabels(float64(writeCount), map[string]string{"cluster": fm.flashNode.clusterID, exporter.FlashNode: fm.flashNode.localAddr, exporter.Disk: d})
|
||||
}
|
||||
@ -131,26 +122,14 @@ func (fm *FlashNodeMetrics) setHitRateMetric() {
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateReadBytesMetric(size uint64, d string) {
|
||||
if stat, ok := StatMap[d]; ok {
|
||||
func (fm *FlashNodeMetrics) updateReadBytesMetric(size uint64, d string) {
|
||||
if stat, ok := cachengine.StatMap[d]; ok {
|
||||
atomic.AddUint64(&stat.ReadBytes, size)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateReadCountMetric(d string) {
|
||||
if stat, ok := StatMap[d]; ok {
|
||||
func (fm *FlashNodeMetrics) updateReadCountMetric(d string) {
|
||||
if stat, ok := cachengine.StatMap[d]; ok {
|
||||
atomic.AddUint64(&stat.ReadCount, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateWriteBytesMetric(size uint64, d string) {
|
||||
if stat, ok := StatMap[d]; ok {
|
||||
atomic.AddUint64(&stat.WriteBytes, size)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateWriteCountMetric(d string) {
|
||||
if stat, ok := StatMap[d]; ok {
|
||||
atomic.AddUint64(&stat.WriteCount, 1)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user