-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add batch process metrics #3070
Changes from 16 commits
51ad65f
38ca888
5bce894
40a88ac
9ace229
40be48a
bbabcf3
c2562b2
7a9def2
081ce7d
c3c78ac
75f4b14
045ba1a
9fe4ad3
ad38eb9
62ad1a4
6f7ecd5
21e0323
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ local batch_processor_mt = { | |
} | ||
local execute_func | ||
local create_buffer_timer | ||
local batch_metrics | ||
local prometheus = require("apisix.plugins.prometheus.exporter") | ||
|
||
|
||
local schema = { | ||
|
@@ -131,7 +133,9 @@ function batch_processor:new(func, config) | |
entry_buffer = { entries = {}, retry_count = 0}, | ||
is_timer_running = false, | ||
first_entry_t = 0, | ||
last_entry_t = 0 | ||
last_entry_t = 0, | ||
route_id = config.route_id, | ||
server_addr = config.server_addr, | ||
} | ||
|
||
return setmetatable(processor, batch_processor_mt) | ||
|
@@ -146,8 +150,20 @@ function batch_processor:push(entry) | |
return | ||
end | ||
|
||
if not batch_metrics and prometheus.get_prometheus() and self.name | ||
and self.route_id and self.server_addr then | ||
batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries", | ||
"batch process remaining entries", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||
{"name", "route_id", "server_addr"}) | ||
end | ||
|
||
local entries = self.entry_buffer.entries | ||
table.insert(entries, entry) | ||
-- add batch metric for every route | ||
if batch_metrics then | ||
self.label = {self.name, self.route_id, self.server_addr} | ||
batch_metrics:set(#entries, self.label) | ||
end | ||
|
||
if #entries == 1 then | ||
self.first_entry_t = now() | ||
|
@@ -173,11 +189,16 @@ function batch_processor:process_buffer() | |
"buffercount[", #self.entry_buffer.entries ,"]") | ||
self.batch_to_process[#self.batch_to_process + 1] = self.entry_buffer | ||
self.entry_buffer = { entries = {}, retry_count = 0 } | ||
if batch_metrics then | ||
self.label = {self.name, self.route_id, self.server_addr} | ||
batch_metrics:set(0, self.label) | ||
end | ||
end | ||
|
||
for _, batch in ipairs(self.batch_to_process) do | ||
schedule_func_exec(self, 0, batch) | ||
end | ||
|
||
self.batch_to_process = {} | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,7 @@ Or you can goto [Grafana official](https://grafana.com/grafana/dashboards/11719) | |
* `Bandwidth`: Total Bandwidth (egress/ingress) flowing through apisix. This metric is available per service and as a sum across all services. | ||
* `etcd reachability`: A gauge type with a value of 0 or 1, representing if etcd can be reached by a apisix or not. | ||
* `Connections`: Various Nginx connection metrics like active, reading, writing, and number of accepted connections. | ||
* `Batch process entries`: A gauge type, when we use plugins such as: sys logger, http logger, sls logger, tcp logger, udp logger and zipkin, the surplus entries which not sended will be statistics in the metrics. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should mention the batch processor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed. |
||
|
||
Here is the original metric data of apisix: | ||
|
||
|
@@ -138,6 +139,14 @@ apisix_bandwidth{type="egress",service="foo.com"} 2379 | |
apisix_bandwidth{type="ingress",service="127.0.0.2"} 83 | ||
apisix_bandwidth{type="ingress",service="bar.com"} 76 | ||
apisix_bandwidth{type="ingress",service="foo.com"} 988 | ||
# HELP apisix_batch_process_entries batch process remaining entries | ||
# TYPE apisix_batch_process_entries gauge | ||
apisix_batch_process_entries{name="http-logger",route_id="9",server_addr="127.0.0.1"} 1 | ||
apisix_batch_process_entries{name="sls-logger",route_id="9",server_addr="127.0.0.1"} 1 | ||
apisix_batch_process_entries{name="tcp-logger",route_id="9",server_addr="127.0.0.1"} 1 | ||
apisix_batch_process_entries{name="udp-logger",route_id="9",server_addr="127.0.0.1"} 1 | ||
apisix_batch_process_entries{name="sys-logger",route_id="9",server_addr="127.0.0.1"} 1 | ||
apisix_batch_process_entries{name="zipkin_report",route_id="9",server_addr="127.0.0.1"} 1 | ||
# HELP apisix_etcd_reachable Config server etcd reachable from Apisix, 0 is unreachable | ||
# TYPE apisix_etcd_reachable gauge | ||
apisix_etcd_reachable 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this if we can't share the table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.