Recreate the "Real World" Kapacitor example using Chronograf

Hi,

The Kapacitor Getting Started guide has a “real world” example that alerts on a deviation from a 95% percentlie of a cpu metric. I’m wondering how this example can be replicated with Chronograf? This is the relevant TICK script for reference:

stream
|from()
.measurement(‘cpu’)
// create a new field called ‘used’ which inverts the idle cpu.
|eval(lambda: 100.0 - “usage_idle”)
.as(‘used’)
|groupBy(‘service’, ‘datacenter’)
|window()
.period(1m)
.every(1m)
// calculate the 95th percentile of the used cpu.
|percentile(‘used’, 95.0)
|eval(lambda: sigma(“percentile”))
.as(‘sigma’)
.keep(‘percentile’, ‘sigma’)
|alert()
.id(’{{ .Name }}/{{ index .Tags “service” }}/{{ index .Tags “datacenter”}}’)
.message(’{{ .ID }} is {{ .Level }} cpu-95th:{{ index .Fields “percentile” }}’)
// Compare values to running mean and standard deviation
.warn(lambda: “sigma” > 2.5)
.crit(lambda: “sigma” > 3.0)
.log(’/tmp/alerts.log’)

    // Post data to custom endpoint
    .post('https://alerthandler.example.com')

    // Execute custom alert handler script
    .exec('/bin/custom_alert_handler.sh')

    // Send alerts to slack
    .slack()
    .channel('#alerts')

    // Sends alerts to PagerDuty
    .pagerDuty()

    // Send alerts to VictorOps
    .victorOps()
    .routingKey('team_rocket')

In particular I’m interested in how to implement the eval(), the percentile(), and the alert().id() in Chronograf. I’m also wondering if templates are possible through Chronograf.

Thanks in advance.

If what you mean is how to recreate this TICK script in Chronograf, the easiest way is to create the script on your local machine and then use Kapacitor to upload it to your Chronograf instance.
kapacitor -url http://<your server name>:9092 define <alert_name> -tick <path to TICK script> -type stream -dbrp <database>.autogen

That will upload the script to your server and enable the alert. If you then go into your Chronograf instance, and go to ‘Alerts’ you will see the alert defined, and you can view the TICK script, but you won’t be able to modify it via Chronograf.

dg