1

I read the doc from Grafana (https://grafana.com/grafana/plugins/golioth-websocket-datasource/?tab=overview) but when I try to replicate it by myself using my locally established WebSockets, it fails to receive data.

Here is what I did:

# ----------- server side: server.py-----------
import asyncio
import websockets
async def echo(websocket, path):
    async for message in websocket:
        message = "I got your message: {}".format(message)
        await websocket.send(message)
asyncio.get_event_loop().run_until_complete(websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()

# ----------- client side: client.py-----------
import asyncio
import websockets
async def hello(uri):
    async with websockets.connect(uri) as websocket:
        await websocket.send("hello world")
        print("< HELLO WORLD")
        while True:
            recv_text = await websocket.recv()
            print("> {}".format(recv_text))
asyncio.get_event_loop().run_until_complete(hello('ws://localhost:8765'))

Run server.py first and then client.pyclient.py has the output as below:

< Hello world!
> I got your message: Hello world!

I also configured the host ws://localhost:8765 in Grafana, I suspect I could receive 'hello world'. but didn't receive any data. (table view is toggled)

enter image description here

enter image description here

Wonder if anyone could help?

2
  • You have some error, so it looks like client is not connected. Click on the red exclamation mark in the panel corner for error message. Use browser console/websocket inspection and inspect connection/responses.
    – Jan Garaj
    Commented Sep 8, 2023 at 23:39
  • Does it mean this way should work?
    – Parting
    Commented Sep 11, 2023 at 9:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.