@arcblock/pm2-prom-module 2.6.6 → 2.6.8

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/core/app.js CHANGED
@@ -59,6 +59,7 @@ class App {
59
59
  status: pidData.status,
60
60
  appUrl: pidData.appUrl,
61
61
  appName: pidData.appName,
62
+ appPid: pidData.appPid,
62
63
  };
63
64
  }
64
65
  else {
package/core/pm2.js CHANGED
@@ -49,6 +49,7 @@ const updateAppPidsData = (workingApp, pidData) => {
49
49
  status: pidData.status,
50
50
  appUrl: pidData.appUrl,
51
51
  appName: pidData.appName,
52
+ appPid: pidData.appPid,
52
53
  });
53
54
  };
54
55
  const detectActiveApps = () => {
@@ -95,6 +96,7 @@ const detectActiveApps = () => {
95
96
  status: pm2_env.status,
96
97
  appUrl: pm2_env.BLOCKLET_APP_URL,
97
98
  appName: pm2_env.BLOCKLET_APP_NAME,
99
+ appPid: pm2_env.BLOCKLET_APP_PID,
98
100
  };
99
101
  }
100
102
  });
@@ -161,6 +163,9 @@ const detectActiveApps = () => {
161
163
  if (stats && Object.keys(stats).length) {
162
164
  for (const [pid, stat] of Object.entries(stats)) {
163
165
  const pidId = Number(pid);
166
+ if (!stat) {
167
+ continue;
168
+ }
164
169
  if (pidId && pidsMonit[pidId]) {
165
170
  pidsMonit[pidId].cpu = Math.round(stat.cpu * 10) / 10;
166
171
  pidsMonit[pidId].memory = stat.memory;
@@ -220,16 +225,19 @@ const detectActiveApps = () => {
220
225
  return () => __awaiter(void 0, void 0, void 0, function* () {
221
226
  return {
222
227
  appName: app.appName,
228
+ appPid: app.appPid,
223
229
  urls: yield (0, domain_1.getAppDomainList)(app.appUrl),
224
230
  };
225
231
  });
226
- }), { concurrency: 8 }).then((apps) => {
232
+ }), { concurrency: 8 })
233
+ .then((apps) => {
227
234
  for (const app of apps) {
228
235
  for (const url of app.urls) {
229
- metrics_1.metricAppDomainList === null || metrics_1.metricAppDomainList === void 0 ? void 0 : metrics_1.metricAppDomainList.set({ appName: app.appName, domain: url }, app.urls.length);
236
+ metrics_1.metricAppDomainList === null || metrics_1.metricAppDomainList === void 0 ? void 0 : metrics_1.metricAppDomainList.set({ appName: app.appName, domain: url, appPid: app.appPid }, app.urls.length);
230
237
  }
231
238
  }
232
- }).catch(error => console.error(error));
239
+ })
240
+ .catch((error) => console.error(error));
233
241
  });
234
242
  };
235
243
  const startPm2Connect = (conf) => {
package/metrics/index.js CHANGED
@@ -151,7 +151,7 @@ const initMetrics = (prefix) => {
151
151
  name: `${prefix}_${METRIC_APP_DOMAIN_LIST}`,
152
152
  help: 'Show app domain list',
153
153
  registers: [exports.registry],
154
- labelNames: ['appName', 'domain'],
154
+ labelNames: ['appName', 'domain', 'appPid'],
155
155
  });
156
156
  exports.metricAppAverageMemory = new prom_client_1.default.Gauge({
157
157
  name: `${prefix}_${METRIC_APP_AVERAGE_MEMORY}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/pm2-prom-module",
3
- "version": "2.6.6",
3
+ "version": "2.6.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/utils/domain.js CHANGED
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAppDomainList = getAppDomainList;
16
16
  const is_url_1 = __importDefault(require("is-url"));
17
- const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
18
17
  const ufo_1 = require("ufo");
19
18
  const keyv_1 = __importDefault(require("keyv"));
20
19
  const sqlite_1 = __importDefault(require("@keyv/sqlite"));
@@ -39,14 +38,15 @@ function getAppDomainList(url) {
39
38
  return [url];
40
39
  }
41
40
  if (yield appDomainListCache.has(url)) {
42
- return yield appDomainListCache.get(url);
41
+ return (yield appDomainListCache.get(url));
43
42
  }
44
43
  const response = yield fetch((0, ufo_1.joinURL)(url, '__blocklet__.js?type=json'));
45
- const domainAliases = ((_a = (yield response.json())) === null || _a === void 0 ? void 0 : _a.domainAliases) || [];
46
- if (!(0, isEmpty_1.default)(domainAliases)) {
44
+ const domainAliases = (_a = (yield response.json())) === null || _a === void 0 ? void 0 : _a.domainAliases;
45
+ if (Array.isArray(domainAliases) && domainAliases.length) {
47
46
  yield appDomainListCache.set(url, domainAliases);
47
+ return domainAliases;
48
48
  }
49
- return domainAliases || [url];
49
+ return [url];
50
50
  }
51
51
  catch (error) {
52
52
  console.error(error);