-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
metric.go
144 lines (125 loc) · 3.46 KB
/
metric.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
135
136
137
138
139
140
141
142
143
144
package emetric
import (
"github.com/gotomicro/ego/core/eapp"
"github.com/gotomicro/ego/server/egovernor"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"time"
)
var (
// TypeHTTP ...
TypeHTTP = "http"
// TypeGRPCUnary ...
TypeGRPCUnary = "unary"
// TypeGRPCStream ...
TypeGRPCStream = "stream"
// TypeRedis ...
TypeRedis = "redis"
TypeGorm = "gorm"
// TypeRocketMQ ...
TypeRocketMQ = "rocketmq"
// TypeWebsocket ...
TypeWebsocket = "ws"
// TypeMySQL ...
TypeMySQL = "mysql"
// CodeJob
CodeJobSuccess = "ok"
// CodeJobFail ...
CodeJobFail = "fail"
// CodeJobReentry ...
CodeJobReentry = "reentry"
// CodeCache
CodeCacheMiss = "miss"
// CodeCacheHit ...
CodeCacheHit = "hit"
// Namespace
DefaultNamespace = "ego"
)
var (
// ServerHandleCounter ...
ServerHandleCounter = CounterVecOpts{
Namespace: DefaultNamespace,
Name: "server_handle_total",
Labels: []string{"type", "method", "peer", "code"},
}.Build()
// ServerHandleHistogram ...
ServerHandleHistogram = HistogramVecOpts{
Namespace: DefaultNamespace,
Name: "server_handle_seconds",
Labels: []string{"type", "method", "peer"},
}.Build()
// ClientHandleCounter ...
ClientHandleCounter = CounterVecOpts{
Namespace: DefaultNamespace,
Name: "client_handle_total",
Labels: []string{"type", "name", "method", "peer", "code"},
}.Build()
// ClientHandleHistogram ...
ClientHandleHistogram = HistogramVecOpts{
Namespace: DefaultNamespace,
Name: "client_handle_seconds",
Labels: []string{"type", "name", "method", "peer"},
}.Build()
// JobHandleCounter ...
JobHandleCounter = CounterVecOpts{
Namespace: DefaultNamespace,
Name: "job_handle_total",
Labels: []string{"type", "name", "code"},
}.Build()
// JobHandleHistogram ...
JobHandleHistogram = HistogramVecOpts{
Namespace: DefaultNamespace,
Name: "job_handle_seconds",
Labels: []string{"type", "name"},
}.Build()
LibHandleHistogram = HistogramVecOpts{
Namespace: DefaultNamespace,
Name: "lib_handle_seconds",
Labels: []string{"type", "method", "address"},
}.Build()
// LibHandleCounter ...
LibHandleCounter = CounterVecOpts{
Namespace: DefaultNamespace,
Name: "lib_handle_total",
Labels: []string{"type", "method", "address", "code"},
}.Build()
LibHandleSummary = SummaryVecOpts{
Namespace: DefaultNamespace,
Name: "lib_handle_stats",
Labels: []string{"name", "status"},
}.Build()
// CacheHandleCounter ...
CacheHandleCounter = CounterVecOpts{
Namespace: DefaultNamespace,
Name: "cache_handle_total",
Labels: []string{"type", "name", "action", "code"},
}.Build()
// CacheHandleHistogram ...
CacheHandleHistogram = HistogramVecOpts{
Namespace: DefaultNamespace,
Name: "cache_handle_seconds",
Labels: []string{"type", "name", "action"},
}.Build()
// BuildInfoGauge ...
BuildInfoGauge = GaugeVecOpts{
Namespace: DefaultNamespace,
Name: "build_info",
Labels: []string{"name", "mode", "region", "zone", "app_version", "ego_version", "start_time", "build_time", "go_version"},
}.Build()
)
func init() {
BuildInfoGauge.WithLabelValues(
eapp.Name(),
eapp.AppMode(),
eapp.AppRegion(),
eapp.AppZone(),
eapp.AppVersion(),
eapp.EgoVersion(),
eapp.StartTime(),
eapp.BuildTime(),
eapp.GoVersion(),
).Set(float64(time.Now().UnixNano() / 1e6))
egovernor.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
promhttp.Handler().ServeHTTP(w, r)
})
}