cubefs

Форк
0
/
stat.go 
99 строк · 2.8 Кб
1
// Copyright 2018 The CubeFS Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package datanode
16

17
import (
18
	"sync"
19
	"sync/atomic"
20
	"time"
21
)
22

23
// Stats defines various metrics that will be collected during the execution.
24
type Stats struct {
25
	inDataSize  uint64
26
	outDataSize uint64
27
	inFlow      uint64
28
	outFlow     uint64
29

30
	Zone                               string
31
	ConnectionCnt                      int64
32
	ClusterID                          string
33
	TCPAddr                            string
34
	Start                              time.Time
35
	Total                              uint64
36
	Used                               uint64
37
	Available                          uint64 // available space
38
	TotalPartitionSize                 uint64 // dataPartitionCnt * dataPartitionSize
39
	RemainingCapacityToCreatePartition uint64
40
	CreatedPartitionCnt                uint64
41
	LackPartitionsInMem                uint64
42
	LackPartitionsInDisk               uint64
43

44
	// the maximum capacity among all the disks that can be used to create partition
45
	MaxCapacityToCreatePartition uint64
46

47
	sync.Mutex
48
}
49

50
// NewStats creates a new Stats.
51
func NewStats(zone string) (s *Stats) {
52
	s = new(Stats)
53
	s.Zone = zone
54
	return s
55
}
56

57
// AddConnection adds a connection.
58
func (s *Stats) AddConnection() {
59
	atomic.AddInt64(&s.ConnectionCnt, 1)
60
}
61

62
// RemoveConnection removes a connection.
63
func (s *Stats) RemoveConnection() {
64
	atomic.AddInt64(&s.ConnectionCnt, -1)
65
}
66

67
// GetConnectionCount gets the connection count.
68
func (s *Stats) GetConnectionCount() int64 {
69
	return atomic.LoadInt64(&s.ConnectionCnt)
70
}
71

72
func (s *Stats) updateMetrics(
73
	total, used, available, createdPartitionWeights, remainWeightsForCreatePartition,
74
	maxWeightsForCreatePartition, dataPartitionCnt uint64) {
75
	s.Lock()
76
	defer s.Unlock()
77

78
	s.Total = total
79
	s.Used = used
80
	s.Available = available
81
	s.TotalPartitionSize = createdPartitionWeights
82
	s.RemainingCapacityToCreatePartition = remainWeightsForCreatePartition
83
	s.MaxCapacityToCreatePartition = maxWeightsForCreatePartition
84
	s.CreatedPartitionCnt = dataPartitionCnt
85
}
86

87
func (s *Stats) updateMetricLackPartitionsInMem(lackPartitionsInMem uint64) {
88
	s.Lock()
89
	defer s.Unlock()
90

91
	s.LackPartitionsInMem = lackPartitionsInMem
92
}
93

94
func (s *Stats) updateMetricLackPartitionsInDisk(lackPartitionsInDisk uint64) {
95
	s.Lock()
96
	defer s.Unlock()
97

98
	s.LackPartitionsInDisk = lackPartitionsInDisk
99
}
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.