使用go自定义prometheus监控指标
复制代码
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
104package main import ( "fmt" "net/http" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "log" "math/rand" "time" ) var ( counter = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "golang", Name: "my_counter", Help: "This is my counter", }) gauge = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: "golang", Name: "my_gauge", Help: "This is my gauge", ConstLabels: map[string]string{ "path":"/api/test", }, }) gauge2 = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: "golang", Name: "my_gauge", Help: "This is my gauge", ConstLabels: map[string]string{ "path":"/api/test1", }, }) gauge3 = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: "golang", Name: "my_gauge", Help: "This is my gauge", ConstLabels: map[string]string{ "path":"/api/test2", }, }) gauge4 = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: "golang", Name: "my_gauge", Help: "This is my gauge", ConstLabels: map[string]string{ "path":"/api/test3", }, }) histogram = prometheus.NewHistogram( prometheus.HistogramOpts{ Namespace: "golang", Name: "my_histogram", Help: "This is my histogram", }) summary = prometheus.NewSummary( prometheus.SummaryOpts{ Namespace: "golang", Name: "my_summary", Help: "This is my summary", }) ) func main() { rand.Seed(time.Now().Unix()) http.Handle("/metrics", promhttp.Handler()) prometheus.MustRegister(counter) prometheus.MustRegister(gauge) prometheus.MustRegister(gauge2) prometheus.MustRegister(gauge3) prometheus.MustRegister(gauge4) prometheus.MustRegister(histogram) prometheus.MustRegister(summary) go func() { for { counter.Add(rand.Float64() * 5) gauge.Set(rand.Float64()*15 ) gauge2.Set(rand.Float64()*15 ) gauge3.Set(rand.Float64()*15 ) gauge4.Set(rand.Float64()*15 ) histogram.Observe(rand.Float64() * 10) summary.Observe(rand.Float64() * 10) time.Sleep(time.Second) } }() fmt.Println("Starting.....") log.Fatal(http.ListenAndServe(":8080", nil)) }
最后
以上就是畅快飞机最近收集整理的关于基于Go实现自定义Prometheus监控指标的全部内容,更多相关基于Go实现自定义Prometheus监控指标内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复