kapacitor

Send the new inserted value on InfluxDB through HTTP


I'm trying to figure out how I can raise a notification when a new value is inserted on my influxDB and send a notification to an HTTP endpoint with the data of the new inserted measurement sample. I'm not sure if it's the goal of Kapacitor (I'm new on the TICK stack) or it's better to use another tool (any suggestion will be welcome).

Thanks in advance.

Best regards, Albert.


Solution

  • In Kapacitor there is two types of task namely batch and stream. The former is meant for processing historical data and stream is for real time purpose.

    Looking at your requirement I guess it is obvious that stream is the way to go as it will enable you to watch data from an influxdb's measurement in real time. For invoking an endpoint in TICK script you can use the HttpPostNode node.

    Example (Pseudo code ONLY):

    var data = stream
        |from()
            .database('myInfluxDB')
            .retentionPolicy('autogen')
            .measurement('measurement_ABCD')
        |window()
            .period(10s)
            .every(10s)
    
    
    data
        |httpPost('http://your.service.url/api/endpoint_xyz')
    

    In this instance the TICK script will watch for new inserted data on measurement, measurement_ABCD for a window period of 10 seconds before doing a HTTP POST to the defined endpoint and this entire process will repeat again every 10 seconds.

    That is, you have a moving window of 10 seconds.

    Reference:

    https://docs.influxdata.com/kapacitor/v1.3/nodes/http_post_node/