user2109354
user2109354

Reputation: 197

Monitor Number of Requests in Sinatra

If I have a specific link in my sinatra, for instance say /requests, how can I monitor the number of times the page is loaded. Ideally, I want to be able to get a hit count for how many times a specific page on my server is accessed. Thanks.

Upvotes: 0

Views: 300

Answers (1)

ch4nd4n
ch4nd4n

Reputation: 4197

There are number of ways to do this. For example, you could add a filters which can log this.

To log the request you can use file system, database, etc. Something like below.

#filter to intercept request to URL
before '/requests' do
  log_request
end
# Helper function to write
def log_request
  # Actual logic to write to file system or database
end

Upvotes: 1

Related Questions