21
"github.com/cubefs/cubefs/util/exporter"
26
StatPeriod = time.Minute * time.Duration(1)
28
MetricMetaFailedPartition = "meta_failed_partition"
29
MetricMetaPartitionInodeCount = "mpInodeCount"
30
MetricMetaPartitionDentryCount = "mpDentryCount"
31
MetricConnectionCount = "connectionCnt"
34
type MetaNodeMetrics struct {
35
MetricConnectionCount *exporter.Gauge
36
MetricMetaFailedPartition *exporter.Gauge
37
MetricMetaPartitionInodeCount *exporter.Gauge
38
MetricMetaPartitionDentryCount *exporter.Gauge
40
metricStopCh chan struct{}
43
func (m *MetaNode) startStat() {
44
m.metrics = &MetaNodeMetrics{
45
metricStopCh: make(chan struct{}, 0),
47
MetricConnectionCount: exporter.NewGauge(MetricConnectionCount),
48
MetricMetaFailedPartition: exporter.NewGauge(MetricMetaFailedPartition),
49
MetricMetaPartitionInodeCount: exporter.NewGauge(MetricMetaPartitionInodeCount),
50
MetricMetaPartitionDentryCount: exporter.NewGauge(MetricMetaPartitionDentryCount),
53
go m.collectPartitionMetrics()
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,
61
m.metrics.MetricMetaPartitionInodeCount.SetWithLabels(float64(mp.GetInodeTreeLen()), labels)
62
m.metrics.MetricMetaPartitionDentryCount.SetWithLabels(float64(mp.GetDentryTreeLen()), labels)
65
func (m *MetaNode) collectPartitionMetrics() {
66
ticker := time.NewTicker(StatPeriod)
69
case <-m.metrics.metricStopCh:
72
if manager, ok := m.metadataManager.(*metadataManager); ok {
74
for _, p := range manager.partitions {
75
if mp, ok := p.(*metaPartition); ok {
76
m.upatePartitionMetrics(mp)
81
m.metrics.MetricConnectionCount.Set(float64(m.connectionCnt))
86
func (m *MetaNode) stopStat() {
87
m.metrics.metricStopCh <- struct{}{}