Hi,
I have the following watcher:
{ "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "search_type": "query_then_fetch", "indices": [ "metricbeat-*" ], "rest_total_hits_as_int": true, "body": { "size": 0, "query": { "bool": { "must": [ { "range": { "system.cpu.total.norm.pct": { "gte": 0.8 } } } ], "filter": { "range": { "@timestamp": { "gte": "now-1m" } } } } }, "aggs": { "servidores": { "terms": { "field": "host.hostname" }, "aggs": { "max_cpu": { "max": { "field": "system.cpu.total.norm.pct" } }, "avg_cpu": { "avg": { "field": "system.cpu.total.norm.pct" } } } } } } } } }, "condition": { "compare": { "ctx.payload.hits.total": { "gt": 0 } } }, "actions": { "send_email": { "throttle_period_in_millis": 300000, "condition": { "compare": { "ctx.payload.hits.total": { "gt": 0 } } }, "email": { "profile": "standard", "to": [ "<emailtest@hotmail.com>" ], "subject": "[elastic] Warning Incident started: Alert - High CPU consumption - Machines > 80% ", "body": { "html": " <h3> Machines with CPU over 80%</h3>\n <ul>\n {{#ctx.payload.aggregations.servidores.buckets}} \n <li> {{key}} {{cpu_max.value}}%</li>\n {{/ctx.payload.aggregations.servidores.buckets}}\n </ul>" } } } } }
The following image shows how the data is arriving in the mail:
As you can see the values are shown as decimals. What I want is to see them in percentages for example: 94.20%, 86.5%, 83.8%, 99.3% rounded to two digits.
I have tried to implement it using the following:
"transform":{
"script": "return: [cputest:system.cpu.total.norm.pct]"
}
But it shows me an error in the syntax of the query.
I hope you can help me.
Regards.