Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
A fast and compact way to get all your network and process stats for your node application.
A fast and compact way to get all your network and process stats for your node application. Websocket, http/s, express and prometheus compatible!
$ npm install nstats
// ws is a websocket server (ws.js) and httpServer is an http or https node server.
var nstats = require('nstats')(ws, httpServer);
//use it with express
app.use(nstats.express());
//display the stats!
console.log(nstats.data); // non-stringifyed
console.log(nstats.toJson()) // stringifyed
console.log(nstats.toPrometheus()) // prometheus format
// ws is a websocket server (ws.js) and httpServer is an http or https node server.
var nstats = require('nstats')();
//use it with express
app.register(nstats.fastify(),{
ignored_routes:['/metrics','/health']
});
app.get('/metrics', (req, res) => {
res.code(200).send(nstats.toPrometheus());
});
app.get('/health', (req, res) => res.code(200).send('All Systems Nominal'));
//display the stats!
console.log(nstats.data); // non-stringifyed
console.log(nstats.toJson()) // stringifyed
console.log(nstats.toPrometheus()) // prometheus format
Import the Grafana Dashboard example inside the Grafana folder to view the the stats in a graph like manner.
const express = require('express');
const nstats = require('nstats');
const WebSocket = require('ws');
const app = express();
const server = require('http').createServer(app);
const port = 3042;
const wss = new WebSocket.Server({ server });
var stats = require('nstats')(wss, server);
stats.interval = 500;
stats.serverName = "TestServer";
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
ws.send(message);
});
});
app.use(stats.express());
app.get('/', (req, res) => res.send());
app.get('/metrics', (req, res) => res.send(stats.toPrometheus()));
app.get('/stats', (req, res) => {
res.type('json')
stats.calc(()=>res.send(stats.toJson()));
});
server.listen(port, () => console.log(`Example app listening on port ${port}!`));
##Properties
####stats.data
The stats.data
object is a JavaScript object containing all the stats.
{
"uptime": 209.653,
"totalMemory": "29.17",
"activeSockets": 2,
"responseOverhead": {
"avg": 0.5810644392156861,
"highest": 5.175994,
"lowest": 0.260562,
"total": 148.17143199999995
},
"avgWriteKBs": "3.26",
"avgReadKBs": "0.28",
"avgPacketsSecond": "1.22",
"totalBytesWritten": 700381,
"totalMBytesWritten": 0.67,
"totalBytesRead": 60813,
"totalMBytesRead": 0.06,
"writeKBS": "0.00",
"readKBS": "0.00",
"packetsSecond": "0.00",
"totalPackets": 255,
"http": {
"GET": {
"200": 255
}
}
}
feel free to add your own stats you want to keep track off too!
stats.data['foo'] = "some dank stat";
####stats.interval
A time in milliseconds on when the stats will refresh and calculate.
stats.interval = 5000; // default is 1 second
Set this to 0 if you do not want it to loop.
##Methods
stats.addWeb(req,res,sTime)
A method to add network usage for http requests not done with express or w.s. res is optional if you want stats.data.http data. sTime (The start time of when you received the req BigInt) is optional if you want responseOverhead data.
var req = http.get("http://google.com", function(res) {
res.on('end', function() {
stats.addWeb(req, res);
});
});
Since its not express or ws, it does not know about it.
stats.calc()
A method to allow you to manually trigger when the stats are computed.
optional call back can be passed to let you know its done.
stats.calc(function(){
//its done!
console.log(stats.data);
});
FAQs
A fast and compact way to get all your network and process stats for your node application.
The npm package nstats receives a total of 347 weekly downloads. As such, nstats popularity was classified as not popular.
We found that nstats demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.