Search code examples
expressionscheduled-tasksinfluxdb

InfluxDB Task to Calculate/Insert Value


I am trying to calculate/insert a value into my InfluxDB 2.0.8 on a regular interval....can this be done with a task?

For a over simplified example: How can I evaluate 1+1 once an hour and insert the result into the database?


Solution

  • I assume you are well aware of the general intrinsics of tasks and how to set up a task. The only thing missing then is how to generate data rows that do not result from querying. The method array.rows() comes handy for this.

    Here is an example - I did not try it.

    import "array"
    option task = {name: "oneplusone", every: 1h}
    
    array.from(rows: [
        {_time: now(), _measurement: "calculation", _field: "result", _value: 1+1}
    ])|> to(bucket: "mybucket")