marcuscalidus-svg-panel
marcuscalidus-svg-panel copied to clipboard
Grafana live data working with some tweaks
I managed to get this plugin working with grafana live. Apparently, the data is no longer in ctrl.series, but moved to ctrl.data. I wrote some work-around javascript for onHandleMetric to keep the data in a series, so most of the javascript can stay the same. I set the alias for the time fields from Live data to "ts", so we can easily skip them, and I'm only using the first row for live data.
var series=[];
if (ctrl.series===undefined || ctrl.series.length===0) {
for (i=0;i<ctrl.data.length;i++) {
for (var key in ctrl.data[i].rows[0]) {
if (key!="ts")
series.push(ctrl.data[i].rows[0][key]);
}
}
} else {
for (i=0;i<ctrl.series.length;i++) {
series.push(ctrl.series[i].stats.current);
}
}
// use series below instead of ctrl.series and remove stats.current when capturing values
Kind regards, Dennis
That's great news. Well done Dennis. Will you create a pull request for this?
Hi Marcus, This can actually be typed directly in the onHandleMetric callback by plugin users. It could be added to the documentation. Not sure if ctrl.data is at some point replacing ctrl.series. Kind regards, Dennis
Hi Dennis, good point. If you want, you may include that into the README. If not I'll try to do it in the next week. Thank you for your support Marco
Hi Marco, It would be great if you can add a small description for using Grafana Live data to the README.
To beef the description up a bit, here is a small screen capture of the live voltage&power graphs and SVG plugin at work, the two 50Hz phasors in the middle use the SVG plugin. The raw signals and harmonics on the right, use a regular 1s grafana polling update. I wrote the webserver that serves that websocket in Go-Lang (Python with FastAPI appeared to be a bit slugish), our webserver subscribes using ZMQ to measurement streams from our advanced synchronized sensors and provides near real-time data via REST and websockets to Grafana.
The live data for the SVG plugin is provided via the WebSocket plugin, since the aliases in my query are alphanumerically ordered, the order will be the same with my JavaScript above (the non-shown path, points to the real-time data stream, in this case the power phasor containing active and reactive power for a three phases connection).
Kind regards,
Dennis
P.s. some prior art and description of our grafana visualization is described at https://grafana.com/blog/2021/01/06/how-using-grafana-and-plugins-gave-a-jolt-to-smart-state-technology-a-company-advancing-technology-for-energy-infrastructures/