@@ -2,7 +2,10 @@ const si = require('systeminformation');
22
33const healthHelpers = { } ;
44
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+ */
69
710const collectedMetrics = {
811 cpu : {
@@ -50,10 +53,18 @@ const collectedMetrics = {
5053 inetLatency : 'all data collected' ,
5154} ;
5255
56+ /**
57+ * collectHealthData scrapes metrics for microservices
58+ * @returns Promise array with each metric in an object
59+ */
60+
5361healthHelpers . collectHealthData = ( ) => {
5462 const healthDataCollection = [ ] ;
5563 const time = Date . now ( ) ;
5664
65+ /** obtains core CPU metrics and creates and pushes object with
66+ * metric name and value to the healthDataCollection array
67+ */
5768 si . cpu ( )
5869 . then ( data => {
5970 const siMethodName = 'cpu' ;
@@ -72,6 +83,9 @@ healthHelpers.collectHealthData = () => {
7283 }
7384 } ) ;
7485
86+ /** obtains CPU speed metrics and creates and pushes object with
87+ * metric name and value to the healthDataCollection array
88+ */
7589 si . cpuCurrentSpeed ( )
7690 . then ( data => {
7791 const siMethodName = 'cpuCurrentSpeed' ;
@@ -90,6 +104,9 @@ healthHelpers.collectHealthData = () => {
90104 }
91105 } ) ;
92106
107+ /** obtains CPU temperature metrics and creates and pushes object with
108+ * metric name and value to the healthDataCollection array
109+ */
93110 si . cpuTemperature ( )
94111 . then ( data => {
95112 const siMethodName = 'cpuTemperature' ;
@@ -108,6 +125,9 @@ healthHelpers.collectHealthData = () => {
108125 }
109126 } ) ;
110127
128+ /** obtains metrics relating to current load and creates and pushes object with
129+ * metric name and value to the healthDataCollection array
130+ */
111131 si . currentLoad ( )
112132 . then ( data => {
113133 const siMethodName = 'currentLoad' ;
@@ -126,6 +146,9 @@ healthHelpers.collectHealthData = () => {
126146 }
127147 } ) ;
128148
149+ /** obtains metrics relating to memory and creates and pushes object with
150+ * metric name and value to the healthDataCollection array
151+ */
129152 si . mem ( )
130153 . then ( data => {
131154 const siMethodName = 'mem' ;
@@ -144,6 +167,9 @@ healthHelpers.collectHealthData = () => {
144167 }
145168 } ) ;
146169
170+ /** obtains metrics relating to current processes and creates and pushes object with
171+ * metric name and value to the healthDataCollection array
172+ */
147173 si . processes ( )
148174 . then ( data => {
149175 const siMethodName = 'processes' ;
@@ -162,6 +188,9 @@ healthHelpers.collectHealthData = () => {
162188 }
163189 } ) ;
164190
191+ /** obtains latency and creates and pushes object with
192+ * metric name and value to the healthDataCollection array
193+ */
165194 si . inetLatency ( )
166195 . then ( data => {
167196 const siMethodName = 'inetLatency' ;
@@ -178,22 +207,14 @@ healthHelpers.collectHealthData = () => {
178207 }
179208 } ) ;
180209
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+ } )
197218 ) ;
198219} ;
199220
0 commit comments