Gathering detailed insights and metrics for swagger-stats-ioredis
Gathering detailed insights and metrics for swagger-stats-ioredis
npm install swagger-stats-ioredis
Typescript
Module System
Node Version
NPM Version
69.6
Supply Chain
96.7
Quality
72.6
Maintenance
50
Vulnerability
99.3
License
Total Downloads
1,150
Last Day
1
Last Week
11
Last Month
32
Last Year
376
Minified
Minified + Gzipped
Latest Version
1.0.4
Package Id
swagger-stats-ioredis@1.0.4
Unpacked Size
5.07 MB
Size
1.62 MB
File Count
92
NPM Version
8.19.2
Node Version
16.18.0
Publised On
05 Jun 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-15.4%
11
Compared to previous week
Last month
255.6%
32
Compared to previous month
Last year
-51.4%
376
Compared to previous year
1
swagger-stats traces REST API requests and responses in Node.js Microservices, and collects statistics per API Operation. swagger-stats detects API operations based on express routes. You may also provide Swagger (Open API) specification, and swagger-stats will match API requests with API Operations defined in swagger specification.
swagger-stats exposes statistics and metrics per API Operation, such as GET /myapi/:parameter
, or GET /pet/{petId}
swagger-stats provides built-in Telemetry UX, so you may enable swagger-stats in your app, and start monitoring immediately, with no infrastructure requirements. Navigate to
http://<your app host:port>/swagger-stats/
swagger-stats stores details about each request/response in Elasticsearch, so you may use Kibana to perform detailed analysis of API usage over time, build visualizations and dashboards
See dashboards/elastic6
for swagger-stats Kibana visualizations and dashboards
swagger-stats exposes metrics in Prometheus format, so you may use Prometheus and Grafana to setup API monitoring and alerting
See dashboards/prometheus
for swagger-stats Grafana dashboards
With statistics and metrics exposed by swagger-stats you may spot problematic API endpoints, see where most of errors happens, catch long-running requests, analyze details of last errors, observe trends, setup alerting.
swagger-stats provides:
npm install swagger-stats --save
If you haven't added prom-client already, you should do this now. It's a peer dependency of swagger-stats as of version 0.95.19.
npm install prom-client@12 --save
1const swStats = require('swagger-stats'); 2const apiSpec = require('swagger.json'); 3app.use(swStats.getMiddleware({swaggerSpec:apiSpec}));
1const swStats = require('swagger-stats'); 2const apiSpec = require('swagger.json'); 3 4const fastify = require('fastify')({ 5 logger: true 6}); 7 8// Enable swagger-stats 9fastify.register(require('fastify-express')).then(()=>{ 10 fastify.register(swStats.getFastifyPlugin, {swaggerSpec:apiSpec}); 11}); 12
express-to-koa
can be used which is just a simple Promise
wrapper.
1const swStats = require('swagger-stats'); 2const apiSpec = require('swagger.json'); 3const e2k = require('express-to-koa'); 4app.use(e2k(swStats.getMiddleware({ swaggerSpec:apiSpec })));
1const swStats = require('swagger-stats'); 2const swaggerSpec = require('./petstore.json'); 3 4const init = async () => { 5 6 server = Hapi.server({ 7 port: 3040, 8 host: 'localhost' 9 }); 10 11 await server.register({ 12 plugin: swStats.getHapiPlugin, 13 options: { 14 swaggerSpec:swaggerSpec 15 } 16 }); 17 18 await server.start(); 19 console.log('Server running on %s', server.info.uri); 20};
1const restify = require('restify'); 2const swStats = require('swagger-stats'); 3const apiSpec = require('swagger.json'); 4 5const server = restify.createServer(); 6 7server.pre(swStats.getMiddleware({ 8 swaggerSpec:apiSpec, 9}));
See /examples
for sample apps
$ curl http://<your app host:port>/swagger-stats/stats
{
"startts": 1501647865959,
"all": {
"requests": 7,
"responses": 7,
"errors": 3,
"info": 0,
"success": 3,
"redirect": 1,
"client_error": 2,
"server_error": 1,
"total_time": 510,
"max_time": 502,
"avg_time": 72.85714285714286,
"total_req_clength": 0,
"max_req_clength": 0,
"avg_req_clength": 0,
"total_res_clength": 692,
"max_res_clength": 510,
"avg_res_clength": 98,
"req_rate": 1.0734549915657108,
"err_rate": 0.4600521392424475
},
"sys": {
"rss": 59768832,
"heapTotal": 36700160,
"heapUsed": 20081776,
"external": 5291923,
"cpu": 0
},
"name": "swagger-stats-testapp",
"version": "0.90.1",
"hostname": "hostname",
"ip": "127.0.0.1"
}
Take a look at Documentation for more details on API and returned statistics.
$ curl http://<your app host:port>/swagger-stats/metrics
# HELP api_all_request_total The total number of all API requests received
# TYPE api_all_request_total counter
api_all_request_total 88715
# HELP api_all_success_total The total number of all API requests with success response
# TYPE api_all_success_total counter
api_all_success_total 49051
# HELP api_all_errors_total The total number of all API requests with error response
# TYPE api_all_errors_total counter
api_all_errors_total 32152
# HELP api_all_client_error_total The total number of all API requests with client error response
# TYPE api_all_client_error_total counter
api_all_client_error_total 22986
. . . . . . . . . .
To collect prom-client default metrics:
1const swaggerStats = require('swagger-stats'); 2const promClient = require('prom-client'); 3 4promClient.collectDefaultMetrics();
Some Node.js specific metrics are included, such as event loop lag:
# HELP nodejs_eventloop_lag_seconds Lag of event loop in seconds.
# TYPE nodejs_eventloop_lag_seconds gauge
nodejs_eventloop_lag_seconds 0.000193641 1597303877464
. . . . . . . . . .
See Changelog
If you find a bug, or have an enhancement in mind please post issues on GitHub.
MIT
No vulnerabilities found.
No security vulnerabilities found.