You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/05/26 04:40:40 UTC
[incubator-apisix] branch master updated: change: updated
prometheus to version 1.1 . (#1607)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new cdf4acb change: updated prometheus to version 1.1 . (#1607)
cdf4acb is described below
commit cdf4acbaea701b52b388e877557802089d73e64c
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Tue May 26 12:40:34 2020 +0800
change: updated prometheus to version 1.1 . (#1607)
---
.travis/linux_apisix_master_luarocks_runner.sh | 3 +-
apisix/plugins/prometheus/exporter.lua | 45 ++++++++++++++++++++------
rockspec/apisix-master-0.rockspec | 2 +-
3 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/.travis/linux_apisix_master_luarocks_runner.sh b/.travis/linux_apisix_master_luarocks_runner.sh
index 2c76087..e65bdbd 100755
--- a/.travis/linux_apisix_master_luarocks_runner.sh
+++ b/.travis/linux_apisix_master_luarocks_runner.sh
@@ -20,6 +20,7 @@ set -ex
export_or_prefix() {
export OPENRESTY_PREFIX="/usr/local/openresty-debug"
+ export APISIX_MAIN="https://raw.githubusercontent.com/apache/incubator-apisix/master/rockspec/apisix-master-0.rockspec"
}
do_install() {
@@ -62,7 +63,7 @@ script() {
sudo PATH=$PATH ./utils/install-apisix.sh remove > build.log 2>&1 || (cat build.log && exit 1)
# install APISIX by luarocks
- sudo luarocks install rockspec/apisix-master-0.rockspec > build.log 2>&1 || (cat build.log && exit 1)
+ sudo luarocks install $APISIX_MAIN > build.log 2>&1 || (cat build.log && exit 1)
# show install files
luarocks show apisix
diff --git a/apisix/plugins/prometheus/exporter.lua b/apisix/plugins/prometheus/exporter.lua
index 91ef22d..de72910 100644
--- a/apisix/plugins/prometheus/exporter.lua
+++ b/apisix/plugins/prometheus/exporter.lua
@@ -14,13 +14,14 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-local base_prometheus = require("resty.prometheus")
+local base_prometheus = require("prometheus")
local core = require("apisix.core")
local ipairs = ipairs
local ngx = ngx
local ngx_capture = ngx.location.capture
local re_gmatch = ngx.re.gmatch
local tonumber = tonumber
+local select = select
local prometheus
-- Default set of latency buckets, 1ms to 60s:
@@ -32,10 +33,29 @@ local DEFAULT_BUCKETS = { 1, 2, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60, 70,
local metrics = {}
-local _M = {version = 0.3}
+ local inner_tab_arr = {}
+ local clear_tab = core.table.clear
+local function gen_arr(...)
+ clear_tab(inner_tab_arr)
+
+ for i = 1, select('#', ...) do
+ inner_tab_arr[i] = select(i, ...)
+ end
+
+ return inner_tab_arr
+end
+
+
+local _M = {}
function _M.init()
+ -- todo: support hot reload, we may need to update the lua-prometheus
+ -- library
+ if ngx.get_phase() ~= "init" and ngx.get_phase() ~= "init_worker" then
+ return
+ end
+
core.table.clear(metrics)
-- across all services
@@ -81,27 +101,31 @@ function _M.log(conf, ctx)
service_id = vars.host
end
- metrics.status:inc(1, vars.status, route_id, service_id, balancer_ip)
+ metrics.status:inc(1,
+ gen_arr(vars.status, route_id, service_id, balancer_ip))
local latency = (ngx.now() - ngx.req.start_time()) * 1000
- metrics.latency:observe(latency, "request", service_id, balancer_ip)
+ metrics.latency:observe(latency,
+ gen_arr("request", service_id, balancer_ip))
local overhead = latency
if ctx.var.upstream_response_time then
overhead = overhead - tonumber(ctx.var.upstream_response_time)
end
- metrics.overhead:observe(overhead, "request", service_id, balancer_ip)
+ metrics.overhead:observe(overhead,
+ gen_arr("request", service_id, balancer_ip))
- metrics.bandwidth:inc(vars.request_length, "ingress", route_id, service_id,
- balancer_ip)
+ metrics.bandwidth:inc(vars.request_length,
+ gen_arr("ingress", route_id, service_id, balancer_ip))
- metrics.bandwidth:inc(vars.bytes_sent, "egress", route_id, service_id,
- balancer_ip)
+ metrics.bandwidth:inc(vars.bytes_sent,
+ gen_arr("egress", route_id, service_id, balancer_ip))
end
local ngx_statu_items = {"active", "accepted", "handled", "total",
"reading", "writing", "waiting"}
+ local label_values = {}
local function nginx_status()
local res = ngx_capture("/apisix/nginx_status")
if not res or res.status ~= 200 then
@@ -126,7 +150,8 @@ local function nginx_status()
break
end
- metrics.connections:set(val[0], name)
+ label_values[1] = name
+ metrics.connections:set(val[0], label_values)
end
end
diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec
index 3a02e1a..aefe8cf 100644
--- a/rockspec/apisix-master-0.rockspec
+++ b/rockspec/apisix-master-0.rockspec
@@ -46,7 +46,7 @@ dependencies = {
"lua-resty-openidc = 1.7.2-1",
"luafilesystem = 1.7.0-2",
"lua-tinyyaml = 0.1",
- "lua-resty-prometheus = 1.0",
+ "lua-resty-prometheus = 1.1",
"jsonschema = 0.8",
"lua-resty-ipmatcher = 0.6",
"lua-resty-kafka = 0.07",