cubefs

Форк
0
/
metrics.go 
88 строк · 2.6 Кб
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 metanode
16

17
import (
18
	"fmt"
19
	"time"
20

21
	"github.com/cubefs/cubefs/util/exporter"
22
)
23

24
// metrics
25
const (
26
	StatPeriod = time.Minute * time.Duration(1)
27

28
	MetricMetaFailedPartition      = "meta_failed_partition"
29
	MetricMetaPartitionInodeCount  = "mpInodeCount"
30
	MetricMetaPartitionDentryCount = "mpDentryCount"
31
	MetricConnectionCount          = "connectionCnt"
32
)
33

34
type MetaNodeMetrics struct {
35
	MetricConnectionCount          *exporter.Gauge
36
	MetricMetaFailedPartition      *exporter.Gauge
37
	MetricMetaPartitionInodeCount  *exporter.Gauge
38
	MetricMetaPartitionDentryCount *exporter.Gauge
39

40
	metricStopCh chan struct{}
41
}
42

43
func (m *MetaNode) startStat() {
44
	m.metrics = &MetaNodeMetrics{
45
		metricStopCh: make(chan struct{}, 0),
46

47
		MetricConnectionCount:          exporter.NewGauge(MetricConnectionCount),
48
		MetricMetaFailedPartition:      exporter.NewGauge(MetricMetaFailedPartition),
49
		MetricMetaPartitionInodeCount:  exporter.NewGauge(MetricMetaPartitionInodeCount),
50
		MetricMetaPartitionDentryCount: exporter.NewGauge(MetricMetaPartitionDentryCount),
51
	}
52

53
	go m.collectPartitionMetrics()
54
}
55

56
func (m *MetaNode) upatePartitionMetrics(mp *metaPartition) {
57
	labels := map[string]string{
58
		"partid":     fmt.Sprintf("%d", mp.config.PartitionId),
59
		exporter.Vol: mp.config.VolName,
60
	}
61
	m.metrics.MetricMetaPartitionInodeCount.SetWithLabels(float64(mp.GetInodeTreeLen()), labels)
62
	m.metrics.MetricMetaPartitionDentryCount.SetWithLabels(float64(mp.GetDentryTreeLen()), labels)
63
}
64

65
func (m *MetaNode) collectPartitionMetrics() {
66
	ticker := time.NewTicker(StatPeriod)
67
	for {
68
		select {
69
		case <-m.metrics.metricStopCh:
70
			return
71
		case <-ticker.C:
72
			if manager, ok := m.metadataManager.(*metadataManager); ok {
73
				manager.mu.RLock()
74
				for _, p := range manager.partitions {
75
					if mp, ok := p.(*metaPartition); ok {
76
						m.upatePartitionMetrics(mp)
77
					}
78
				}
79
				manager.mu.RUnlock()
80
			}
81
			m.metrics.MetricConnectionCount.Set(float64(m.connectionCnt))
82
		}
83
	}
84
}
85

86
func (m *MetaNode) stopStat() {
87
	m.metrics.metricStopCh <- struct{}{}
88
}
89

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

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

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

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