[Solved]Performing math functions in Kapacitor

Hello,

I have this script (this is part of it)

var data = stream
    |from()
        .database(db)
        .retentionPolicy(rp)
        .measurement(measurement)
        .groupBy(groupBy)
        .where(whereFilter)
    |window()
        .period(period)
        .every(every)
        .align()
    // |mean('mem_active_maximum')
    //     .as('value')

    |eval(lambda: 'mem_active_maximum' / 100)
        .as('percent')
    //|log()
var trigger = data
    |alert()
        .crit(lambda: "percent" > crit)
        .stateChangesOnly()
        .message(message)
        .id(idVar)
        .idTag(idTag)
        .levelTag(levelTag)
        .messageField(messageField)
        .details(details)
        .durationField(durationField)
        .log('/tmp/log.txt')
        .email()

I am trying to divide the value from mem_active_maxiumum by 100. When I define the script i get this:

Failed to compile 0 expression: invalid math operator / for type string

The documentation would suggest that should work. It doesnt, why?

EDIT: the values in the database are 6000%. I’m dividing by 100 to get the same result as i get in Grafana.

Figured it out with fresh eyes. Bloody quotes :slight_smile:

1 Like