added SQL query to grab metrics averaged over a bucket