File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
server/rpcserver/serverinterceptors Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ package metric
2
+
3
+ import "github.com/prometheus/client_golang/prometheus"
4
+
5
+ type (
6
+ GaugeVecOpts VectorOpts // GaugeVecOpts 指标向量选项
7
+
8
+ GaugeVec interface {
9
+ Set (v float64 , labels ... string ) // Set 设置标签
10
+ Inc (labels ... string ) // Inc 增加标签
11
+ Add (v float64 , labels ... string ) // Add 添加标签
12
+ }
13
+
14
+ promGaugeVec struct {
15
+ gauge * prometheus.GaugeVec
16
+ }
17
+ )
18
+
19
+ // NewGaugeVec 封装 prometheus.NewGaugeVec 为了增加 labels 参数
20
+ func NewGaugeVec (cfg * GaugeVecOpts ) GaugeVec {
21
+ if cfg == nil {
22
+ return nil
23
+ }
24
+
25
+ vec := prometheus .NewGaugeVec (prometheus.GaugeOpts {
26
+ Namespace : cfg .Namespace ,
27
+ Subsystem : cfg .Subsystem ,
28
+ Name : cfg .Name ,
29
+ Help : cfg .Help ,
30
+ }, cfg .Labels )
31
+ // 反向注册,将指标注册到指标注册器中
32
+ prometheus .MustRegister (vec )
33
+ //将注册到指标注册器中的指标包装成promGaugeVec
34
+ return & promGaugeVec {gauge : vec }
35
+ }
36
+
37
+ func (p promGaugeVec ) Set (v float64 , labels ... string ) {
38
+ p .gauge .WithLabelValues (labels ... ).Set (v )
39
+ }
40
+
41
+ func (p promGaugeVec ) Inc (labels ... string ) {
42
+ p .gauge .WithLabelValues (labels ... ).Inc ()
43
+ }
44
+
45
+ func (p promGaugeVec ) Add (v float64 , labels ... string ) {
46
+ p .gauge .WithLabelValues (labels ... ).Add (v )
47
+ }
Original file line number Diff line number Diff line change
1
+ package metric
2
+
3
+ // VectorOpts 指标选项
4
+ type VectorOpts struct {
5
+ Namespace string // 命名空间
6
+ Subsystem string // 子系统
7
+ Name string // 指标名称
8
+ Help string // 指标帮助信息
9
+ Labels []string // 指标标签
10
+ }
Original file line number Diff line number Diff line change
1
+ package serverinterceptors
You can’t perform that action at this time.
0 commit comments