Last active
May 23, 2019 01:06
-
-
Save bvader/843359aa6274774351a1e486a6626947 to your computer and use it in GitHub Desktop.
Heartbeat Uptime Percentage Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# New 7.x for computing uptime percentage by URL | |
# Note you can change the timestamp range and interval as needed. | |
# Right now this aggs on "url.domain" but could / should be "monitor.name" or "monitor.id" | |
POST /heartbeat-*/_search?size=0 | |
{ | |
"query": { | |
"range": { | |
"@timestamp": { | |
"gte": "now-24h/h", | |
"lte": "now/h" | |
} | |
} | |
}, | |
"size": 0, | |
"aggs": { | |
"uptime_over_time": { | |
"date_histogram": { | |
"field": "@timestamp", | |
"interval": "15m" | |
}, | |
"aggs": { | |
"uptime_aggs": { | |
"terms": { | |
"field": "url.domain" | |
}, | |
"aggs": { | |
"up_sum": { | |
"sum": { | |
"field": "summary.up" | |
} | |
}, | |
"down_sum": { | |
"sum": { | |
"field": "summary.down" | |
} | |
}, | |
"percent_uptime": { | |
"bucket_script": { | |
"buckets_path": { | |
"up_sum": "up_sum", | |
"down_sum": "down_sum" | |
}, | |
"script": "params.up_sum / (params.up_sum + params.down_sum)" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment