@harperfast/harper-pro 5.0.6 → 5.0.7

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.
Files changed (104) hide show
  1. package/core/bin/status.js +2 -2
  2. package/core/bin/stop.js +6 -5
  3. package/core/components/EntryHandler.ts +2 -4
  4. package/core/components/Scope.ts +1 -1
  5. package/core/components/componentLoader.ts +4 -11
  6. package/core/components/requestRestart.ts +2 -17
  7. package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.js +25 -0
  8. package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js +34 -0
  9. package/core/package-lock.json +63 -971
  10. package/core/resources/DatabaseTransaction.ts +3 -8
  11. package/core/resources/Table.ts +17 -12
  12. package/core/resources/databases.ts +2 -2
  13. package/core/resources/graphql.ts +165 -163
  14. package/core/resources/indexes/HierarchicalNavigableSmallWorld.ts +3 -14
  15. package/core/resources/indexes/vector.ts +0 -17
  16. package/core/resources/loadEnv.ts +16 -20
  17. package/core/resources/login.ts +3 -4
  18. package/core/resources/roles.ts +65 -60
  19. package/core/security/auth.ts +14 -15
  20. package/core/security/jsLoader.ts +2 -14
  21. package/core/server/REST.ts +11 -10
  22. package/core/server/fastifyRoutes.ts +29 -30
  23. package/core/server/graphqlQuerying.ts +3 -4
  24. package/core/server/http.ts +1 -175
  25. package/core/server/mqtt.ts +2 -8
  26. package/core/server/serverHelpers/serverUtilities.ts +5 -2
  27. package/core/server/threads/threadServer.js +2 -30
  28. package/core/server/throttle.ts +0 -18
  29. package/core/utility/environment/environmentManager.js +4 -10
  30. package/core/utility/environment/systemInformation.js +355 -0
  31. package/core/utility/hdbTerms.ts +0 -1
  32. package/core/utility/operation_authorization.js +5 -2
  33. package/dist/core/bin/status.js +2 -2
  34. package/dist/core/bin/status.js.map +1 -1
  35. package/dist/core/bin/stop.js +5 -5
  36. package/dist/core/bin/stop.js.map +1 -1
  37. package/dist/core/components/EntryHandler.js +2 -4
  38. package/dist/core/components/EntryHandler.js.map +1 -1
  39. package/dist/core/components/Scope.js +1 -1
  40. package/dist/core/components/Scope.js.map +1 -1
  41. package/dist/core/components/componentLoader.js +3 -11
  42. package/dist/core/components/componentLoader.js.map +1 -1
  43. package/dist/core/components/requestRestart.js +1 -12
  44. package/dist/core/components/requestRestart.js.map +1 -1
  45. package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.js +24 -0
  46. package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.js.map +1 -0
  47. package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js +19 -18
  48. package/dist/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js.map +1 -1
  49. package/dist/core/resources/DatabaseTransaction.js +1 -6
  50. package/dist/core/resources/DatabaseTransaction.js.map +1 -1
  51. package/dist/core/resources/Table.js +18 -14
  52. package/dist/core/resources/Table.js.map +1 -1
  53. package/dist/core/resources/databases.js +1 -2
  54. package/dist/core/resources/databases.js.map +1 -1
  55. package/dist/core/resources/graphql.js +176 -176
  56. package/dist/core/resources/graphql.js.map +1 -1
  57. package/dist/core/resources/indexes/HierarchicalNavigableSmallWorld.js +2 -14
  58. package/dist/core/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
  59. package/dist/core/resources/indexes/vector.js +0 -14
  60. package/dist/core/resources/indexes/vector.js.map +1 -1
  61. package/dist/core/resources/loadEnv.js +17 -20
  62. package/dist/core/resources/loadEnv.js.map +1 -1
  63. package/dist/core/resources/login.js +4 -4
  64. package/dist/core/resources/login.js.map +1 -1
  65. package/dist/core/resources/roles.js +68 -64
  66. package/dist/core/resources/roles.js.map +1 -1
  67. package/dist/core/security/auth.js +15 -17
  68. package/dist/core/security/auth.js.map +1 -1
  69. package/dist/core/security/jsLoader.js +2 -16
  70. package/dist/core/security/jsLoader.js.map +1 -1
  71. package/dist/core/server/REST.js +11 -11
  72. package/dist/core/server/REST.js.map +1 -1
  73. package/dist/core/server/fastifyRoutes.js +29 -30
  74. package/dist/core/server/fastifyRoutes.js.map +1 -1
  75. package/dist/core/server/graphqlQuerying.js +4 -5
  76. package/dist/core/server/graphqlQuerying.js.map +1 -1
  77. package/dist/core/server/http.js +0 -179
  78. package/dist/core/server/http.js.map +1 -1
  79. package/dist/core/server/mqtt.js +3 -5
  80. package/dist/core/server/mqtt.js.map +1 -1
  81. package/dist/core/server/serverHelpers/serverUtilities.js +2 -2
  82. package/dist/core/server/serverHelpers/serverUtilities.js.map +1 -1
  83. package/dist/core/server/threads/threadServer.js +2 -26
  84. package/dist/core/server/threads/threadServer.js.map +1 -1
  85. package/dist/core/server/throttle.js +0 -17
  86. package/dist/core/server/throttle.js.map +1 -1
  87. package/dist/core/utility/environment/environmentManager.js +4 -9
  88. package/dist/core/utility/environment/environmentManager.js.map +1 -1
  89. package/dist/core/utility/environment/systemInformation.js +219 -359
  90. package/dist/core/utility/environment/systemInformation.js.map +1 -1
  91. package/dist/core/utility/hdbTerms.js +0 -1
  92. package/dist/core/utility/hdbTerms.js.map +1 -1
  93. package/dist/core/utility/operation_authorization.js +2 -2
  94. package/dist/core/utility/operation_authorization.js.map +1 -1
  95. package/npm-shrinkwrap.json +54 -974
  96. package/package.json +1 -2
  97. package/studio/web/assets/{index-qbLPhOzw.js → index-C0And10y.js} +2 -2
  98. package/studio/web/assets/{index-qbLPhOzw.js.map → index-C0And10y.js.map} +1 -1
  99. package/studio/web/index.html +1 -1
  100. package/core/dataLayer/harperBridge/TableSizeObject.ts +0 -35
  101. package/core/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.ts +0 -24
  102. package/core/utility/environment/systemInformation.ts +0 -698
  103. package/dist/core/dataLayer/harperBridge/TableSizeObject.js +0 -32
  104. package/dist/core/dataLayer/harperBridge/TableSizeObject.js.map +0 -1
@@ -1,87 +1,25 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.SystemInformationResponse = exports.SystemInformationRequest = void 0;
40
- exports.getTimeInfo = getTimeInfo;
41
- exports.getCPUInfo = getCPUInfo;
42
- exports.getMemoryInfo = getMemoryInfo;
43
- exports.getHDBProcessInfo = getHDBProcessInfo;
44
- exports.getDiskInfo = getDiskInfo;
45
- exports.getNetworkInfo = getNetworkInfo;
46
- exports.getSystemInformation = getSystemInformation;
47
- exports.getTableSize = getTableSize;
48
- exports.getMetrics = getMetrics;
49
- exports.systemInformation = systemInformation;
50
- const promises_1 = require("node:fs/promises");
51
- const node_path_1 = __importDefault(require("node:path"));
52
- const systeminformation_1 = __importDefault(require("systeminformation"));
53
- const harper_logger_js_1 = __importDefault(require("../logging/harper_logger.js"));
54
- const hdbTerms = __importStar(require("../hdbTerms.js"));
55
- const lmdbGetTableSize_ts_1 = require("../../dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js");
56
- const manageThreads_js_1 = require("../../server/threads/manageThreads.js");
57
- const environmentManager_js_1 = __importDefault(require("./environmentManager.js"));
58
- const databases_ts_1 = require("../../resources/databases.js");
59
- const TableSizeObject_ts_1 = require("../../dataLayer/harperBridge/TableSizeObject.js");
60
- const rocksdb_js_1 = require("@harperfast/rocksdb-js");
61
- environmentManager_js_1.default.initSync();
1
+ 'use strict';
2
+ const fs = require('fs-extra');
3
+ const path = require('path');
4
+ const si = require('systeminformation');
5
+ const log = require('../logging/harper_logger.js');
6
+ const terms = require("../hdbTerms.js");
7
+ const lmdbGetTableSize = require('../../dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js');
8
+ const schemaDescribe = require('../../dataLayer/schemaDescribe.js');
9
+ const { getThreadInfo } = require('../../server/threads/manageThreads.js');
10
+ const env = require('./environmentManager.js');
11
+ env.initSync();
12
+ const { databases } = require("../../resources/databases.js");
62
13
  //this will hold the system_information which is static to improve performance
63
14
  let systemInformationCache = undefined;
64
15
  class SystemInformationRequest {
65
- operator;
66
- attributes;
67
16
  constructor(attributes) {
68
- this.operator = hdbTerms.OPERATIONS_ENUM.SYSTEM_INFORMATION;
17
+ this.operator = terms.OPERATIONS_ENUM.SYSTEM_INFORMATION;
69
18
  this.attributes = attributes;
70
19
  }
71
20
  }
72
- exports.SystemInformationRequest = SystemInformationRequest;
73
21
  class SystemInformationResponse {
74
- system;
75
- time;
76
- cpu;
77
- memory;
78
- disk;
79
- network;
80
- harperdb_processes;
81
- table_size;
82
- metrics;
83
- threads;
84
- constructor(system, time, cpu, memory, disk, network, harperdbProcesses, tableSize, metrics, threads) {
22
+ constructor(system, time, cpu, memory, disk, network, harperdbProcesses) {
85
23
  this.system = system;
86
24
  this.time = time;
87
25
  this.cpu = cpu;
@@ -89,150 +27,139 @@ class SystemInformationResponse {
89
27
  this.disk = disk;
90
28
  this.network = network;
91
29
  this.harperdb_processes = harperdbProcesses;
92
- this.table_size = tableSize;
93
- this.metrics = metrics;
94
- this.threads = threads;
95
30
  }
96
31
  }
97
- exports.SystemInformationResponse = SystemInformationResponse;
32
+ module.exports = {
33
+ getHDBProcessInfo,
34
+ getNetworkInfo,
35
+ getDiskInfo,
36
+ getMemoryInfo,
37
+ getCPUInfo,
38
+ getTimeInfo,
39
+ getSystemInformation,
40
+ systemInformation,
41
+ getTableSize,
42
+ getMetrics,
43
+ SystemInformationRequest,
44
+ };
98
45
  /**
99
- * Returns the current local time, uptime, timezone, and timezone name.
46
+ * executes the time function to return the time info for the system
47
+ * @returns {si.Systeminformation.TimeData}
100
48
  */
101
49
  function getTimeInfo() {
102
- return systeminformation_1.default.time();
50
+ return si.time();
103
51
  }
104
52
  /**
105
- * Detects CPU information such as manufacturer, brand, vendor, speed, cores, physical cores, and
106
- * processors.
53
+ * executes cpu related functions
54
+ * @returns {Promise<{}|Pick<si.Systeminformation.CpuData, "manufacturer" | "brand" | "vendor" | "speed" | "cores" | "physicalCores" | "processors">>}
107
55
  */
108
56
  async function getCPUInfo() {
109
57
  try {
110
- const [cpu, cpu_speed, loadInfo] = await Promise.all([systeminformation_1.default.cpu(), systeminformation_1.default.cpuCurrentSpeed(), systeminformation_1.default.currentLoad()]);
111
- const { manufacturer, brand, vendor, speed, cores, physicalCores, performanceCores, efficiencyCores, processors, flags, virtualization, } = cpu;
112
- const { avgLoad, cpus, currentLoad, currentLoadUser, currentLoadSystem, currentLoadNice, currentLoadIdle, currentLoadIrq, } = loadInfo;
113
- return {
114
- manufacturer,
115
- brand,
116
- vendor,
117
- speed,
118
- cores,
119
- physicalCores,
120
- performanceCores,
121
- efficiencyCores,
122
- processors,
123
- flags,
124
- virtualization,
125
- cpu_speed,
126
- current_load: {
127
- avgLoad,
128
- cpus: cpus.map(({ load, loadUser, loadSystem, loadNice, loadIdle, loadIrq }) => ({
129
- load,
130
- loadUser,
131
- loadSystem,
132
- loadNice,
133
- loadIdle,
134
- loadIrq,
135
- })),
136
- currentLoad,
137
- currentLoadUser,
138
- currentLoadSystem,
139
- currentLoadNice,
140
- currentLoadIdle,
141
- currentLoadIrq,
142
- },
143
- };
58
+ // eslint-disable-next-line no-unused-vars
59
+ let { family, model, stepping, revision, voltage, speedmin, speedmax, governor, socket, cache, ...cpuInfo } = await si.cpu();
60
+ cpuInfo.cpu_speed = await si.cpuCurrentSpeed();
61
+ let {
62
+ // eslint-disable-next-line no-unused-vars
63
+ rawCurrentload, cpus, ...cpuCurrentLoad } = await si.currentLoad();
64
+ cpuCurrentLoad.cpus = [];
65
+ cpus.forEach((cpuData) => {
66
+ // eslint-disable-next-line no-unused-vars
67
+ let { rawLoad, rawLoadIdle, rawLoadIrq, rawLoadNice, rawLoadSystem, rawLoadUser, ...cpuLoad } = cpuData;
68
+ cpuCurrentLoad.cpus.push(cpuLoad);
69
+ });
70
+ cpuInfo.current_load = cpuCurrentLoad;
71
+ return cpuInfo;
144
72
  }
145
73
  catch (e) {
146
- harper_logger_js_1.default.error(`error in getCPUInfo: ${e}`);
147
- return null;
74
+ log.error(`error in getCPUInfo: ${e}`);
75
+ return {};
148
76
  }
149
77
  }
150
78
  /**
151
- * Detect system and Node.js memory usage.
79
+ * fetches information related memory
80
+ * @returns {Promise<{}|Pick<si.Systeminformation.MemData, "total" | "free" | "used" | "active" | "available" | "swaptotal" | "swapused" | "swapfree">>}
152
81
  */
153
82
  async function getMemoryInfo() {
154
83
  try {
155
- const { total, free, used, active, available, reclaimable, swaptotal, swapused, swapfree, writeback, dirty } = await systeminformation_1.default.mem();
156
- return {
157
- total,
158
- free,
159
- used,
160
- active,
161
- available,
162
- reclaimable,
163
- swaptotal,
164
- swapused,
165
- swapfree,
166
- writeback,
167
- dirty,
168
- ...process.memoryUsage(),
169
- };
84
+ // eslint-disable-next-line no-unused-vars
85
+ let { buffers, cached, slab, buffcache, ...memInfo } = await si.mem();
86
+ return Object.assign(memInfo, process.memoryUsage());
170
87
  }
171
88
  catch (e) {
172
- harper_logger_js_1.default.error(`error in getMemoryInfo: ${e}`);
173
- return null;
174
- }
175
- }
176
- async function getHdbPid() {
177
- try {
178
- return Number.parseInt(await (0, promises_1.readFile)(node_path_1.default.join(environmentManager_js_1.default.get(hdbTerms.CONFIG_PARAMS.ROOTPATH), hdbTerms.HDB_PID_FILE), 'utf8'));
179
- }
180
- catch (err) {
181
- if (err.code === hdbTerms.NODE_ERROR_CODES.ENOENT) {
182
- harper_logger_js_1.default.warn(`Unable to locate 'hdb.pid' file, try stopping and starting Harper. This could be because Harper is not running.`);
183
- }
184
- else {
185
- throw err;
186
- }
89
+ log.error(`error in getMemoryInfo: ${e}`);
90
+ return {};
187
91
  }
188
92
  }
189
93
  /**
190
- * Detects the Harper process PID and returns the process info.
94
+ * searches for & returns the processes for hdb core
191
95
  * @returns {Promise<{core: []}>}
192
96
  */
193
97
  async function getHDBProcessInfo() {
194
- const harperdbProcesses = {
98
+ let harperdbProcesses = {
195
99
  core: [],
196
100
  };
197
101
  try {
198
- const [processes, hdbPid] = await Promise.all([systeminformation_1.default.processes(), getHdbPid()]);
199
- const proc = processes.list.find((p) => p.pid === hdbPid);
200
- if (proc) {
201
- harperdbProcesses.core.push(proc);
102
+ let processes = await si.processes();
103
+ let hdbPid;
104
+ try {
105
+ hdbPid = Number.parseInt(await fs.readFile(path.join(env.get(terms.CONFIG_PARAMS.ROOTPATH), terms.HDB_PID_FILE), 'utf8'));
202
106
  }
107
+ catch (err) {
108
+ if (err.code === terms.NODE_ERROR_CODES.ENOENT) {
109
+ log.warn(`Unable to locate 'hdb.pid' file, try stopping and starting Harper. This could be because Harper is not running.`);
110
+ }
111
+ else {
112
+ throw err;
113
+ }
114
+ }
115
+ processes.list.forEach((p) => {
116
+ if (p.pid === hdbPid) {
117
+ harperdbProcesses.core.push(p);
118
+ }
119
+ });
120
+ for (const hdbP of harperdbProcesses.core) {
121
+ for (const p of processes.list) {
122
+ if (p.pid === hdbP.parentPid && (p.name === 'PM2' || p.command === 'PM2')) {
123
+ hdbP.parent = 'PM2';
124
+ }
125
+ }
126
+ }
127
+ return harperdbProcesses;
203
128
  }
204
129
  catch (e) {
205
- harper_logger_js_1.default.error(`error in getHDBProcessInfo: ${e}`);
130
+ log.error(`error in getHDBProcessInfo: ${e}`);
131
+ return harperdbProcesses;
206
132
  }
207
- return harperdbProcesses;
208
133
  }
209
134
  /**
210
- * Retrieves disk related info & stats
211
- * @returns {Promise<DiskInfo>}
135
+ * gets disk related info & stats
136
+ * @returns {Promise<{}>}
212
137
  */
213
138
  async function getDiskInfo() {
214
- const disk = {};
139
+ let disk = {};
215
140
  try {
216
- if (!environmentManager_js_1.default.get(hdbTerms.CONFIG_PARAMS.OPERATIONSAPI_SYSINFO_DISK))
141
+ if (!env.get(terms.CONFIG_PARAMS.OPERATIONSAPI_SYSINFO_DISK))
217
142
  return disk;
218
- const [disksIO, fsStats, fsSize] = await Promise.all([systeminformation_1.default.disksIO(), systeminformation_1.default.fsStats(), systeminformation_1.default.fsSize()]);
219
- const { rIO, wIO, tIO } = disksIO;
220
- disk.io = { rIO, wIO, tIO };
221
- const { rx, tx, wx } = fsStats;
222
- disk.read_write = { rx, tx, wx };
223
- disk.size = fsSize;
143
+ // eslint-disable-next-line no-unused-vars
144
+ let { rIO_sec, wIO_sec, tIO_sec, ms, ...diskIo } = await si.disksIO();
145
+ disk.io = diskIo;
146
+ // eslint-disable-next-line no-unused-vars
147
+ let { rxSec, txSec, wxSec, ...fsStats } = await si.fsStats();
148
+ disk.read_write = fsStats;
149
+ disk.size = await si.fsSize();
150
+ return disk;
224
151
  }
225
152
  catch (e) {
226
- harper_logger_js_1.default.error(`error in getDiskInfo: ${e}`);
153
+ log.error(`error in getDiskInfo: ${e}`);
154
+ return disk;
227
155
  }
228
- return disk;
229
156
  }
230
157
  /**
231
- * Detects networking connection information & stats
158
+ * gets networking & connection information & stats
232
159
  * @returns {Promise<{interfaces: [], default_interface: null, stats: [], latency: {}, connections: []}>}
233
160
  */
234
161
  async function getNetworkInfo() {
235
- const network = {
162
+ let network = {
236
163
  default_interface: null,
237
164
  latency: {},
238
165
  interfaces: [],
@@ -240,227 +167,160 @@ async function getNetworkInfo() {
240
167
  connections: [],
241
168
  };
242
169
  try {
243
- if (!environmentManager_js_1.default.get(hdbTerms.CONFIG_PARAMS.OPERATIONSAPI_SYSINFO_NETWORK))
170
+ if (!env.get(terms.CONFIG_PARAMS.OPERATIONSAPI_SYSINFO_NETWORK))
244
171
  return network;
245
- const [defaultInterface, latency, nInterfaces, stats] = await Promise.all([
246
- systeminformation_1.default.networkInterfaceDefault(),
247
- systeminformation_1.default.inetChecksite('https://google.com').catch(() => ({})),
248
- systeminformation_1.default.networkInterfaces(),
249
- systeminformation_1.default.networkStats(),
250
- ]);
251
- network.default_interface = defaultInterface || null;
252
- network.latency = latency;
253
- for (const nInterface of nInterfaces) {
254
- const { iface, ifaceName, default: isDefault, ip4, ip4subnet, ip6, ip6subnet, mac, operstate, type, duplex, speed, } = nInterface;
255
- network.interfaces.push({
256
- iface,
257
- ifaceName,
258
- default: isDefault,
259
- ip4,
260
- ip4subnet,
261
- ip6,
262
- ip6subnet,
263
- mac,
264
- operstate,
265
- type,
266
- duplex,
267
- speed,
268
- });
269
- }
270
- for (const nStat of stats) {
271
- const { iface, operstate, rx_bytes, rx_dropped, rx_errors, tx_bytes, tx_dropped, tx_errors } = nStat;
272
- network.stats.push({ iface, operstate, rx_bytes, rx_dropped, rx_errors, tx_bytes, tx_dropped, tx_errors });
273
- }
172
+ network.default_interface = await si.networkInterfaceDefault();
173
+ network.latency = await si.inetChecksite('google.com');
174
+ let nInterfaces = await si.networkInterfaces();
175
+ nInterfaces.forEach((_interface) => {
176
+ // eslint-disable-next-line no-unused-vars
177
+ let { internal, virtual, mtu, dhcp, dnsSuffix, ieee8021xAuth, ieee8021xState, carrierChanges, ...networkInt } = _interface;
178
+ network.interfaces.push(networkInt);
179
+ });
180
+ let stats = await si.networkStats();
181
+ stats.forEach((nStat) => {
182
+ // eslint-disable-next-line no-unused-vars
183
+ let { rxSec, txSec, ms, ...stat } = nStat;
184
+ network.stats.push(stat);
185
+ });
186
+ return network;
274
187
  }
275
188
  catch (e) {
276
- harper_logger_js_1.default.error(`error in getNetworkInfo: ${e}`);
189
+ log.error(`error in getNetworkInfo: ${e}`);
190
+ return network;
277
191
  }
278
- return network;
279
192
  }
280
193
  /**
281
- * Detect operating system and Node.js runtime information.
282
- * @returns {Promise<SystemInfo>}
194
+ * gets system information
195
+ * @returns {Promise<Pick<si.Systeminformation.OsData, "platform" | "distro" | "release" | "codename" | "kernel" | "arch" | "hostname">|{}>}
283
196
  */
284
197
  async function getSystemInformation() {
285
198
  if (systemInformationCache !== undefined) {
286
199
  return systemInformationCache;
287
200
  }
288
- let systemInfo = {};
201
+ let system_info = {};
289
202
  try {
290
- const [osInfo, versions] = await Promise.all([systeminformation_1.default.osInfo(), systeminformation_1.default.versions('node, npm')]);
291
- const { platform, distro, release, codename, kernel, arch, hostname, fqdn } = osInfo;
292
- const { node, npm } = versions;
293
- systemInfo = {
294
- platform,
295
- distro,
296
- release,
297
- codename,
298
- kernel,
299
- arch,
300
- hostname,
301
- fqdn,
302
- node_version: node,
303
- npm_version: npm,
304
- };
305
- systemInformationCache = systemInfo;
203
+ // eslint-disable-next-line no-unused-vars
204
+ let { codepage, logofile, serial, build, servicepack, uefi, ...sysInfo } = await si.osInfo();
205
+ system_info = sysInfo;
206
+ let versions = await si.versions('node, npm');
207
+ system_info.node_version = versions.node;
208
+ system_info.npm_version = versions.npm;
209
+ systemInformationCache = system_info;
210
+ return systemInformationCache;
306
211
  }
307
212
  catch (e) {
308
- harper_logger_js_1.default.error(`error in getSystemInformation: ${e}`);
213
+ log.error(`error in getSystemInformation: ${e}`);
214
+ return system_info;
309
215
  }
310
- return systemInfo;
311
216
  }
312
- function rocksdbGetTableSize(table) {
313
- const rocksdb = table.primaryStore;
314
- const stats = rocksdb.getStats();
315
- const transactionLogSize = rocksdb
316
- .listLogs()
317
- .reduce((sum, logName) => sum + rocksdb.useLog(logName).getLogFileSize(), 0);
318
- return new TableSizeObject_ts_1.TableSizeObject(table.databaseName, table.tableName, stats['rocksdb.estimate-live-data-size'] ?? 0, stats['rocksdb.estimate-num-keys'] ?? 0, transactionLogSize
319
- // transactionLogRecordCount - currently not supported by `rocksdb-js`
320
- );
321
- }
322
- /**
323
- * Retrieves table size information.
324
- * @returns {TableSizeObject[]}
325
- */
326
- function getTableSize() {
327
- const results = [];
328
- const databases = (0, databases_ts_1.getDatabases)();
329
- for (const db of Object.values(databases)) {
330
- for (const table of Object.values(db)) {
331
- if (table.primaryStore.rootStore instanceof rocksdb_js_1.RocksDatabase) {
332
- results.push(rocksdbGetTableSize(table));
333
- }
334
- else {
335
- results.push((0, lmdbGetTableSize_ts_1.lmdbGetTableSize)(table));
336
- }
217
+ async function getTableSize() {
218
+ //get details for all tables
219
+ let tableSizes = [];
220
+ let allSchemas = await schemaDescribe.describeAll();
221
+ for (const tables of Object.values(allSchemas)) {
222
+ for (const tableData of Object.values(tables)) {
223
+ tableSizes.push(await lmdbGetTableSize(tableData));
337
224
  }
338
225
  }
339
- return results;
226
+ return tableSizes;
340
227
  }
341
- const rocksDBDatabaseLevelStats = new Set([
342
- 'blockCacheCapacity',
343
- 'blockCacheDataHit',
344
- 'blockCacheDataMiss',
345
- 'blockCacheFilterHit',
346
- 'blockCacheFilterMiss',
347
- 'blockCacheHit',
348
- 'blockCacheIndexHit',
349
- 'blockCacheIndexMiss',
350
- 'blockCacheMiss',
351
- 'blockCachePinnedUsage',
352
- 'blockCacheUsage',
353
- 'bytesRead',
354
- 'bytesWritten',
355
- 'dbFlushMicros',
356
- 'dbGetMicros',
357
- 'dbSeekMicros',
358
- 'dbWriteMicros',
359
- 'noFileErrors',
360
- 'numberKeysRead',
361
- 'numberKeysWritten',
362
- 'numberReseeksIteration',
363
- 'numRunningFlushes',
364
- 'oldestSnapshotTime',
365
- 'stallMicros',
366
- 'txnOverheadMutexOldCommitMap',
367
- 'txnOverheadMutexPrepare',
368
- 'txnOverheadMutexSnapshot',
369
- ]);
370
- // Strips the "rocksdb." prefix and converts kebab-case to camelCase
371
- function toRocksDBCamelCase(key) {
372
- return key.replace(/^rocksdb\./, '').replace(/[-.]([a-z])/g, (_, c) => c.toUpperCase());
373
- }
374
- function getRocksDBStats(table, dbStats) {
375
- const stats = table.primaryStore.getStats();
376
- const tableStats = (dbStats.tables[table.tableName] = {});
377
- for (const [key, value] of Object.entries(stats)) {
378
- const name = toRocksDBCamelCase(key);
379
- if (rocksDBDatabaseLevelStats.has(name)) {
380
- dbStats[name] = value;
381
- }
382
- else {
383
- tableStats[name] = value;
384
- }
385
- }
386
- }
387
- function getLMDBStats(table, dbStats) {
388
- if (!dbStats.readers) {
389
- const { root: _root, ...stats } = table.primaryStore.rootStore.getStats();
390
- Object.assign(dbStats, stats);
391
- dbStats.readers = table.primaryStore.rootStore
392
- .readerList()
393
- .split(/\n\s+/)
394
- .slice(1)
395
- .map((line) => {
396
- const [pid, thread, txnid] = line.trim().split(' ');
397
- return { pid, thread, txnid };
398
- });
399
- if (table.auditStore) {
400
- const { treeDepth, treeBranchPageCount, treeLeafPageCount, entryCount, overflowPages } = table.auditStore.getStats();
401
- dbStats.audit = { treeDepth, treeBranchPageCount, treeLeafPageCount, entryCount, overflowPages };
402
- }
403
- }
404
- const { entryCount, overflowPages, treeBranchPageCount, treeDepth, treeLeafPageCount } = table.primaryStore.getStats();
405
- dbStats.tables[table.tableName] = { entryCount, overflowPages, treeBranchPageCount, treeDepth, treeLeafPageCount };
406
- }
407
- /**
408
- * Get RocksDB or LMDB metrics for all databases and tables.
409
- * @returns {Promise<DatabaseMetrics>}
410
- */
411
228
  async function getMetrics() {
412
- const databaseStats = {};
413
- const databases = (0, databases_ts_1.getDatabases)();
414
- for (const [dbName, db] of Object.entries(databases)) {
415
- const dbStats = { tables: {} };
416
- databaseStats[dbName] = dbStats;
417
- for (const [tableName, table] of Object.entries(db)) {
229
+ let schemaStats = {};
230
+ for (let schemaName in databases) {
231
+ let dbStats = (schemaStats[schemaName] = {});
232
+ let tableStats = (dbStats.tables = {});
233
+ for (let tableName in databases[schemaName]) {
418
234
  try {
419
- if (table.primaryStore.rootStore instanceof rocksdb_js_1.RocksDatabase) {
420
- getRocksDBStats(table, dbStats);
235
+ let table = databases[schemaName][tableName];
236
+ if (!dbStats.readers) {
237
+ Object.assign(dbStats, table.primaryStore.rootStore.getStats());
238
+ delete dbStats.root;
239
+ dbStats.readers = table.primaryStore.rootStore
240
+ .readerList()
241
+ .split(/\n\s+/)
242
+ .slice(1)
243
+ .map((line) => {
244
+ const [pid, thread, txnid] = line.trim().split(' ');
245
+ return { pid, thread, txnid };
246
+ });
247
+ if (table.auditStore) {
248
+ const { treeDepth, treeBranchPageCount, treeLeafPageCount, entryCount, overflowPages } = table.auditStore.getStats();
249
+ dbStats.audit = { treeDepth, treeBranchPageCount, treeLeafPageCount, entryCount, overflowPages };
250
+ }
421
251
  }
422
- else {
423
- getLMDBStats(table, dbStats);
252
+ let tableFullStats = table.primaryStore.getStats();
253
+ let tablePrunedStats = {};
254
+ for (let storeKey of ['treeDepth', 'treeBranchPageCount', 'treeLeafPageCount', 'entryCount', 'overflowPages']) {
255
+ tablePrunedStats[storeKey] = tableFullStats[storeKey];
424
256
  }
257
+ tableStats[tableName] = tablePrunedStats;
425
258
  }
426
259
  catch (error) {
427
- // if a database no longer exists, don't want to throw an error
428
- harper_logger_js_1.default.notify(`Error getting stats for table ${tableName}: ${error}`);
260
+ // if a schema no longer exists, don't want to throw an error
261
+ log.notify(`Error getting stats for table ${tableName}: ${error}`);
429
262
  }
430
263
  }
431
264
  }
432
- return databaseStats;
265
+ return schemaStats;
433
266
  }
434
- const attributeMap = {
435
- system: getSystemInformation,
436
- time: getTimeInfo,
437
- cpu: getCPUInfo,
438
- memory: getMemoryInfo,
439
- disk: getDiskInfo,
440
- network: getNetworkInfo,
441
- harperdb_processes: getHDBProcessInfo,
442
- table_size: getTableSize,
443
- metrics: getMetrics,
444
- threads: manageThreads_js_1.getThreadInfo,
445
- };
446
267
  /**
447
- * Retrieves system information for the requested attributes.
268
+ *
448
269
  * @param {SystemInformationRequest} systemInfoReq
449
270
  * @returns {Promise<SystemInformationResponse>}
450
271
  */
451
272
  async function systemInformation(systemInfoReq) {
452
- const attributes = Array.isArray(systemInfoReq.attributes) && systemInfoReq.attributes.length > 0
453
- ? systemInfoReq.attributes
454
- : Object.keys(attributeMap);
455
- const response = new SystemInformationResponse();
456
- await Promise.all(attributes
457
- .filter((attr) => attr in attributeMap)
458
- .map(async (attr) => {
459
- if (attr === 'database_metrics') {
460
- attr = 'metrics';
273
+ let response = new SystemInformationResponse();
274
+ if (!Array.isArray(systemInfoReq.attributes) || systemInfoReq.attributes.length === 0) {
275
+ response.system = await getSystemInformation();
276
+ response.time = getTimeInfo();
277
+ response.cpu = await getCPUInfo();
278
+ response.memory = await getMemoryInfo();
279
+ response.disk = await getDiskInfo();
280
+ response.network = await getNetworkInfo();
281
+ response.harperdb_processes = await getHDBProcessInfo();
282
+ response.table_size = await getTableSize();
283
+ response.metrics = await getMetrics();
284
+ response.threads = await getThreadInfo();
285
+ return response;
286
+ }
287
+ for (let attr of systemInfoReq.attributes) {
288
+ switch (attr) {
289
+ case 'system':
290
+ response.system = await getSystemInformation();
291
+ break;
292
+ case 'time':
293
+ response.time = getTimeInfo();
294
+ break;
295
+ case 'cpu':
296
+ response.cpu = await getCPUInfo();
297
+ break;
298
+ case 'memory':
299
+ response.memory = await getMemoryInfo();
300
+ break;
301
+ case 'disk':
302
+ response.disk = await getDiskInfo();
303
+ break;
304
+ case 'network':
305
+ response.network = await getNetworkInfo();
306
+ break;
307
+ case 'harperdb_processes':
308
+ response.harperdb_processes = await getHDBProcessInfo();
309
+ break;
310
+ case 'table_size':
311
+ response.table_size = await getTableSize();
312
+ break;
313
+ case 'database_metrics':
314
+ case 'metrics':
315
+ response.metrics = await getMetrics();
316
+ break;
317
+ case 'threads':
318
+ response.threads = await getThreadInfo();
319
+ break;
320
+ default:
321
+ break;
461
322
  }
462
- response[attr] = await attributeMap[attr]();
463
- }));
323
+ }
464
324
  return response;
465
325
  }
466
326
  //# sourceMappingURL=systemInformation.js.map