# HG changeset patch # User Kim Alvefur # Date 1612300580 -3600 # Node ID 8cb2a64b15da750e70f8a880d01d076f8589e781 # Parent 43e5429ab35593470dba477587e502e4f49706b4 mod_http_file_share: Collect cache hit/miss statistics for downloads diff -r 43e5429ab355 -r 8cb2a64b15da plugins/mod_http_file_share.lua --- a/plugins/mod_http_file_share.lua Tue Feb 02 22:11:53 2021 +0100 +++ b/plugins/mod_http_file_share.lua Tue Feb 02 22:16:20 2021 +0100 @@ -274,6 +274,9 @@ end +local download_cache_hit = module:measure("download_cache_hit", "rate"); +local download_cache_miss = module:measure("download_cache_miss", "rate"); + function handle_download(event, path) -- GET /uploads/:slot+filename local request, response = event.request, event.response; local slot_id = path:match("^[^/]+"); @@ -281,7 +284,7 @@ local cached = upload_cache:get(slot_id); if cached then module:log("debug", "Cache hit"); - -- TODO stats (instead of logging?) + download_cache_hit(); basename = cached.name; filesize = cached.size; filetype = cached.type; @@ -290,6 +293,7 @@ -- TODO cache negative hits? else module:log("debug", "Cache miss"); + download_cache_miss(); local slot, when = errors.coerce(uploads:get(nil, slot_id)); if not slot then module:log("debug", "uploads:get(%q) --> not-found, %s", slot_id, when);