@opengis/fastify-table 2.0.81 → 2.0.82

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.
@@ -1 +1 @@
1
- {"version":3,"file":"loggerSystem.d.ts","sourceRoot":"","sources":["../../../../server/plugins/metric/loggerSystem.ts"],"names":[],"mappings":"AAsBA,wBAA8B,YAAY,CACxC,GAAG,CAAC,EAAE,GAAG,GACR,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAsJ9B"}
1
+ {"version":3,"file":"loggerSystem.d.ts","sourceRoot":"","sources":["../../../../server/plugins/metric/loggerSystem.ts"],"names":[],"mappings":"AAgDA,wBAA8B,YAAY,CACxC,GAAG,CAAC,EAAE,GAAG,GACR,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAsJ9B"}
@@ -14,35 +14,50 @@ const filesFolder = getFolder(config);
14
14
  const redisKey = "logger-process-online";
15
15
  const sqlQuery = `select datname as dbname, application_name as app, client_addr as client_ip,
16
16
  (now()-backend_start)::text as msec, state, query from pg_stat_activity where datname=$1`;
17
+ const prev = {};
18
+ const cpuUsage = () => {
19
+ const usage = process.cpuUsage();
20
+ const cpus = os.cpus();
21
+ const total = cpus.reduce((acc, curr) => acc + Object.values(curr.times).reduce((a, b) => a + b, 0), 0);
22
+ if (!prev.usage || !prev.total) {
23
+ Object.assign(prev, { usage, total });
24
+ return 0;
25
+ }
26
+ const diffUsage = (usage.user - prev.usage.user + usage.system - prev.usage.system) / 1000;
27
+ const diffTotal = total - prev.total;
28
+ Object.assign(prev, { usage, total });
29
+ return (diffUsage / diffTotal) * cpus.length * 100;
30
+ };
31
+ cpuUsage();
17
32
  export default async function loggerSystem(req) {
18
33
  const { pg = pgClients.client } = req || {};
19
34
  const dbName = pg?.options?.database;
20
35
  const dbsize = config.redis
21
36
  ? await rclient.get(`${dbName}:content:dbsize:${redisKey}`)
22
37
  : null;
23
- const dbVerion = await pg
24
- .query("select version();")
25
- .then((el) => el.rows?.[0]?.version);
38
+ const dbVerion = pg?.query
39
+ ? await pg
40
+ .query("select version();")
41
+ .then((el) => el.rows?.[0]?.version)
42
+ : null;
26
43
  const dbSize = dbsize ||
27
- (await pg
28
- .query(`select pg_size_pretty(pg_database_size($1))`, [dbName])
29
- .then((el) => el.rows?.[0]?.pg_size_pretty));
30
- const query = await pg
31
- .query(sqlQuery, [dbName])
32
- .then((el) => el.rows || []);
44
+ (pg?.query
45
+ ? await pg
46
+ .query(`select pg_size_pretty(pg_database_size($1))`, [dbName])
47
+ .then((el) => el.rows?.[0]?.pg_size_pretty)
48
+ : null);
49
+ const query = pg?.query
50
+ ? await pg.query(sqlQuery, [dbName]).then((el) => el.rows || [])
51
+ : null;
33
52
  const { stdout: topProcess } = platform === "win32"
34
53
  ? { stdout: "Cant show top on this system type" }
35
54
  : await execAsync("top -b -n 1");
36
55
  const osInfo = `${os.version()} ${os.machine?.() || ""}`;
37
56
  const cpuInfo = os.cpus();
38
- const totalCpu = Object.values(cpuInfo?.[0]?.times || {}).reduce((acc, tv) => acc + tv, 0) *
39
- cpuInfo.length;
40
57
  const totalMemory = os.totalmem();
41
58
  const memory = process.memoryUsage();
42
59
  const resource = process.resourceUsage();
43
- const currentCpuUsage = (((process.cpuUsage().user + process.cpuUsage().system) * 1000) /
44
- totalCpu) *
45
- 100;
60
+ const currentCpuUsage = cpuUsage();
46
61
  const redisInfo = config.redis ? await rclient.info() : "";
47
62
  const lines = redisInfo.split("\r\n").filter((el) => el && el.split);
48
63
  const redis = {};
@@ -56,9 +71,11 @@ export default async function loggerSystem(req) {
56
71
  await rclient.set(`${dbName}:content:dbsize:${redisKey}`, dbSize, "EX", 30 * 60);
57
72
  }
58
73
  const latency = config.redis ? await rclient.latency("latest") : null;
59
- const uptime = await pg
60
- .query("select extract('epoch' from current_timestamp - pg_postmaster_start_time())::int as uptime")
61
- .then((el) => el.rows?.[0]?.uptime);
74
+ const uptime = pg?.query
75
+ ? await pg
76
+ .query("select extract('epoch' from current_timestamp - pg_postmaster_start_time())::int as uptime")
77
+ .then((el) => el.rows?.[0]?.uptime)
78
+ : null;
62
79
  const metric5 = config.redis
63
80
  ? await rclient2.hgetall(`${dbName}:system_metrics`)
64
81
  : {};
@@ -1 +1 @@
1
- {"version":3,"file":"pgClients.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/pgClients.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;AAgB1C,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"pgClients.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/pgClients.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;AAiB1C,eAAe,SAAS,CAAC"}
@@ -10,6 +10,7 @@ if (config.pg) {
10
10
  user: config.pg?.user || "postgres",
11
11
  password: config.pg?.password || "postgres",
12
12
  statement_timeout: config.pg?.statement_timeout || 10000,
13
+ connectionTimeoutMillis: config.pg?.connectionTimeoutMillis || 5000,
13
14
  });
14
15
  client.init = async () => {
15
16
  await init(client);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.81",
3
+ "version": "2.0.82",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [