Create streaming datasource plugin that listens to websocket

Hello,

I’m trying to develop a telemetry server, for a real time application, that runs on a raspberry pi. At first I tried to configure a InfluxDB instance on it and simply set up a Influxdb datasource that queries the db with a frequency of 10Hz, but it turned out to be too much work for a single pi to handle.

there’s where I got the idea to bypass the database and simply stream directly to Grafana only data that changes in order to have a (pseudo) real time telemetry system.

For what I can read online, this was a requested feature in the past years but currently there doesn’t exist a fully working plugin that allows it. (correct me if I’m wrong).

I tried to develop my own streaming plugin following the tutorials “building a datasource plugin” and “building a streaming datasource plugin”, but I’m already facing a problem (probably first of many).

If there is another way to achieve my goal pleas tell me, otherwise a bit of help on my problem would be very appreciated!

I managed to set up a datasource and when I run a query I just receive a costant (default) value. I tried to change the code (see images) in datasource.ts by changing values to return and in types.ts and QueryEditor.tsx to change the “MyQuery” and allow the user to have an additional parameter in the query but the problem I get is the following:

  1. I keep receiving a costant value
  2. I cannot see the box for the additional variable of the query in grafana.

Could you please tell me what I’m doing wrong?

Grafana version : 7.4.3

[QueryEditor.tsx]

(As I am a new user I’m allowed to post only 2 pictures, I posted the most significative ones. I’ll report below the code of “MyQuery” and the “query” method in datasource.ts)

export interface MyQuery extends DataQuery {

  queryText?: string;

  constant: number;

  offset: number,

}
async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {

    const { range } = options;

    const from = range!.from.valueOf();

    const to = range!.to.valueOf();

    // Return a constant for each query.

    const data = options.targets.map(target => {

      const query = defaults(target, );

      const frame = new MutableDataFrame({

        refId: query.refId,

        fields: [

          { name: 'time', type: FieldType.time },

          { name: 'value', type: FieldType.number },

        ],

      });

      for(var i = 0; i < 10; i++) {

        frame.add({ time: from + (i * 10), value: i + query.offset });

      }

    });

    return { data };

  }

How about installing InfluxDB on the same machine that you’re running Grafana
on (which means the DB queries to get the data Grafana needs to represent
should be quick and efficient) and then send data from the RPi telemetry device
to this InfluxDB instance?

That gives the RPi very little to do, sends as little data over the network as
possible, and stores it somewhere a bit more reliable than an RPi SD card.

Antony.

You have to dig in the source code to see how it is implemented.

I have a backup DB which is not meant to be suitable for a real time application. I need the raspberry pi in order to see data as fast as possible. Both Grafana and InfluxDB currently run on the pi (see image).

I would like to keep using the pi since it brings many benefits to my project, but it cannot handle this workload. (I know I could use a laptop instead but as I said I really would like to find a way to use the pi)

I wish there was an easy way to directly push data into Grafana without storing it into InfluxDB and execute queries on it.

I wish there was an easier solution than just dig into the source code and try to reverse engineer it.

I would anyway really appreciate any feedback you could give on my problem related to the query, since it applies also to any other system which doesn’t use a streaming feature.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.