Recreate the "Real World" Kapacitor example using Chronograf


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:

// create a new field called ‘used’ which inverts the idle cpu.
|eval(lambda: 100.0 - “usage_idle”)
|groupBy(‘service’, ‘datacenter’)
// calculate the 95th percentile of the used cpu.
|percentile(‘used’, 95.0)
|eval(lambda: sigma(“percentile”))
.keep(‘percentile’, ‘sigma’)
.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)

    // Post data to custom endpoint

    // Execute custom alert handler script

    // Send alerts to slack

    // Sends alerts to PagerDuty

    // Send alerts to VictorOps

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.