LogstashでNginxのログをGoogle Cloud Storageに送信

input {
  file {
    path => "/var/log/nginx/access.*.log"
    start_position => "access_pos"
    sincedb_path => "/var/log/nginx/access.pos"
    add_field => { "log_filename" => "%{path}" }
  }

  file {
    path => "/var/log/nginx/error.*.log"
    start_position => "error_pos"
    sincedb_path => "/var/log/nginx/error.pos"
    add_field => { "log_filename" => "%{path}" }
  }
}

filter {
  mutate {
    if [path] =~ "/var/log/nginx/" {
      gsub => [
        "log_filename", "/var/log/nginx/", ""
      ]
    }
  }
}

output {
  google_cloud_storage {
    bucket => "your-bucket-name"
    key_path => "/path/to/your-service-account-key.json"
    log_file_prefix => "logs/"
    temp_directory => "/tmp/logstash-gcs"
    gzip => true
    date_pattern => "%Y/%m/%d"
  }
}