mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-02 20:17:35 +08:00
fix(prometheus): collect nginx_status and return the body (#4014)
Signed-off-by: spacewander <spacewanderlzx@gmail.com> Co-authored-by: John Bampton <jbampton@users.noreply.github.com>
This commit is contained in:
parent
d6f3f7ae02
commit
e9fedee192
@ -300,6 +300,14 @@ http {
|
||||
prometheus.export_metrics()
|
||||
}
|
||||
}
|
||||
|
||||
{% if with_module_status then %}
|
||||
location = /apisix/nginx_status {
|
||||
allow 127.0.0.0/24;
|
||||
deny all;
|
||||
stub_status;
|
||||
}
|
||||
{% end %}
|
||||
}
|
||||
{% end %}
|
||||
|
||||
|
@ -90,7 +90,10 @@ function _M.export_metrics()
|
||||
local method = ngx.req.get_method()
|
||||
|
||||
if uri == api.uri and method == api.methods[1] then
|
||||
return api.handler()
|
||||
local code, body = api.handler()
|
||||
if code or body then
|
||||
core.response.exit(code, body)
|
||||
end
|
||||
end
|
||||
|
||||
return core.response.exit(404)
|
||||
|
@ -25,19 +25,24 @@ make run
|
||||
|
||||
code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/prometheus/metrics)
|
||||
if [ ! $code -eq 404 ]; then
|
||||
echo "failed: should listen default prometheus address"
|
||||
echo "failed: should listen at default prometheus address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9091/apisix/prometheus/metrics)
|
||||
if [ ! $code -eq 200 ]; then
|
||||
echo "failed: should listen default prometheus address"
|
||||
echo "failed: should listen at default prometheus address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! curl -i http://127.0.0.1:9091/apisix/prometheus/metrics | grep "apisix_nginx_http_current_connections" > /dev/null; then
|
||||
echo "failed: should listen at default prometheus address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
make stop
|
||||
|
||||
echo "passed: should listen default prometheus address"
|
||||
echo "passed: should listen at default prometheus address"
|
||||
|
||||
echo '
|
||||
plugin_attr:
|
||||
@ -51,13 +56,13 @@ IP=127.0.0.1 PORT=9092 make run
|
||||
|
||||
code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9092/apisix/prometheus/metrics)
|
||||
if [ ! $code -eq 200 ]; then
|
||||
echo "failed: should listen configured prometheus address"
|
||||
echo "failed: should listen at configured prometheus address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
make stop
|
||||
|
||||
echo "passed: should listen configured prometheus address"
|
||||
echo "passed: should listen at configured prometheus address"
|
||||
|
||||
echo '
|
||||
plugin_attr:
|
||||
@ -73,16 +78,16 @@ IP=127.0.0.1 PORT=9092 make run
|
||||
|
||||
code=$(curl -v -k -i -m 20 -o /dev/null -s http://127.0.0.1:9092/prometheus/metrics || echo 'ouch')
|
||||
if [ "$code" != "ouch" ]; then
|
||||
echo "failed: should listen previous prometheus address"
|
||||
echo "failed: should listen at previous prometheus address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/prometheus/metrics)
|
||||
if [ ! $code -eq 200 ]; then
|
||||
echo "failed: should listen previous prometheus address"
|
||||
echo "failed: should listen at previous prometheus address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
make stop
|
||||
|
||||
echo "passed: should listen previous prometheus address"
|
||||
echo "passed: should listen at previous prometheus address"
|
||||
|
Loading…
Reference in New Issue
Block a user