Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created February 3, 2020 19:18
Show Gist options
  • Save zaneclaes/8d5de538d20a89bf55bbaece25bff8fc to your computer and use it in GitHub Desktop.
Save zaneclaes/8d5de538d20a89bf55bbaece25bff8fc to your computer and use it in GitHub Desktop.
Node Red Forward Prometheus to MQTT
[{"id":"d647cda7.47601","type":"tab","label":"OBD","disabled":false,"info":""},{"id":"c1814e23.3d93d","type":"inject","z":"d647cda7.47601","name":"","topic":"","payload":"","payloadType":"date","repeat":"15","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["e8d485cc.aa10a8"]]},{"id":"e8d485cc.aa10a8","type":"http request","z":"d647cda7.47601","name":"prometheus","method":"GET","ret":"txt","paytoqs":false,"url":"localhost:8000","tls":"","proxy":"","authType":"","x":290,"y":240,"wires":[["1360a3fe.df2cdc"]]},{"id":"1360a3fe.df2cdc","type":"function","z":"d647cda7.47601","name":"stats","func":"lines = msg.payload.split(\"\\n\");\nmsg.payload = [];\nfor(var i=0; i<lines.length; i++) {\n if (lines[i][0] == '#')\n continue;\n if (!lines[i].startsWith('obd_'))\n continue;\n var br = lines[i].indexOf('{');\n var sp = lines[i].indexOf(' ');\n var f = (br > 0 && br < sp) ? br : sp;\n var v = parseFloat(lines[i].substr(f+1))\n msg.payload.push([lines[i].substr(0, f), v]);\n}\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":240,"wires":[["ade236b2.c9c008"]]},{"id":"a7563fcb.2d4ad","type":"function","z":"d647cda7.47601","name":"parse","func":"msg.topic = '/obd/' + msg.payload[0].substr(4);\nmsg.payload = msg.payload[1];\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":240,"wires":[["9d033a07.302b58"]]},{"id":"ade236b2.c9c008","type":"split","z":"d647cda7.47601","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":550,"y":240,"wires":[["a7563fcb.2d4ad"]]},{"id":"9d033a07.302b58","type":"mqtt out","z":"d647cda7.47601","name":"","topic":"","qos":"","retain":"","broker":"beea580d.c54f28","x":790,"y":240,"wires":[]},{"id":"beea580d.c54f28","type":"mqtt-broker","z":"","name":"Van Home Assistant","broker":"192.168.145.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment