Control: SQL DB instance having low CPU utilization should be reviewed
Description
DB instances may be oversized for their usage.
Usage
Run the control in your terminal:
powerpipe control run gcp_thrifty.control.sql_db_instance_low_utilizationSnapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run gcp_thrifty.control.sql_db_instance_low_utilization --shareSteampipe Tables
SQL
with sql_db_instance_usage as (  select    instance_id,    round(cast(sum(maximum) / count(maximum) as numeric), 1) as avg_max,    count(maximum) as days  from    gcp_sql_database_instance_metric_cpu_utilization_daily  where    date_part('day', now() - timestamp) <= 30  group by    instance_id)select  i.self_link as resource,  case    when avg_max is null then 'error'    when avg_max <= $1 then 'alarm'    when avg_max <= $2 then 'info'    else 'ok'  end as status,  case    when avg_max is null then 'Logging metrics not available for ' || title || '.'    else title || ' is averaging ' || avg_max || '% max utilization over the last ' || days || ' days.'  end as reason    , i.location, i.projectfrom  gcp_sql_database_instance as i  left join sql_db_instance_usage as u on i.project || ':' || i.name = u.instance_id
Params
| Args | Name | Default | Description | Variable | 
|---|---|---|---|---|
| $1 | sql_db_instance_avg_cpu_utilization_low |  | The average CPU utilization required for DB instances to be considered infrequently used. This value should be lower than sql_db_instance_avg_cpu_utilization_high. | |
| $2 | sql_db_instance_avg_cpu_utilization_high |  | The average CPU utilization required for DB instances to be considered frequently used. This value should be higher than sql_db_instance_avg_cpu_utilization_low. |