Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using server-sent events with cubism.js graphs

Can cubism.js graphs be populated with data received from server-sent events? If so, would this be easy to implement?

Thank you,

/David

like image 827
OG Dude Avatar asked May 26 '12 14:05

OG Dude


People also ask

How do I send events from server to client?

The server-sent events streaming can be started by the client's GET request to Server. Accept: text/event-stream indicates the client waiting for event stream from the server, Cache-Control: no-cache indicates that disabling the caching and Connection: keep-alive indicates the persistent connection.

How do server-sent events work?

Server-Sent Events is designed to use the JavaScript EventSource API in order to subscribe to a stream of data in any popular browser. Through this interface a client requests a particular URL in order to receive an event stream.

How do you use SSE in react?

To do that, open the terminal and run the following command: mkdir sse-fetch-event-source && cd sse-fetch-event-source && mkdir frontend server . This will create a new folder sse-fetch-event-source , point the current working directory to it, and create folders frontend and server inside it.

How do you test SSE events?

To test it, you will normally open browser, making a connection to SSE channel and then wait for the push notification to receive on the browser when an event is triggered on the server. To test with multiple clients, you might open multiple browsers and do the same tests.


1 Answers

As far as I can tell, Cubism wants to poll — and seems to be designed completely around polling, not event-driven pushes. A custom metric is simply meant to fetch data the context decides it wants, so you'd really have to write a custom context designed with things like server-sent events and long-polling/_changes feed architectures.

Or!

Why not write a custom metric that fakes it? Basically, provide a context.metric request function that's closed around a buffer. As you get events, put them in the buffer. Then when Cubism's context gets around to polling your metric fetch function (you can set the clientDelay lower since now it won't actually increase network traffic) you can ± just shift the buffer out right away.

like image 53
natevw Avatar answered Oct 07 '22 00:10

natevw