Zhofang commited on
Commit
441a894
·
verified ·
1 Parent(s): 2bb45ea

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +110 -43
app.js CHANGED
@@ -1,47 +1,114 @@
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 = 7860;
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
- // Create the HTTP server
44
- http.createServer(handler).listen(port, () => {
45
- console.log(`Worker ${process.pid} listening on port ${port}`);
46
- });
47
- }
 
1
+ $(function () {
2
+ var mychart;
3
+ var previous = null;
4
+ var count = 0;
5
+ $(window).load(function () {
6
+ initiateChart("container");
7
+ parseFile();
8
+ });
 
9
 
10
+ function parseFile() {
11
+ // actually skidded from vshield, gonna recode it
12
+ $.ajax({
13
+ url: "/nginx_status",
14
+ dataType: "text",
15
+ cache: false,
16
+ })
17
+ .done(function (data) {
18
+ var current = 0;
19
+ var part = data.split(" ")[9];
20
+ var series = mychart.series[0],
21
+ current = parseInt(part);
22
+ shift = series.data.length > 40;
23
+ if (previous !== null) {
24
+ series.addPoint(
25
+ [Math.floor($.now()), current - previous],
26
+ true,
27
+ shift
28
+ );
29
+ }
30
+ previous = current;
31
+ count++;
32
+ // call it again after one second
33
+ setTimeout(parseFile, 1000);
34
+ })
35
+ .fail(function (jqXHR, textStatus, errorThrown) {
36
+ console.log(errorThrown);
37
+ });
38
+ }
39
 
40
+ function initiateChart(divid) {
41
+ mychart = Highcharts.chart("container", {
42
+ chart: {
43
+ type: "area",
44
+ backgroundColor: "#242222",
45
+ },
46
+ title: {
47
+ text: "@renzalwaysnt",
48
+ },
49
+ xAxis: {
50
+ type: "datetime",
51
+ dateTimeLabelFormats: {
52
+ day: "%a",
53
+ },
54
+ gridLineColor: "#7851a9",
55
+ labels: {
56
+ style: {
57
+ color: "#7851a9",
58
+ },
59
+ },
60
+ },
61
+ yAxis: {
62
+ allowDecimals: false,
63
+ labels: {
64
+ formatter: function () {
65
+ if (this.value > 1000) {
66
+ return this.value / 1000 + "k r/s";
67
+ } else {
68
+ return this.value + " r/s";
69
+ }
70
+ },
71
+ },
72
+ },
73
+ tooltip: {
74
+ pointFormat: "Requests: {point.y:,.0f}",
75
+ },
76
+ colors: [
77
+ { linearGradient: [0, 0, 0, 0], stops: [[0, "rgba(120,81,169,1)"]] },
78
+ ],
79
+ plotOptions: {
80
+ area: {
81
+ fillColor: {
82
+ linearGradient: {
83
+ x1: 0,
84
+ y1: 0,
85
+ x2: 0,
86
+ y2: 1,
87
+ },
88
+ stops: [
89
+ [0, "#7851a9"],
90
+ [1, new Highcharts.Color("#7851a9").setOpacity(0).get("rgba")],
91
+ ],
92
+ },
93
+ pointStart: 1940,
94
+ marker: {
95
+ enabled: true,
96
+ symbol: "circle",
97
+ radius: 2,
98
+ states: {
99
+ hover: {
100
+ enabled: true,
101
+ },
102
+ },
103
+ },
104
+ },
105
+ },
106
+ series: [
107
+ {
108
+ name: "Requests",
109
+ data: [],
110
+ },
111
+ ],
112
  });
 
113
  }
114
+ });