Eliminates the grunt work of building consistent metric keys from complex API paths and acquiring response time.
Accepts the metric (i.e. StatsD) client of your choice, such as the popular Etsy's StatsD, Datadog, etc...
The client must implement or be adapted the provided MetricsClient interface.
interface MetricsClient {
timing(key: string, milliseconds: number): void;
increment(key: string): void;
incrementBy(key: string, value: number): void;
decrement(key: string): void;
decrementBy(key: string, value: number): void;
gauge(key: string, value: number): void;
histogram(key: string, value: number): void;
close(): void;
}
Depends on the following portions of Restify's RouteSpec, Request, and Response interface:
RouteSpec.path
for the string or RegExp path definition.RouteSpec.method
for the HTTP verb.Response.getHeader('Response-Time')
andRequest.time()
as a backup for determining response time.
let metricsLogger = new ApiMetricsLogger(client, options);
server.on('after', (request: any, response: Response, route: Route, error) => {
metricsLogger.logResponseMetrics(request, response, route, error);
});
timing
boolean log the timing for each request.default = true
increment
boolean increment for each request.default = true
ISC License
Copyright (c) 2016, Changepoint
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Based on the work originally done by jtrinklein here.