Sometimes you might need some “quick-and-dirty” metrics from your cloud infrastructure. What can you do? Perhaps you need to count monthly API requests, but have not installed an application performance monitoring solution and added agents to your app(s).
Unfortunately the default log retention period is 30 days on Google Cloud Platform (GCP), but you’re now in luck; you can override the logging defaults.
Customize Log Retention
- Stackdriver logs (default: 30 days)
- Audit logs (default: 400 days)
- Metrics (default: 6 weeks)
In the past you would have to create a log sink and ship your logs to cloud storage buckets, PubSub, BigQuery, or another outlet to retain logs for later analysis. This is still advised for long-term storage and analysis, but you have a little more flexibility now with the gcloud CLI beta feature shown below.
- View your current default configuration
gcloud beta logging buckets list
2. Increase your default retention period (between 1 and 3650 days)
gcloud beta logging buckets update _Default --location=global --retention-days=90
3. Confirm your new retention policy is in effect
gcloud beta logging buckets describe _Default --location=global
Build the filters and metrics you want
Once your log retention is as desired (be mindful of storage costs), you can then create filters and metrics as your heart desires.
The Google Cloud Console (web admin) also allows you to filter and download logs, but they are limited. If you want to retrieve logs for a certain period of time or range, consider using the gcloud beta logging read command.