Batch Influxdb writes. Refactor code