@colyseus/tools 0.15.42 → 0.15.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/report-stats.js +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/tools",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.44",
|
|
4
4
|
"description": "Colyseus Tools for Production",
|
|
5
5
|
"input": "./src/index.ts",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@colyseus/uwebsockets-transport": "^0.15.9"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@pm2/io": "^6.0.1",
|
|
42
43
|
"node-os-utils": "^1.3.7",
|
|
43
44
|
"cors": "^2.8.5",
|
|
44
45
|
"dotenv": "^8.2.0",
|
package/report-stats.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const net = require('net');
|
|
4
5
|
const pm2 = require('pm2');
|
|
5
6
|
|
|
6
7
|
const COLYSEUS_CLOUD_URL = `${process.env.ENDPOINT}/vultr/stats`;
|
|
@@ -55,7 +56,7 @@ pm2.Client.executeRemote('getMonitorData', {}, async function(err, list) {
|
|
|
55
56
|
const aggregate = { ccu: 0, roomcount: 0, };
|
|
56
57
|
const apps = {};
|
|
57
58
|
|
|
58
|
-
list.
|
|
59
|
+
await Promise.all(list.map(async (item) => {
|
|
59
60
|
const env = item.pm2_env;
|
|
60
61
|
const app_id = env.pm_id;
|
|
61
62
|
const uptime = new Date(env.pm_uptime); // uptime in milliseconds
|
|
@@ -88,6 +89,9 @@ pm2.Client.executeRemote('getMonitorData', {}, async function(err, list) {
|
|
|
88
89
|
custom_monitor[key] = Number(axm_monitor[originalKey].value);
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
// check if process .sock file is active
|
|
93
|
+
const socket_is_active = await checkSocketIsActive(`/run/colyseus/${(2567 + env.NODE_APP_INSTANCE)}.sock`);
|
|
94
|
+
|
|
91
95
|
apps[app_id] = {
|
|
92
96
|
pid: item.pid,
|
|
93
97
|
uptime,
|
|
@@ -98,8 +102,9 @@ pm2.Client.executeRemote('getMonitorData', {}, async function(err, list) {
|
|
|
98
102
|
...custom_monitor,
|
|
99
103
|
version,
|
|
100
104
|
node_version,
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
socket_is_active,
|
|
106
|
+
};
|
|
107
|
+
}));
|
|
103
108
|
|
|
104
109
|
const fetchipv4 = await fetch("http://169.254.169.254/v1.json");
|
|
105
110
|
const ip = (await fetchipv4.json()).interfaces[0].ipv4.address;
|
|
@@ -145,3 +150,15 @@ pm2.Client.executeRemote('getMonitorData', {}, async function(err, list) {
|
|
|
145
150
|
process.exit();
|
|
146
151
|
}
|
|
147
152
|
});
|
|
153
|
+
|
|
154
|
+
function checkSocketIsActive(sockFilePath) {
|
|
155
|
+
return new Promise((resolve, _) => {
|
|
156
|
+
const client = net.createConnection({ path: sockFilePath, timeout: 5000 })
|
|
157
|
+
.on('connect', () => {
|
|
158
|
+
client.end(); // close the connection
|
|
159
|
+
resolve(true);
|
|
160
|
+
})
|
|
161
|
+
.on('error', () => resolve(false))
|
|
162
|
+
.on('timeout', () => resolve(false));
|
|
163
|
+
});
|
|
164
|
+
}
|