changeset 3366:6d1c5ecf72c1

mod_http_upload: Report statistics on upload sizes (0.10+)
author Kim Alvefur <zash@zash.se>
date Mon, 29 Oct 2018 01:21:29 +0100
parents a5a5f85d7ca1
children a83eed629d4b
files mod_http_upload/mod_http_upload.lua
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_upload/mod_http_upload.lua	Mon Oct 29 01:10:10 2018 +0100
+++ b/mod_http_upload/mod_http_upload.lua	Mon Oct 29 01:21:29 2018 +0100
@@ -109,6 +109,13 @@
 	return sum < quota;
 end
 
+local measure_slot = function () end
+if module.measure then
+	-- COMPAT 0.9
+	-- module:measure was added in 0.10
+	measure_slot = module:measure("sizes", "slot");
+end
+
 local function handle_request(origin, stanza, xmlns, filename, filesize)
 	local username, host = origin.username, origin.host;
 	-- local clients only
@@ -157,6 +164,8 @@
 		pending_slots[slot] = nil;
 	end);
 
+	measure_slot(filesize);
+
 	origin.log("debug", "Given upload slot %q", slot);
 
 	local base_url = module:http_url();
@@ -213,6 +222,13 @@
 	return true;
 end);
 
+local measure_upload = function () end
+if module.measure then
+	-- COMPAT 0.9
+	-- module:measure was added in 0.10
+	measure_upload = module:measure("sizes", "upload");
+end
+
 -- http service
 local function upload_data(event, path)
 	local uploader = pending_slots[path];
@@ -252,6 +268,7 @@
 		os.remove(full_filename);
 		return 500;
 	end
+	measure_upload(#event.request.body);
 	module:log("info", "File uploaded by %s to slot %s", uploader, random_dir);
 	return 201;
 end