Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-stats

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-stats

Telemetry for your APIs. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices, based on express routes and Swagger (Open API) specification

  • 0.93.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
decreased by-25.11%
Maintainers
1
Weekly downloads
 
Created
Source

swagger-stats

swagger-stats

http://swaggerstats.io | Documentation | API DOC | API SPEC

Build Status Dependencies Coverage Status Tested on APIs.guru npm version

Telemetry for your APIs

Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices

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}

Monitoring with Prometheus and Grafana

swagger-stats exposes metrics in Prometheus format, so you may use Prometheus and Grafana to setup API monitoring and alerting

swagger-stats Prometheus Dashboard

See dashboards/prometheus for swagger-stats Grafana dashboards

Embedded Monitoring

swagger-stats provides built-in Monitoring UI, so you may enable swagger-stats in your app, and start monitoring immediately, with no infrastructure requirements

swagger-stats Built-In Monitoring

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:

  • CPU and Memory Usage of Node process
  • Counts of requests and responses(total and by response class), processing time (total/avg/max), content length(total/avg/max) for requests and responses, rates for requests and errors. This is baseline set of stats.
  • Statistics by Request Method: baseline stats collected for each request method
  • Timeline: baseline stats collected for each 1 minute interval during last 60 minutes. Timeline helps you to analyze trends.
  • Errors: count of responses per each error code, top "not found" resources, top "server error" resources
  • Last errors: request and response details for the last 100 errors (last 100 error responses)
  • Longest requests: request and response details for top 100 requests that took longest time to process (time to send response)
  • Tracing: Request and Response details - method, URLs, parameters, request and response headers, addresses, start/stop times and processing duration, matched API Operation info
  • API Statistics: baseline stats and parameter stats per each API Operation. API operation detected based on express routes, and based on Swagger (Open API) specification
  • Metrics in Prometheus format, so you may use Prometheus and Grafana to setup API monitoring and alerting

How to Use

Install

npm install swagger-stats --save

Enable swagger-stats middleware in your app

var swStats = require('swagger-stats');
var apiSpec = require('swagger.json');
app.use(swStats.getMiddleware({swaggerSpec:apiSpec}));

See /examples for sample apps

Get Statistics with API

$ 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.

Get Prometheus Metrics

$ 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

. . . . . . . . . .  

Embedded Monitoring User Interface

Swagger-stats comes with built-in User Interface. Navigate to /swagger-stats/ui in your app to start monitoring right away

http://<your app host:port>/swagger-stats/ui
Key metrics

swagger-stats bundled User Interface

Timeline

swagger-stats bundled User Interface

Request and error rates

swagger-stats bundled User Interface

API Operations

swagger-stats bundled User Interface

Stats By Method

swagger-stats bundled User Interface

Updates

v0.93.0
  • [feature] Support providing Prometheus metrics via prom-client library #20
v0.92.0
  • [feature] OnResponseFinish hook: pass request/response record to callback so app can post proceses it add it to the log #5
v0.91.0
  • [feature] Option to specify alternative URI path for ui,stats and metrics #17
app.use(swStats.getMiddleware({
   uriPath: '/myservice',
   swaggerSpec:swaggerSpec
}));
$ curl http://<your app host:port>/myservice/stats
v0.90.3
  • [feature] Added new chart to API Operation Page #16
    • handle time histogram
    • request size histogram
    • response size histogram
    • response codes counts
v0.90.2
v0.90.1
  • [feature] Added CPU and Memory Usage Stats and monitoring in UI #8

Enhancements and Bug Reports

If you find a bug, or have an enhancement in mind please post issues on GitHub.

License

MIT

Keywords

FAQs

Package last updated on 24 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc