@@ -2,7 +2,10 @@ const si = require('systeminformation');
2
2
3
3
const healthHelpers = { } ;
4
4
5
- /* This object contains all systeminformation methods, metric names, and corresponding points */
5
+ /**
6
+ * This object contains all systeminformation methods,
7
+ * metric names, and corresponding data points
8
+ */
6
9
7
10
const collectedMetrics = {
8
11
cpu : {
@@ -50,10 +53,18 @@ const collectedMetrics = {
50
53
inetLatency : 'all data collected' ,
51
54
} ;
52
55
56
+ /**
57
+ * collectHealthData scrapes metrics for microservices
58
+ * @returns Promise array with each metric in an object
59
+ */
60
+
53
61
healthHelpers . collectHealthData = ( ) => {
54
62
const healthDataCollection = [ ] ;
55
63
const time = Date . now ( ) ;
56
64
65
+ /** obtains core CPU metrics and creates and pushes object with
66
+ * metric name and value to the healthDataCollection array
67
+ */
57
68
si . cpu ( )
58
69
. then ( data => {
59
70
const siMethodName = 'cpu' ;
@@ -72,6 +83,9 @@ healthHelpers.collectHealthData = () => {
72
83
}
73
84
} ) ;
74
85
86
+ /** obtains CPU speed metrics and creates and pushes object with
87
+ * metric name and value to the healthDataCollection array
88
+ */
75
89
si . cpuCurrentSpeed ( )
76
90
. then ( data => {
77
91
const siMethodName = 'cpuCurrentSpeed' ;
@@ -90,6 +104,9 @@ healthHelpers.collectHealthData = () => {
90
104
}
91
105
} ) ;
92
106
107
+ /** obtains CPU temperature metrics and creates and pushes object with
108
+ * metric name and value to the healthDataCollection array
109
+ */
93
110
si . cpuTemperature ( )
94
111
. then ( data => {
95
112
const siMethodName = 'cpuTemperature' ;
@@ -108,6 +125,9 @@ healthHelpers.collectHealthData = () => {
108
125
}
109
126
} ) ;
110
127
128
+ /** obtains metrics relating to current load and creates and pushes object with
129
+ * metric name and value to the healthDataCollection array
130
+ */
111
131
si . currentLoad ( )
112
132
. then ( data => {
113
133
const siMethodName = 'currentLoad' ;
@@ -126,6 +146,9 @@ healthHelpers.collectHealthData = () => {
126
146
}
127
147
} ) ;
128
148
149
+ /** obtains metrics relating to memory and creates and pushes object with
150
+ * metric name and value to the healthDataCollection array
151
+ */
129
152
si . mem ( )
130
153
. then ( data => {
131
154
const siMethodName = 'mem' ;
@@ -144,6 +167,9 @@ healthHelpers.collectHealthData = () => {
144
167
}
145
168
} ) ;
146
169
170
+ /** obtains metrics relating to current processes and creates and pushes object with
171
+ * metric name and value to the healthDataCollection array
172
+ */
147
173
si . processes ( )
148
174
. then ( data => {
149
175
const siMethodName = 'processes' ;
@@ -162,6 +188,9 @@ healthHelpers.collectHealthData = () => {
162
188
}
163
189
} ) ;
164
190
191
+ /** obtains latency and creates and pushes object with
192
+ * metric name and value to the healthDataCollection array
193
+ */
165
194
si . inetLatency ( )
166
195
. then ( data => {
167
196
const siMethodName = 'inetLatency' ;
@@ -178,22 +207,14 @@ healthHelpers.collectHealthData = () => {
178
207
}
179
208
} ) ;
180
209
181
- // Return a promise that resolves to an array of all of the data points unnested
182
- return (
183
- Promise . all ( healthDataCollection )
184
- // Remove any empty strings, NaN, or "NaN" from values prevent database errors
185
- . then ( array =>
186
- array . filter ( metric => {
187
- if (
188
- isNaN ( metric . value ) ||
189
- metric . value === 'NaN' ||
190
- metric . value === '' ||
191
- metric . value === null
192
- )
193
- return false ;
194
- else return true ;
195
- } )
196
- )
210
+ /** Return a promise that resolves to an array of all of the data points
211
+ * and removes any empty strings, NaN, or "NaN" from values prevent database errors
212
+ */
213
+ return Promise . all ( healthDataCollection ) . then ( array =>
214
+ array . filter ( metric => {
215
+ if ( isNaN ( metric . value ) || metric . value === 'NaN' || metric . value === '' ) return false ;
216
+ else return true ;
217
+ } )
197
218
) ;
198
219
} ;
199
220
0 commit comments