-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig.yml
118 lines (112 loc) · 3.7 KB
/
config.yml
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
- name: nginx
format: $remote_addr - $remote_user [$time_local] "$method $request $protocol" $request_time-$upstream_response_time $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" $request_id
source_files:
- ./logs/nginx.log
external_labels:
region: zone1
relabel_config:
source_labels:
- request
- method
- status
replacement:
request:
trim: "?"
replace:
- target: /v1.0/example/\d+
value: /v1.0/example/:id
status:
replace:
- target: 4.+
value: 4xx
- target: 5.+
value: 5xx
histogram_buckets: [0.1, 0.3, 0.5, 1, 2]
exemplar_config:
match:
request_time: ">= 0.3"
labels:
- request_id
- remote_addr
- name: gin
format: $clientip - [$time_local] "$method $request $protocol $status $upstream_response_time "$http_user_agent" $err"
source_files:
- ./logs/gin.log
external_labels:
region: zone1
relabel_config:
source_labels:
- request
- method
- status
replacement:
request:
trim: "?"
histogram_buckets: [0.1, 0.3, 0.5, 1, 2]
- name: gateway_uri
format: $remote_addr - $remote_user [$time_local] "$method $uri $protocol" $request_time-$upstream_response_time $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" $request_id
source_files:
- ./logs/nginx_gateway.access.log
relabel_config:
source_labels:
- uri
- method
- status
replacement:
uri:
trim: "?"
replace:
# replace url "/api/path1/path2/123/xxx" to "/api/path1/path2/:id/xxx"
# replace url "/api/path7/path8/789/xxx" to "/api/path7/path8/:id/xxx"
- target: (^\/api\/[^\/]+\/[^\/]+\/)\d+(.*)
value: ${1}:id${2}
# replace url "/api/path1/path2/path3/123/xxx" to "/api/path1/path2/path3/:id/xxx"
# replace url "/api/path7/path8/path9/789/xxx" to "/api/path7/path8/path9/:id/xxx"
- target: (^\/api\/[^\/]+\/[^\/]+\/[^\/]+\/)\d+(.*)
value: ${1}:id${2}
- target: (^\/api\/[^\/]+\/[^\/]+\/[^\/]+\/)\d+(.*)
value: ${1}:id${2}
# The remaining uris starting with /api/ remain as is
- target: ^\/api\/.*
value: ${0}
# The uri that does not match the above rules and is not my concern, please replace it with 'notATargetUri'
- target: (.*)
value: "notATargetUri"
status:
replace:
- target: 404
value: 404
- target: 4.+
value: 4xx
- target: 5.+
value: 5xx
histogram_buckets: [0.1, 0.3, 0.5, 1, 2]
- name: gateway_service
format: $remote_addr - $remote_user [$time_local] "$method $service $protocol" $request_time-$upstream_response_time $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" $request_id
source_files:
- ./logs/nginx_gateway.access.log
relabel_config:
source_labels:
- method
- status
- service
replacement:
service:
trim: "?"
replace:
# extract the second part from the request_uri as the service name.
# The service of "/api/user/path1/123" is "user", and the service of "/api/order/path1/123" is "order"
# Then we can generate metrics for the service dimension
- target: \/api\/([\d\w-]+)
value: ${1}
- target: (.*)
- value: ""
status:
replace:
- target: 404
value: 404
- target: 4.+
value: 4xx
- target: 5.+
value: 5xx
histogram_buckets: [0.1, 0.3, 0.5, 1, 2]