Przeglądaj źródła

Send HTTP request size metric

The metric is a "summary" called http_request_size_bytes.
Eric Mc Sween 6 lat temu
rodzic
commit
4a92be80ea

+ 4 - 1
libraries/metrics/http.coffee

@@ -12,9 +12,12 @@ module.exports.monitor = (logger) ->
 			end.apply(this, arguments)
 			responseTime = process.hrtime(startTime)
 			responseTimeMs = Math.round(responseTime[0] * 1000 + responseTime[1] / 1000)
+			requestSize = parseInt(req.headers["content-length"], 10)
 			if req.route?.path?
 				routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1)
 				Metrics.timing("http_request", responseTimeMs, null, {method:req.method, status_code: res.statusCode, path:routePath})
+				if requestSize
+					Metrics.summary("http_request_size_bytes", requestSize, {method:req.method, path:routePath})
 				remoteIp = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress
 				reqUrl = req.originalUrl || req.url
 				referrer = req.headers['referer'] || req.headers['referrer']
@@ -23,7 +26,7 @@ module.exports.monitor = (logger) ->
 						httpRequest:
 							requestMethod: req.method
 							requestUrl: reqUrl
-							requestSize: req.headers["content-length"]
+							requestSize: requestSize
 							status: res.statusCode
 							responseSize: res._headers?["content-length"]
 							userAgent: req.headers["user-agent"]

+ 8 - 0
libraries/metrics/metrics.coffee

@@ -91,6 +91,14 @@ module.exports = Metrics =
 		if process.env['DEBUG_METRICS']
 			console.log("doing count/inc", key, opts)
 
+	summary : (key, value, opts = {})->
+		key = Metrics.buildPromKey(key)
+		opts.app = appname
+		opts.host = hostname
+		prom.metric('summary', key).observe(opts, value)
+		if process.env['DEBUG_METRICS']
+			console.log("doing summary", key, value, opts)
+
 	timing: (key, timeSpan, sampleRate, opts = {})->
 		key = Metrics.buildPromKey("timer_" + key)
 		opts.app = appname

+ 1 - 1
libraries/metrics/package.json

@@ -1,6 +1,6 @@
 {
   "name": "metrics-sharelatex",
-  "version": "2.5.1",
+  "version": "2.6.0",
   "description": "A drop-in metrics and monitoring module for node.js apps",
   "repository": {
     "type": "git",

+ 3 - 0
libraries/metrics/statsd/metrics.coffee

@@ -29,6 +29,9 @@ module.exports = Metrics =
 	count : (key, count, sampleRate = 1)->
 		statsd.count buildKey(key), count, sampleRate
 
+	summary : (key, value)->
+		# not supported
+
 	timing: (key, timeSpan, sampleRate)->
 		statsd.timing(buildKey(key), timeSpan, sampleRate)