-
Notifications
You must be signed in to change notification settings - Fork 269
/
metrics.go
134 lines (120 loc) · 4.46 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package loader
import (
"github.com/pingcap/tiflow/engine/pkg/promutil"
"github.com/prometheus/client_golang/prometheus"
)
var (
f = &promutil.PromFactory{}
// should error.
tidbExecutionErrorCounter = f.NewCounterVec(
prometheus.CounterOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "tidb_execution_error",
Help: "Total count of tidb execution errors",
}, []string{"task", "source_id"})
queryHistogram = f.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "query_duration_time",
Help: "Bucketed histogram of query time (s) of a txn.",
Buckets: prometheus.ExponentialBuckets(0.000005, 2, 25),
}, []string{"task", "source_id"})
txnHistogram = f.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "txn_duration_time",
Help: "Bucketed histogram of processing time (s) of a txn.",
Buckets: prometheus.ExponentialBuckets(0.000005, 2, 25),
}, []string{"task", "worker", "source_id", "target_schema", "target_table"})
stmtHistogram = f.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "stmt_duration_time",
Help: "Bucketed histogram of every statement query time (s).",
Buckets: prometheus.ExponentialBuckets(0.000005, 2, 25),
}, []string{"type", "task"})
dataFileGauge = f.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "data_file_gauge",
Help: "data files in total",
}, []string{"task", "source_id"})
tableGauge = f.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "table_gauge",
Help: "tables in total",
}, []string{"task", "source_id"})
dataSizeGauge = f.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "data_size_gauge",
Help: "data size in total",
}, []string{"task", "source_id"})
progressGauge = f.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "progress",
Help: "the processing progress of loader in percentage",
}, []string{"task", "source_id"})
// should alert.
loaderExitWithErrorCounter = f.NewCounterVec(
prometheus.CounterOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "exit_with_error_count",
Help: "counter for loader exits with error",
}, []string{"task", "source_id"})
remainingTimeGauge = f.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "dm",
Subsystem: "loader",
Name: "remaining_time",
Help: "the remaining time in second to finish load process",
}, []string{"task", "worker", "source_id", "source_schema", "source_table"})
)
// RegisterMetrics registers metrics.
func RegisterMetrics(registry *prometheus.Registry) {
registry.MustRegister(tidbExecutionErrorCounter)
registry.MustRegister(txnHistogram)
registry.MustRegister(queryHistogram)
registry.MustRegister(stmtHistogram)
registry.MustRegister(dataFileGauge)
registry.MustRegister(tableGauge)
registry.MustRegister(dataSizeGauge)
registry.MustRegister(progressGauge)
registry.MustRegister(loaderExitWithErrorCounter)
registry.MustRegister(remainingTimeGauge)
}
func (l *Loader) removeLabelValuesWithTaskInMetrics(task string) {
tidbExecutionErrorCounter.DeletePartialMatch(prometheus.Labels{"task": task})
txnHistogram.DeletePartialMatch(prometheus.Labels{"task": task})
queryHistogram.DeletePartialMatch(prometheus.Labels{"task": task})
stmtHistogram.DeletePartialMatch(prometheus.Labels{"task": task})
dataFileGauge.DeletePartialMatch(prometheus.Labels{"task": task})
tableGauge.DeletePartialMatch(prometheus.Labels{"task": task})
dataSizeGauge.DeletePartialMatch(prometheus.Labels{"task": task})
progressGauge.DeletePartialMatch(prometheus.Labels{"task": task})
loaderExitWithErrorCounter.DeletePartialMatch(prometheus.Labels{"task": task})
remainingTimeGauge.DeletePartialMatch(prometheus.Labels{"task": task})
}