br41n10 opened a new issue, #11352:
URL: https://github.com/apache/apisix/issues/11352

   ### Description
   
   How to expose a metric from custom plugin, using the default prometheus 
exported URI `/apisix/prometheus/metrics`.
   
   In my case, I want get summary metric about request_time, not the builtin 
histogram metric `apisix_http_latency_bucket`.
   
   Here is a example plugin code
   
   ``` lua
   local base_prometheus = require("prometheus")
   local core = require("apisix.core")
   local ngx       = ngx
   local clear_tab = core.table.clear
   local plugin_name = "request-time-metric"
   local prometheus = require("apisix.plugins.prometheus.exporter")
   
   local custom_metrics = {}
   
   local schema = {
       type = "object",
       properties = {},
   }
   
   local _M = {
       version = 0.1,
       priority = 40,
       name = plugin_name,
       schema = schema,
   }
   
   -- need modify ngx_tpl.lua to call this function, I don't think this is a 
better way
   function _M.http_init()
       if ngx.get_phase() ~= "init" and ngx.get_phase() ~= "init_worker"  then
           return
       end
   
       clear_tab(custom_metrics)
   
       prometheus = base_prometheus.init("prometheus-metrics", "apisix_")
   
       custom_metrics.test_counter = prometheus:counter("test_counter", "test", 
{"test"})
   end
   
   function _M.http_log(conf, ctx)
       custom_metrics.test_counter:inc(1, "test")
   end
   
   function _M.log(conf, ctx)
       -- print "null"
       core.log.warn("metrics: ", core.json.encode(custom_metrics.test_counter, 
true))
   end
   
   return _M
   
   ```
   
   
   Is this the right way? Or should I just modify the builtin 
prometheus/exporter.lua plugin (is there will be a problem when upgrade 
apisix?) ? 
   
   ### Environment
   
   - APISIX version (run `apisix version`): 3.9.1
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): 
openresty/1.25.3.1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to