├── .gitignore
├── README.md
├── index.html
├── index.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | package-lock.json
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Welcome to layer7-dstat 👋
2 |
3 | > A simple layer7 dstat on the web
4 |
5 |
6 | Demo
7 |
8 |
9 |
10 |
11 |
12 | ## Install
13 |
14 | ```sh
15 | npm install
16 | ```
17 |
18 | ## Usage
19 |
20 | ```sh
21 | npm run start
22 | ```
23 |
24 | ## Author
25 |
26 | 👤 **Filippo Finke**
27 |
28 | - Website: https://filippofinke.ch
29 | - Github: [@filippofinke](https://github.com/filippofinke)
30 | - LinkedIn: [@filippofinke](https://linkedin.com/in/filippofinke)
31 |
32 | ## Show your support
33 |
34 | Give a ⭐️ if this project helped you!
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Layer7 - DSTAT
7 |
36 |
37 |
38 |
39 |
43 |
44 |
45 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const http = require("http");
2 | const fs = require("fs");
3 | const WebSocket = require("ws");
4 | const cluster = require("cluster");
5 | const os = require("os");
6 |
7 | const cpus = os.cpus().length;
8 | const port = 8080;
9 | const index = fs.readFileSync("./index.html");
10 |
11 | if (cluster.isMaster) {
12 | console.log(`Number of CPUs is ${cpus}`);
13 | console.log(`Master ${process.pid} is running`);
14 |
15 | let requests = 0;
16 | let childs = [];
17 | for (let i = 0; i < cpus; i++) {
18 | let child = cluster.fork();
19 | child.on("message", (msg) => {
20 | requests++;
21 | });
22 | childs.push(child);
23 | }
24 |
25 | setInterval(() => {
26 | for (let child of childs) {
27 | child.send(requests);
28 | }
29 | requests = 0;
30 | }, 1000);
31 | } else {
32 | console.log(`Worker ${process.pid} started`);
33 |
34 | const handler = function (req, res) {
35 | if (req.url == "/dstat") {
36 | process.send(0);
37 | res.end();
38 | } else {
39 | res.end(index);
40 | }
41 | };
42 |
43 | const server = http.createServer(handler);
44 | const wss = new WebSocket.Server({ server });
45 |
46 | process.on("message", (requests) => {
47 | wss.clients.forEach((client) => client.send(requests));
48 | });
49 |
50 | server.listen(port);
51 | }
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "layer7-dstat",
3 | "version": "1.0.0",
4 | "description": "A simple layer7 dstat on the web",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node index.js"
8 | },
9 | "keywords": [],
10 | "author": "Filippo Finke",
11 | "dependencies": {
12 | "ws": "^7.2.1"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/filippofinke/layer7-dstat.git"
17 | }
18 | }
--------------------------------------------------------------------------------