forked from bssr-nodes/bssr-nodes-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodestatsChecker.js
108 lines (100 loc) · 3.87 KB
/
nodestatsChecker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const axios = require("axios");
const ping = require("ping-tcp-js");
const chalk = require("chalk");
let pingLocals = {
UK: config.Ping.UK,
CA: config.Ping.CA,
EU: config.Ping.EU,
};
let stats = {
node1: {
serverID: "52db8185",
IP: config.Nodes.node1,
ID: "17",
Location: pingLocals.UK,
},
node2: {
serverID: "f3e4e60a",
IP: config.Nodes.node2,
ID: "9",
Location: pingLocals.UK,
},
car: {
serverID: "f3e5h71c",
IP: config.Nodes.car,
ID: "9",
Location: pingLocals.EU,
}
};
if (config.Enabled.nodestatsChecker) {
console.log(chalk.magenta("[NODE CHECKER] ") + chalk.green("Enabled"));
// Node status
setInterval(() => {
// Public and private nodes
for (let [node, data] of Object.entries(stats)) {
setTimeout(() => {
axios({
url: `http://${data.Location}?ip=${data.IP}&port=22`,
method: "POST",
headers: {
"Content-Type": "application/json",
},
}).then((response) => {
let pingData = response.data.ping;
if (isNaN(pingData)) {
pingData = "0";
}
nodePing.set(node, {
ip: response.data.address,
ping: pingData,
});
}).catch((error) => {});
axios({
url: `${config.Pterodactyl.hosturl}/api/client/servers/${data.serverID}/resources`,
method: "GET",
followRedirect: true,
maxRedirects: 5,
headers: {
Authorization: `Bearer ${config.Pterodactyl.apikeyclient}`,
"Content-Type": "application/json",
Accept: "Application/vnd.pterodactyl.v1+json",
},
}).then((response) => {
nodeStatus.set(`${node}.timestamp`, Date.now());
nodeStatus.set(`${node}.status`, true);
nodeStatus.set(`${node}.is_vm_online`, true);
}).catch((error) => {
ping.ping(data.IP, 22).then(() => {
nodeStatus.set(`${node}.timestamp`, Date.now());
nodeStatus.set(`${node}.status`, false);
nodeStatus.set(`${node}.is_vm_online`, true);
}).catch((e) => {
nodeStatus.set(`${node}.timestamp`, Date.now());
nodeStatus.set(`${node}.status`, false);
nodeStatus.set(`${node}.is_vm_online`, false);
});
});
setTimeout(() => {
axios({
url: `${config.Pterodactyl.hosturl}/api/application/nodes/${data.ID}/allocations?per_page=9000`,
method: "GET",
followRedirect: true,
maxRedirects: 5,
headers: {
Authorization: `Bearer ${config.Pterodactyl.apikey}`,
"Content-Type": "application/json",
Accept: "Application/vnd.pterodactyl.v1+json",
},
}).then((response) => {
const serverCount = response.data.data.filter((m) => m.attributes.assigned === true).length;
nodeServers.set(node, {
servers: serverCount,
});
}).catch((err) => {});
}, 2000);
}, 2000);
}
}, 10000);
} else {
console.log(chalk.magenta("[NODE CHECKER] ") + chalk.red("Disabled"));
}