Skip to content

Commit 8adbc25

Browse files
committed
Health metrics function rewrite
The system information coming from si was strangley not being passed to through the function. The function was being called syncronously and because all the si function are async the return at the end of the function was always passing an empty array. This is because although the data from si was coming in, it was being pushed into an empty array defined at the top of the file inside of a .then and becuase the return was executing synchrounously the array was never being updated. Added awaits to each of the si functions and now the data is moving again
1 parent 3730a14 commit 8adbc25

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

chronos_npm_package/controllers/healthHelpers.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ const collectedMetrics = {
5858
* @returns Promise array with each metric in an object
5959
*/
6060

61-
healthHelpers.collectHealthData = () => {
61+
healthHelpers.collectHealthData = async() => {
62+
6263
const healthDataCollection = [];
6364
const time = Date.now();
6465

6566
/** obtains core CPU metrics and creates and pushes object with
6667
* metric name and value to the healthDataCollection array
6768
*/
68-
si.cpu()
69+
await si.cpu()
6970
.then(data => {
7071
// console.log(data)
7172
const siMethodName = 'cpu';
@@ -88,7 +89,7 @@ healthHelpers.collectHealthData = () => {
8889
/** obtains CPU speed metrics and creates and pushes object with
8990
* metric name and value to the healthDataCollection array
9091
*/
91-
si.cpuCurrentSpeed()
92+
await si.cpuCurrentSpeed()
9293
.then(data => {
9394
const siMethodName = 'cpuCurrentSpeed';
9495
for (let metricName in collectedMetrics[siMethodName]) {
@@ -110,7 +111,7 @@ healthHelpers.collectHealthData = () => {
110111
* metric name and value to the healthDataCollection array
111112
*/
112113

113-
si.cpuTemperature()
114+
await si.cpuTemperature()
114115
.then(data => {
115116
const siMethodName = 'cpuTemperature';
116117
for (let metricName in collectedMetrics[siMethodName]) {
@@ -132,7 +133,7 @@ healthHelpers.collectHealthData = () => {
132133
* obtains metrics relating to current load and creates and pushes object with
133134
* metric name and value to the healthDataCollection array
134135
*/
135-
si.currentLoad()
136+
await si.currentLoad()
136137
.then(data => {
137138
const siMethodName = 'currentLoad';
138139
for (let metricName in collectedMetrics[siMethodName]) {
@@ -154,7 +155,7 @@ healthHelpers.collectHealthData = () => {
154155
* obtains metrics relating to memory and creates and pushes object with
155156
* metric name and value to the healthDataCollection array
156157
*/
157-
si.mem()
158+
await si.mem()
158159
.then(data => {
159160
const siMethodName = 'mem';
160161
for (let metricName in collectedMetrics[siMethodName]) {
@@ -175,7 +176,7 @@ healthHelpers.collectHealthData = () => {
175176
/** obtains metrics relating to current processes and creates and pushes object with
176177
* metric name and value to the healthDataCollection array
177178
*/
178-
si.processes()
179+
await si.processes()
179180
.then(data => {
180181
const siMethodName = 'processes';
181182
for (let metricName in collectedMetrics[siMethodName]) {
@@ -196,7 +197,7 @@ healthHelpers.collectHealthData = () => {
196197
/** obtains latency and creates and pushes object with
197198
* metric name and value to the healthDataCollection array
198199
*/
199-
si.inetLatency()
200+
await si.inetLatency()
200201
.then(data => {
201202
const siMethodName = 'inetLatency';
202203
healthDataCollection.push({
@@ -205,7 +206,6 @@ healthHelpers.collectHealthData = () => {
205206
category: 'Latency',
206207
time,
207208
});
208-
console.log("HEALTH METRICS PRE PROMISE",healthDataCollection)
209209

210210
})
211211
.catch(err => {

0 commit comments

Comments
 (0)