Convert or truncate values with kapacitor when sending alert message


I have a measurement “Exchange_RoundTrip” that records the time taken to deliver an email message from my exchange server to a remote email account. The value should be in milliseconds, however when the data is recorded it is done so in nanoseconds.

When the alert is fired off, the value shows as nano seconds. Is there a way i can conver this in my TICK script and only output the value in MS?

I tried the following: {{ index .Fields “deliveryTime” | printf “%.2f”}}

this just adds zero’s on the end of the value. The value is stored as an integer (for some reason unknown to me), so i convert it to a float.

My script:

var db = 'REMOVED'

var rp = 'REMOVED'

var measurement = 'Exchange_Roundtrip'

var groupBy = ['host']

var whereFilter = lambda: TRUE

var period = 30s

var every = 30s

var name = 'Exchange RoundTrip	'

var idVar = name + ':{{.Group}}'

var message = ''

var idTag = 'alertID'

var levelTag = 'level'

var messageField = 'message'

var durationField = 'duration'

var outputDB = 'chronograf'

var outputRP = 'autogen'

var outputMeasurement = 'alerts'

var triggerType = 'threshold'

var crit = 150.0

var data = stream
    |eval(lambda: float("delivery_Time"))

var trigger = data
        .crit(lambda: "deliveryTime" > crit)
        // .stateChangesOnly()

        .tag('alertName', name)
        .tag('triggerType', triggerType)


Delivery Time: 10719370.00MS - i know that the time is actually 107MS so even if i can’t convert the value if there is a way to truncate it. I found a truncate option in the documentation but it looks as though this applies to the time stamp.

Appreciate i’d be better off recording the data in ms anyway but i’m just working with the data i have.




I guess this should work:

|eval(lambda: float(“delivery_Time”) / 1000000.0)

Did you try like so?

Hope it helps!

Hi Arturo,

I hadn’t tried that, but i’ve just given it ago. Looking at the data in Grafana and the values I’m getting into my alerts it looks to have worked! Grafana converts it to MS for me and the results match.

Thank you Arturo, it’s much appreciated.


Nice!! Yeah, Grafana make that for us…Although in Kapacitor we need to make the math!!

Nice to hear that the answer works!!!