-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path001_change_prometheus_default_buckets.patch
72 lines (60 loc) · 2.38 KB
/
001_change_prometheus_default_buckets.patch
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
diff --git a/apisix/plugins/prometheus/exporter.lua b/apisix/plugins/prometheus/exporter.lua
index 45ff94c3..6a9ff8eb 100644
--- a/apisix/plugins/prometheus/exporter.lua
+++ b/apisix/plugins/prometheus/exporter.lua
@@ -168,10 +168,15 @@ function _M.http_init(prometheus_enabled_in_stream)
{"code", "route", "matched_uri", "matched_host", "service", "consumer", "node",
unpack(extra_labels("http_status"))})
+ local buckets = DEFAULT_BUCKETS
+ if attr and attr.default_buckets then
+ buckets = attr.default_buckets
+ end
+
metrics.latency = prometheus:histogram("http_latency",
"HTTP request latency in milliseconds per service in APISIX",
{"type", "route", "service", "consumer", "node", unpack(extra_labels("http_latency"))},
- DEFAULT_BUCKETS)
+ buckets)
metrics.bandwidth = prometheus:counter("bandwidth",
"Total bandwidth in bytes consumed per service in APISIX",
@@ -208,6 +213,12 @@ end
function _M.http_log(conf, ctx)
+ local attr = plugin.plugin_attr("prometheus")
+ local official
+ if attr and attr.official then
+ official = attr.official
+ end
+
local vars = ctx.var
local route_id = ""
@@ -235,11 +246,17 @@ function _M.http_log(conf, ctx)
matched_host = ctx.curr_req_matched._host or ""
end
+ if official and official.enable_status then
+
metrics.status:inc(1,
gen_arr(vars.status, route_id, matched_uri, matched_host,
service_id, consumer_name, balancer_ip,
unpack(extra_labels("http_status", ctx))))
+ end
+
+ if official and official.enable_latency then
+
local latency, upstream_latency, apisix_latency = latency_details(ctx)
local latency_extra_label_values = extra_labels("http_latency", ctx)
@@ -257,6 +274,10 @@ function _M.http_log(conf, ctx)
gen_arr("apisix", route_id, service_id, consumer_name, balancer_ip,
unpack(latency_extra_label_values)))
+ end
+
+ if official and official.enable_bandwidth then
+
local bandwidth_extra_label_values = extra_labels("bandwidth", ctx)
metrics.bandwidth:inc(vars.request_length,
@@ -266,6 +287,8 @@ function _M.http_log(conf, ctx)
metrics.bandwidth:inc(vars.bytes_sent,
gen_arr("egress", route_id, service_id, consumer_name, balancer_ip,
unpack(bandwidth_extra_label_values)))
+
+ end
end