[Solved] Writing a TICKscript to aggregate multiple measurements into one

As an update, I did figure it out. I needed to write the script as a stream instead of batch type for my environment, after poking around with things for a bit. I had hit a silly error in the below thread, and also saw that you can combine multiple operations into a single eval() node. This simplified what I was trying to do.

You can see more of that in this thread:

For anyone who stumbles on this later, here is a short example of how to write the TICKscript as a stream type.

// Get cpu_sys
var cpu_sys = stream
    |from()
        .database(db)
        .retentionPolicy(rp)
        .measurement('container_cpu_system_seconds_total')

// Get cpu_user
var cpu_user = stream
    |from()
        .database(db)
        .retentionPolicy(rp)
        .measurement('container_cpu_user_seconds_total')

// Get cpu_total
var cpu_total = stream
    |from()
        .database(db)
        .retentionPolicy(rp)
        .measurement('container_cpu_usage_seconds_total')

// Aggregate metrics
cpu_total
    |join(cpu_user, cpu_sys)
        .as('cpu_total', 'cpu_user', 'cpu_sys')
        .tolerance(10s)
        .fill('null')
    |eval(
        lambda: "cpu_total.counter",
        lambda: "cpu_sys.counter",
        lambda: "cpu_user.counter"
    )
        .as('total', 'system', 'user')
    |influxDBOut()
        .database(db)
        .retentionPolicy(rp)
        .measurement('container_cpu_seconds')
        .precision('s')
1 Like