I would suggest adding a piece of Rack middleware to the top of the middleware stack, which increments the counter for the request path.
For example, to do this using Redis:
# lib/request_counter.rb class RequestCounter def self.redis @redis ||= Redis.new(host: ENV["REDIS_HOST"], port: ENV["REDIS_PORT"]) end def initialize(app) @app = app end def call(env) request = Rack::Request.new(env) self.class.redis.incr "request_counter:#{request.fullpath}" @app.call(env) end end
This would mean that every request /path
would increment the Redis key request_counter:/path
source share