Skip to content

Commit 93f572a

Browse files
authored
Fix null stats (#15)
* null to zero network stats * test for null value * revert test cases * fix null for cpu and memory
1 parent 48cbba7 commit 93f572a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/statCollector.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ async function getCPUStats(): Promise<ProcessedCPUStats> {
197197
response.data.forEach((element: CPUStats) => {
198198
userLoadX.push({
199199
x: element.time,
200-
y: element.userLoad
200+
y: element.userLoad || 0
201201
})
202202

203203
systemLoadX.push({
204204
x: element.time,
205-
y: element.systemLoad
205+
y: element.systemLoad || 0
206206
})
207207
})
208208

@@ -224,12 +224,12 @@ async function getMemoryStats(): Promise<ProcessedMemoryStats> {
224224
response.data.forEach((element: MemoryStats) => {
225225
activeMemoryX.push({
226226
x: element.time,
227-
y: element.activeMemoryMb
227+
y: element.activeMemoryMb || 0
228228
})
229229

230230
availableMemoryX.push({
231231
x: element.time,
232-
y: element.availableMemoryMb
232+
y: element.availableMemoryMb || 0
233233
})
234234
})
235235

@@ -247,16 +247,16 @@ async function getNetworkStats(): Promise<ProcessedNetworkStats> {
247247
if (logger.isDebugEnabled()) {
248248
logger.debug(`Got network stats: ${JSON.stringify(response.data)}`)
249249
}
250-
250+
251251
response.data.forEach((element: NetworkStats) => {
252252
networkReadX.push({
253253
x: element.time,
254-
y: element.rxMb
255-
})
254+
y: element.rxMb || 0
255+
})
256256

257257
networkWriteX.push({
258258
x: element.time,
259-
y: element.txMb
259+
y: element.txMb || 0
260260
})
261261
})
262262

@@ -276,12 +276,12 @@ async function getDiskStats(): Promise<ProcessedDiskStats> {
276276
response.data.forEach((element: DiskStats) => {
277277
diskReadX.push({
278278
x: element.time,
279-
y: element.rxMb
279+
y: element.rxMb || 0
280280
})
281281

282282
diskWriteX.push({
283283
x: element.time,
284-
y: element.wxMb
284+
y: element.wxMb || 0
285285
})
286286
})
287287

0 commit comments

Comments
 (0)