This module has functions needed to create middlewares for frameworks such as express and koa.
It also exports the 2 functions needed to implement your own middleware.
If you implement a middleware for a framework not implemented here, please contribute it back.
Methods
-
<static> createExpressMiddleware(metricsRegistry [, reportingIntervalInSeconds])
-
Creates an Express middleware that reports a timer on request data.
With this middleware you will get requests counts and latency percentiles all filterable by status codes, http method, and uri paths.Parameters:
Name Type Argument Description metricsRegistry
SelfReportingMetricsRegistry reportingIntervalInSeconds
number <optional>
Returns:
- Type
- function
-
<static> createKoaMiddleware(metricsRegistry [, reportingIntervalInSeconds])
-
Creates a Koa middleware that reports a timer on request data.
With this middleware you will get requests counts and latency percentiles all filterable by status codes, http method, and uri paths.Parameters:
Name Type Argument Description metricsRegistry
SelfReportingMetricsRegistry reportingIntervalInSeconds
number <optional>
Returns:
- Type
- function
-
<static> onRequestEnd(metricsRegistry, stopwatch, method, statusCode [, uri] [, reportingIntervalInSeconds])
-
When the request ends stop the stop watch and create or update the timer for requests that tracked by method, status code, path.
The timers (meters and histograms) that get reported will be filterable by status codes, http method, the uri path.
You will be able to create dash boards such as success percentage, latency percentiles by uri path and method, etc.Parameters:
Name Type Argument Description metricsRegistry
SelfReportingMetricsRegistry The Self Reporting Metrics Registry
stopwatch
Stopwatch The stopwatch created by onRequestStart
method
string The Http Method for the request
statusCode
string | number The status code for the response
uri
string <optional>
The uri path for the request. Please note to avoid out of control time series dimension creation spread,
you would want to strip out ids and or other variables from the uri path.reportingIntervalInSeconds
number <optional>
override the reporting interval defaults to every 10 seconds.
-
<static> onRequestStart()
-
At the start of the request, create a stopwatch, that starts tracking how long the request is taking.
Returns:
- Type
- Stopwatch