Hello,
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
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|window()
.period(period)
.every(every)
.align()
|mean('delivery_time_seconds')
.as('delivery_Time')
|eval(lambda: float("delivery_Time"))
.as('deliveryTime')
var trigger = data
|alert()
.crit(lambda: "deliveryTime" > crit)
// .stateChangesOnly()
.message(message)
.details(details)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.email('pb@email.co.uk')
trigger
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag('alertName', name)
.tag('triggerType', triggerType)
trigger
|httpOut('output')
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.
Thanks,
Phil