Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to return json on websocket #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cceyda
Copy link

@cceyda cceyda commented Feb 21, 2021

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 ~

try:
parsed = json.loads(status)
except:
continue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle exception properly.

@wookayin
Copy link
Owner

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

@cceyda
Copy link
Author

cceyda commented Jun 25, 2021

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

@wookayin
Copy link
Owner

wookayin commented Jun 26, 2021

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?

@cceyda
Copy link
Author

cceyda commented Jun 26, 2021

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.

Copy link
Owner

@wookayin wookayin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if the JSON format here is the best possible one. I think instead of having a list as a top-level element, we should have some dict(object) a la gpustat's JSON output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants