Browse Source

修复servicestat功能

gitlink
Sydonian 7 months ago
parent
commit
15aae23806
3 changed files with 21 additions and 21 deletions
  1. +8
    -8
      common/pkgs/servicestats/hub_strorage_transfer.go
  2. +8
    -8
      common/pkgs/servicestats/hub_transfter.go
  3. +5
    -5
      common/pkgs/servicestats/service_stats.go

+ 8
- 8
common/pkgs/servicestats/hub_strorage_transfer.go View File

@@ -5,23 +5,23 @@ import (
"sync"
"time"

cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
"gitlink.org.cn/cloudream/common/utils/math2"
cortypes "gitlink.org.cn/cloudream/storage2/coordinator/types"
)

type HubStorageTransferStats struct {
data HubStorageTransferStatsData
fromHubID cdssdk.HubID
fromHubID cortypes.HubID
lock *sync.Mutex
}

type HubStorageTransferStatsData struct {
Entries map[cdssdk.StorageID]*HubStorageTransferStatsEntry
Entries map[cortypes.StorageID]*HubStorageTransferStatsEntry
StartTime time.Time
}

type HubStorageTransferStatsEntry struct {
DestStorageID cdssdk.StorageID
DestStorageID cortypes.StorageID

OutputBytes int64
MaxOutputBytes int64
@@ -36,7 +36,7 @@ type HubStorageTransferStatsEntry struct {
SuccessInput int64
}

func (s *HubStorageTransferStats) RecordUpload(dstStorageID cdssdk.StorageID, transferBytes int64, isSuccess bool) {
func (s *HubStorageTransferStats) RecordUpload(dstStorageID cortypes.StorageID, transferBytes int64, isSuccess bool) {
s.lock.Lock()
defer s.lock.Unlock()

@@ -58,7 +58,7 @@ func (s *HubStorageTransferStats) RecordUpload(dstStorageID cdssdk.StorageID, tr
e.TotalOutput++
}

func (s *HubStorageTransferStats) RecordDownload(dstStorageID cdssdk.StorageID, transferBytes int64, isSuccess bool) {
func (s *HubStorageTransferStats) RecordDownload(dstStorageID cortypes.StorageID, transferBytes int64, isSuccess bool) {
s.lock.Lock()
defer s.lock.Unlock()

@@ -83,7 +83,7 @@ func (s *HubStorageTransferStats) Reset() time.Time {
s.lock.Lock()
defer s.lock.Unlock()

s.data.Entries = make(map[cdssdk.StorageID]*HubStorageTransferStatsEntry)
s.data.Entries = make(map[cortypes.StorageID]*HubStorageTransferStatsEntry)
s.data.StartTime = time.Now()
return s.data.StartTime
}
@@ -93,7 +93,7 @@ func (s *HubStorageTransferStats) DumpData() HubStorageTransferStatsData {
defer s.lock.Unlock()

data := s.data
data.Entries = make(map[cdssdk.StorageID]*HubStorageTransferStatsEntry)
data.Entries = make(map[cortypes.StorageID]*HubStorageTransferStatsEntry)
for k, v := range s.data.Entries {
v2 := *v
data.Entries[k] = &v2


+ 8
- 8
common/pkgs/servicestats/hub_transfter.go View File

@@ -5,23 +5,23 @@ import (
"sync"
"time"

cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
"gitlink.org.cn/cloudream/common/utils/math2"
cortypes "gitlink.org.cn/cloudream/storage2/coordinator/types"
)

type HubTransferStats struct {
data HubTransferStatsData
fromHubID cdssdk.HubID
fromHubID cortypes.HubID
lock *sync.Mutex
}

type HubTransferStatsData struct {
Entries map[cdssdk.HubID]*HubTransferStatsEntry
Entries map[cortypes.HubID]*HubTransferStatsEntry
StartTime time.Time
}

type HubTransferStatsEntry struct {
DestHubID cdssdk.HubID
DestHubID cortypes.HubID

OutputBytes int64
MaxOutputBytes int64
@@ -36,7 +36,7 @@ type HubTransferStatsEntry struct {
SuccessInput int64
}

func (s *HubTransferStats) RecordOutput(dstHubID cdssdk.HubID, transferBytes int64, isSuccess bool) {
func (s *HubTransferStats) RecordOutput(dstHubID cortypes.HubID, transferBytes int64, isSuccess bool) {
s.lock.Lock()
defer s.lock.Unlock()

@@ -58,7 +58,7 @@ func (s *HubTransferStats) RecordOutput(dstHubID cdssdk.HubID, transferBytes int
e.TotalOutput++
}

func (s *HubTransferStats) RecordInput(dstHubID cdssdk.HubID, transferBytes int64, isSuccess bool) {
func (s *HubTransferStats) RecordInput(dstHubID cortypes.HubID, transferBytes int64, isSuccess bool) {
s.lock.Lock()
defer s.lock.Unlock()

@@ -85,7 +85,7 @@ func (s *HubTransferStats) Reset() time.Time {
defer s.lock.Unlock()

s.data.StartTime = time.Now()
s.data.Entries = make(map[cdssdk.HubID]*HubTransferStatsEntry)
s.data.Entries = make(map[cortypes.HubID]*HubTransferStatsEntry)
return s.data.StartTime
}

@@ -94,7 +94,7 @@ func (s *HubTransferStats) DumpData() HubTransferStatsData {
defer s.lock.Unlock()

data := s.data
data.Entries = make(map[cdssdk.HubID]*HubTransferStatsEntry)
data.Entries = make(map[cortypes.HubID]*HubTransferStatsEntry)
for k, v := range s.data.Entries {
v2 := *v
data.Entries[k] = &v2


+ 5
- 5
common/pkgs/servicestats/service_stats.go View File

@@ -4,7 +4,7 @@ import (
"sync"
"time"

cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
cortypes "gitlink.org.cn/cloudream/storage2/coordinator/types"
)

type StatsHost struct {
@@ -14,24 +14,24 @@ type StatsHost struct {
HubStorageTransfer *HubStorageTransferStats
}

func (h *StatsHost) SetupHubTransfer(fromHubID cdssdk.HubID) {
func (h *StatsHost) SetupHubTransfer(fromHubID cortypes.HubID) {
h.HubTransfer = &HubTransferStats{
fromHubID: fromHubID,
lock: &sync.Mutex{},
data: HubTransferStatsData{
StartTime: time.Now(),
Entries: make(map[cdssdk.HubID]*HubTransferStatsEntry),
Entries: make(map[cortypes.HubID]*HubTransferStatsEntry),
},
}
}

func (h *StatsHost) SetupHubStorageTransfer(fromHubID cdssdk.HubID) {
func (h *StatsHost) SetupHubStorageTransfer(fromHubID cortypes.HubID) {
h.HubStorageTransfer = &HubStorageTransferStats{
fromHubID: fromHubID,
lock: &sync.Mutex{},
data: HubStorageTransferStatsData{
StartTime: time.Now(),
Entries: make(map[cdssdk.StorageID]*HubStorageTransferStatsEntry),
Entries: make(map[cortypes.StorageID]*HubStorageTransferStatsEntry),
},
}
}

Loading…
Cancel
Save