Skip to content

Grafana retaining logs

Published: at 11:20 AM

Retaining Logs using Cloud Logs Export

Grafana retains logs, traces and profiles for 30 days by default. This is a good starting point, but you may want to retain logs for longer periods for compliance or troubleshooting purposes. Grafana Cloud Logs Export allows you to export logs to an S3 bucket for long-term retention.

Setting up Cloud Logs Export

Amazon S3 (AWS) - Instructions

  1. Create an S3 bucket to export your logs to.
  2. Allow Cloud Logs Export access to your bucket by creating and attaching a bucket policy statement.
{
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn provided by Grafana Cloud"
      },
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::{{ BUCKET_NAME }}"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn provided by Grafana Cloud"
      },
      "Action": ["s3:GetObject", "s3:GetObjectAttributes", "s3:PutObject"],
      "Resource": "arn:aws:s3:::{{ BUCKET_NAME }}/*"
    }
  ]
}

Create a lifecycle policy to manage the retention of your logs. Under the Management tab, select Lifecycle, and then click Add lifecycle rule. Configure the rule to delete logs after a specified number of days.

{
  "Rules": [
    {
      "ID": "Delete logs after 365 days",
      "Status": "Enabled",
      "Prefix": "",
      "Expiration": {
        "Days": 365
      }
    }
  ]
}

Resources

Retain logs longer without breaking the bank: Introducing Grafana Cloud Logs Export Cloud Logs Export


Previous Post
Setting up my homelab