gpustat-web icon indicating copy to clipboard operation
gpustat-web copied to clipboard

Add option to return json on websocket

Open cceyda opened this issue 3 years ago • 4 comments

I have added the option to also get the results as a json formatted string from the websocket by setting ws.send_str('json'). json is more convenient for consuming in other applications, that are piggy-backing off of this library.

I have been using your gpustat & gpustat-web libraries for a while 😄 ~ Thank you ~

cceyda avatar Feb 21 '21 14:02 cceyda

May I ask what is the main purpose of emitting the data json? All the data is given as 'text' actually too.

wookayin avatar Jun 25 '21 13:06 wookayin

the ansi conversion was making the text hard to parse in the websocket response

cceyda avatar Jun 25 '21 13:06 cceyda

I still don't quite understand. The JSON response is an array of still ANSI-coded gpustat output, right? Why do you need them in the first place?

wookayin avatar Jun 26 '21 01:06 wookayin

Because otherwise websocket returns info formatted with html (with tags, and some stats left out), due to conversion done here: return ansi_conv.convert(body, full=False) the response looks like this:

<span class="ansi36">[0]</span> <span class="ansi34">TITAN RTX                </span> |<span class="ansi31"> 26°C</span>, <span class="ansi32">  0 %</span> | <span class="ansi36"></span><span class="ansi1 ansi36"></span><span class="ansi1 ansi33">    1</span> / <span class="ansi33">24220</span> MB | ...

I want the whole gpu info in json format, like this:

[{"hostname": "server1", "query_time": "2021-06-26T17:39:18.868461", "gpus": [{"index": 0, "uuid": ....

So that I can do my own parsing and formatting.

cceyda avatar Jun 26 '21 08:06 cceyda