Skip to content

Instantly share code, notes, and snippets.

@pryorda
Last active November 7, 2019 20:22
Show Gist options
  • Save pryorda/cba432e94ac7006caff1af69b20d53ad to your computer and use it in GitHub Desktop.
Save pryorda/cba432e94ac7006caff1af69b20d53ad to your computer and use it in GitHub Desktop.
Get Count of Prometheus values by Day
#!/bin/bash
startdate=2019-10-01
enddate=$(date -I)
d="$startdate"
while [ "$d" != "$enddate" ]; do
current=$d
d=$(date -I -d "$d + 1 day")
data=$(curl -s 'http://prometheus/api/v1/query_range?query=probe_http_status_code\{job="kubernetes-services",instance=~".*conversion.*"\}&start='$current'T00:00:00.000Z&end='$d'T00:00:00.000Z&step=15s')
count=$(echo ${data}|jq '.data.result[0].values[] | select( .[1] != "200")' 2>&1 |grep -c \"0\")
echo ${current}:${count}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment