Google Cloud Cost Control is a feature that allows you to monitor and manage your Google Cloud spending. It provides a range of tools and resources that can help you optimize your Cloud costs, including:
- Cost reports and alerts: You can set up cost reports and alerts to help you understand how much you are spending on Google Cloud, and to get notified when your costs exceed a certain threshold.
- Budgets and threshold alerts: You can set budgets and threshold alerts to help you stay within your desired spending limits.
- Cost optimization recommendations: Google Cloud Cost Control provides recommendations on how you can optimize your Cloud costs, such as by turning off idle resources or by using more cost-effective pricing options.
- Cost analysis tools: You can use cost analysis tools like the Cost Explorer and the BigQuery Reservations Cost Analysis report to understand how your costs are being incurred and to identify opportunities for optimization.
Google Cloud Cost Control is available to all Google Cloud users, and it can be accessed through the Google Cloud Console or the Google Cloud API.
Most of the time we create resources but forget to delete residues. For example, If we create GKE cluster and assign some persistent volume, After deleting the GKE it will not delete the persistent disk. SSD(Balance Persistence Delete) costing is considerable we should not ignore this.
List all the unused disk in Google Cloud project :
#List all the
$ project=<Project_ID>
$ gcloud compute disks list --filter="status=READY AND -users:*" --project $project --format='table[box](name,zone,creationTimestamp,sizeGb,status)' --sort-by creationTimestamp
Delete un-assigned Disk :
$ zone=asia-south1-b
$ project=<Project_ID>
$ gcloud compute disks list --format='value(name,zone,status)' --zones $zone --project $project | awk '$3 == "READY" {print $1}' | xargs -I {} gcloud compute disks delete {} --quiet --project $project --zone $zone
This will delete only un-assigned disk, even if try to delete assigned disk to instance it will throw error.
Log Exclusion Level
In Google Cloud, log exclusions allow you to specify patterns for log entries that you do not want to be ingested into Stackdriver Logging. You can set the log exclusion level to either INFO
, ERROR
, or DEBUG
.
Here is how the log exclusion levels work:
INFO
level log exclusions: These exclusions apply to log entries with a severity level ofINFO
or higher.ERROR
level log exclusions: These exclusions apply to log entries with a severity level ofERROR
or higher.DEBUG
level log exclusions: These exclusions apply to log entries with a severity level ofDEBUG
or higher.
You can set the log exclusion level when creating or modifying a log exclusion. To do this, you can use the Google Cloud Console, the gcloud command-line tool, or the Stackdriver Logging API.
Logging → Log Router → Edit _Default sink → Add below two exclusion filters → Save the sink config.1
Exclusion of INFO and DEBUG Logs :
Edit _Default sink configuration to exclude INFO and DEBUG Container Logs, as well as we can exclude Load Balancer logs as well to reduce the cost if it’s not required
Edit default sink
Choose logs to filter out of sink
Exclusion filter name: kubernetes_debug_info_log_exclusion
Filter:
resource.type="k8s_container"
severity=INFO OR
severity=DEBUG
Exclusion filter name: loadbalancer_info_log_exclusion
Filter:
resource.type="internal_http_lb_rule"
OR resource.type="http_load_balancer"
Log Retention Period :
In Google Cloud, the log retention period is the length of time that log entries are stored in Stackdriver Logging. By default, log entries are retained for 30 days, but you can change the log retention period to any value between 7 days and 7 years.
To change the log retention period, you can use the Google Cloud Console, Here’s an example of how to change the log retention period using the GUI:
Reference :