Kapacitor Alert Message

Hi,

I’m asking for a simple kapacitor example. I want to create alert when disk space is more than 90% for example. This part is fine but I also want to display total disk space and free size in alert message. So, I want to trigger an alert for metric 1 and display information about metric 2 and metric 3 in alert message.

Can you show me how to accomplish this?

Thanks,

You should be able to achieve that by using multiple streams. you will then use each metric as you wish. See this community post for an example (you won’t need to join the streams if you want just to write a message)

the message can be built in this way using the aliases

|alert() 
        .id( {...} ) // The alert title 
        .message('{{.Level}} - Disk Space > Total Disk Space: ' + string('Total_Disk_Space') + '| Occupied Space: ' + string('Disk_Space') + {...})

Some time ago I found this post which has a really nice and complete TICK script example, it might be useful as an example.

let me know if this works

Edit: removed a non-working solution

1 Like

This should work,

|eval(lambda: ("Free_Megabytes") / 1024.0)
        .as('Free_Gigabytes')
        .keep('Free_Megabytes', 'Percent_Free_Space', 'Free_Gigabytes')

It turns free MB in to GB and keeps all three values. You can alert on the percentage value and to use the newly created fields add {{index .Fields “Free_Gigbyte”}} and so on

Tis how i do it anyways

1 Like

Thanks for the help @philb @Giovanni_Luisotto

I was using perfmon counters for windows devices but couldn’t get the Total Size. Then, I tried [inputs.disk] and it works good so far.

Here is the script I’ve created today, it’s my first TICK Script. Criticism are welcomed. Please, share if you have ideas about improvements.

var measurement = 'disk'    
var groupBy = ['path', 'host']
var whereFilter = lambda: ("path" !~ /mnt/ AND "path" != '/boot')

var message = name + ' Status: {{.Level}}' + '
{{.Group}}
Usage: {{ index .Fields "value" | printf "%0.2f" }} %
Empty Space: {{ index .Fields "free" | printf "%0.2f" }} GB
Total Space: {{ index .Fields "total" | printf "%0.2f" }} GB'

var convert_GiB = 0.0000000009313225746154785

var data = stream
|from()
    .database(db)
    .retentionPolicy(rp)
    .measurement(measurement)
    .groupBy(groupBy)
    .where(whereFilter)
    |eval(lambda: "used_percent", lambda: float("free") * convert_GiB, lambda: float("total") * convert_GiB)
    .as('value', 'free', 'total')
    .keep('value', 'free', 'total')