mqtt to grafana simpleJson bridge (webservice)
With this flow, you can plug Grafana SimpleJson datasource to your node-red instance in order to poll MQTT real time values (historical values are not available).
NodeRed configuration
Copy and paste this example to NodeRed Link multiple MQTT topic listener to StoreToFlowContext function input
Note: / in mqtt topics are replaced with _ in variable names
Grafana configuration
Just configure SimpleJson datasource with URL [http://your_node_red_instance:1880/] in grafana.
SimpleJson requires two POST methods: search and query in order to list available variables in grafana metrics. These two methods are implemented by two HTTP endpoints.
Sea documentation here at Grafana simple Json plugin site
[{"id":"d6e8edce.d5fb88","type":"change","z":"49e8c24b.3113ac","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":340,"wires":[["c12dbd81.44ca88"]]},{"id":"cf780c20.8982d","type":"mqtt in","z":"49e8c24b.3113ac","name":"","topic":"m/e/int/imp/compteur","qos":"2","broker":"521e4ee9.7676b","x":140,"y":500,"wires":[["710bed4d.14d32c"]]},{"id":"d2c78cfd.353a08","type":"http in","z":"49e8c24b.3113ac","name":"","url":"/query","method":"post","upload":false,"swaggerDoc":"","x":110,"y":340,"wires":[["f17105fc.e48508"]]},{"id":"134f7576.802123","type":"template","z":"49e8c24b.3113ac","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"[\n {\n \"target\":\"{{ topic }}\",\n \"datapoints\":[\n [{{ payload }},{{ts}}]\n ]\n }\n]","x":450,"y":340,"wires":[["d6e8edce.d5fb88"]]},{"id":"c12dbd81.44ca88","type":"http response","z":"49e8c24b.3113ac","name":"","x":750,"y":340,"wires":[]},{"id":"710bed4d.14d32c","type":"function","z":"49e8c24b.3113ac","name":"StoreToFlowContext","func":"flow.set(msg.topic.replace(/\\//g, '_'),msg.payload);\nreturn null;","outputs":1,"noerr":0,"x":460,"y":420,"wires":[[]]},{"id":"f17105fc.e48508","type":"function","z":"49e8c24b.3113ac","name":"QueryTopic","func":"msg.topic=msg.payload.targets[0].target;\nmsg.payload=flow.get(msg.payload.targets[0].target);\nmsg.ts = Math.round((new Date()).getTime());\n\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":340,"wires":[["134f7576.802123"]]},{"id":"9df53e78.80db18","type":"function","z":"49e8c24b.3113ac","name":"ListTargetsInFlowContext","func":"msg.payload=flow.keys();\nmsg.payload.shift();\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":260,"wires":[["50683cf0.0e080c"]]},{"id":"a9eb07b9.38f888","type":"http in","z":"49e8c24b.3113ac","name":"","url":"/search","method":"post","upload":false,"swaggerDoc":"","x":110,"y":260,"wires":[["9df53e78.80db18"]]},{"id":"50683cf0.0e080c","type":"change","z":"49e8c24b.3113ac","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":260,"wires":[["8982de3d.5452c8"]]},{"id":"8982de3d.5452c8","type":"http response","z":"49e8c24b.3113ac","name":"","x":790,"y":260,"wires":[]},{"id":"4979e26c.dbce2c","type":"mqtt in","z":"49e8c24b.3113ac","name":"","topic":"m/e/int/freebox/maxrate","qos":"2","broker":"521e4ee9.7676b","x":150,"y":460,"wires":[["710bed4d.14d32c"]]},{"id":"328224ef.72d9f4","type":"mqtt in","z":"49e8c24b.3113ac","name":"","topic":"m/e/int/freebox/wifienabled","qos":"2","broker":"521e4ee9.7676b","x":150,"y":420,"wires":[["710bed4d.14d32c"]]},{"id":"521e4ee9.7676b","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]