Socket
Socket
Sign inDemoInstall

swagger-stats

Package Overview
Dependencies
4
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.70.1 to 0.70.2

img/ui.png

9

examples/spectest/spectest.js

@@ -27,2 +27,6 @@ 'use strict';

// JSON formatting
app.set('json spaces', 2);
app.set('json replacer', null);
// all environments

@@ -75,2 +79,7 @@ app.set('port', process.env.PORT || 3040);

app.use(swStats.getMiddleware({
name: 'swagger-stats-testapp',
version: '0.70.1',
nodehostname: "hostname",
nodename: "node-1",
nodeaddress: "127.0.0.1",
timelineBucketDuration: tlBucket,

@@ -77,0 +86,0 @@ swaggerSpec:swaggerSpec

7

examples/testapp/testapp.js

@@ -110,7 +110,6 @@ 'use strict';

// Enable swagger-stats to capture statistics on request / responses
// Enable swagger-stats middleware
app.use(swStats.getMiddleware({
name: 'sws-test-app',
version: '0.60.1',
timelineBucketDuration: tlBucket,
name: 'swagger-stats-testapp',
version: '0.70.1',
swaggerSpec:swaggerSpec

@@ -117,0 +116,0 @@ }));

@@ -9,2 +9,4 @@ /**

var fs = require('fs');
var path = require('path');
var debug = require('debug')('sws:interface');

@@ -23,2 +25,12 @@

var uiMarkup = '<!DOCTYPE html><html><head><title>Swagger Stats UI</title><link href="dist/css/sws.min.css" rel="stylesheet"></head>\
<body>\
<div id="SWSUI"></div>\
<script src="dist/js/sws.min.js"></script>\
<script>\
$(document).ready(function(){$("#SWSUI").swaggerstatsui({});});\
</script>\
</body>\
</html>';
// Request hanlder

@@ -79,3 +91,2 @@ function handleRequest(req, res){

// Respond to requests handled by swagger-stats

@@ -87,4 +98,22 @@ // swagger-stats requests will not be counted in statistics

}else if(req.url =='/swagger-stats/ui'){
// TODO Show UI
res.status(200).send(uiMarkup);
return;
}else if(req.url.startsWith('/swagger-stats/dist')) {
var fileName = req.url.replace('/swagger-stats/dist/','');
var qidx = fileName.indexOf('?');
if(qidx!=-1) fileName = fileName.substring(0,qidx);
var options = {
root: path.join(__dirname,'..','dist'),
dotfiles: 'deny'
// TODO Caching
};
res.sendFile(fileName, options, function (err) {
if (err) {
next(err);
} else {
console.log('Sent:', fileName);
}
});
return;
}

@@ -103,4 +132,2 @@

}
};
{
"name": "swagger-stats",
"version": "0.70.1",
"version": "0.70.2",
"description": "Collect and monitor REST API statistics in node app, based on Swagger API specification",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# swagger-stats
Collect and monitor REST API statistics in node express app based on Swagger API specification or express routes
### Install
```
npm install swagger-stats --save
```
### Enable
```javascript
var swStats = require('swagger-stats');
var app = module.exports = express();
var swaggerSpec = require('swagger.json');
// Enable swagger-stats middleware
app.use(swStats.getMiddleware({
name: 'swagger-stats-testapp',
version: '0.70.1',
swaggerSpec:swaggerSpec
}));
```
See /examples
### Monitor
```
$ curl http://<your app host:port>/swagger-stats/stats
{
"startts": 1495174617959,
"all": {
"requests": 247,
"responses": 246,
"errors": 89,
"info": 0,
"success": 139,
"redirect": 18,
"client_error": 68,
"server_error": 21,
"total_time": 12601,
"max_time": 100,
"avg_time": 51.016194331983804,
"total_req_clength": 12760,
"max_req_clength": 209,
"avg_req_clength": 51,
"total_res_clength": 25361,
"max_res_clength": 200,
"avg_res_clength": 102,
"req_rate": 1.8788726763941634,
"err_rate": 0.6715970417749351
},
"name": "swagger-stats-testapp",
"version": "0.70.1",
"nodehostname": "hostname",
"nodename": "node-1",
"nodeaddress": "127.0.0.1"
}
```
Try also:
```
$ curl http://<your app host:port>/swagger-stats/stats?fields=method
$ curl http://<your app host:port>/swagger-stats/stats?fields=timeline
$ curl http://<your app host:port>/swagger-stats/stats?fields=lasterrors
$ curl http://<your app host:port>/swagger-stats/stats?fields=longestreq
$ curl http://<your app host:port>/swagger-stats/stats?fields=apidefs
$ curl http://<your app host:port>/swagger-stats/stats?fields=apistats
$ curl http://<your app host:port>/swagger-stats/stats?fields=errors
$ curl http://<your app host:port>/swagger-stats/stats?fields=all
```
Or combination:
```
$ curl http://<your app host:port>/swagger-stats/stats?fields=method,timeline
$ curl http://<your app host:port>/swagger-stats/stats?fields=all
$ curl http://<your app host:port>/swagger-stats/stats?fields=*
```
### User Interface
```
http://<your app host:port>/swagger-stats/ui
```
![alt text](img/ui.png "swagger-stats bundled User Interface")

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc