tariqbuilds / linux-dash

A beautiful web dashboard for Linux
https://afaqurk.github.io/linux-dash/
MIT License
10.43k stars 1.2k forks source link

Getting JSON error in node enviroment #508

Open spmsupun opened 3 years ago

spmsupun commented 3 years ago

I am getting JSON error when WS retrieve data from backend, so I debug the frontend js and I am getting a invalid json:

{ 
  "moduleName": "current_ram",
  "output": "{ "total": 15853.7, "used": 13733.4, "available": 2120.32 }" 
}

image image

Am I doing something wrong?

VigneshVaidyanathan commented 3 years ago

It is an error when the JSON values get parsed. I made the following changes and it worked.

index.js Modified line 58 from var wsResponse = '{ "moduleName": "' + moduleName + '", "output": "'+ output.join('') +'" }' to var wsResponse = '{ "moduleName": "' + moduleName + '", "output": '+ output.join('') +' }' reason The extra " double quotes surrounding the output property value, messed with the double quotes inside the actual value. So I removed it to so it can be directly converted to an object.

server.service.js Modified line 36 - from var moduleData = JSON.parse(response.output); to var moduleData = response.output) reason Made the change so when the websocket client listens to the data being passed, it should not try to parse the already parsed output property.

If you have edited the changes in the server.service.js then build the source and copy the linuxDash.min.js to the server. You could also directly update the linuxDash.min.js and index.js on the server and everything will start working.

I have not done any tests or verifications to make sure things do not break in other implementations like Python etc, but my app started showing everything after that.

Let me know if it works for you.

spmsupun commented 3 years ago

I have already chosen a different one, It's been so long 😅

VigneshVaidyanathan commented 2 years ago

@spmsupun Out of curiosity, which dashboard do you use now?

spmsupun commented 2 years ago

@VigneshVaidyanathan i use netdata

VigneshVaidyanathan commented 2 years ago

Installed it. There is no turning back now, is it. It looks awesome 😄

spmsupun commented 2 years ago

yeah, I thought it's heavy but no, its super light weight

DanZai233 commented 11 months ago

@VigneshVaidyanathan it works!