maX
maX

Reputation: 742

google cloud storage per file statistics/downloads

Is it possible to get per file statistics (or at least download count) for files in google cloud storage?

I want to find the number of downloads for a js plugin file to get an idea of how frequently these are used (in client pages).

Upvotes: 3

Views: 1479

Answers (2)

Neo Anderson
Neo Anderson

Reputation: 6340

Yes, it is possible, but it has to be enabled.

The official recommendation is to create another bucket for the logs generated by the main bucket that you want to trace.

gsutil mb gs://<some-unique-prefix>-example-logs-bucket

then assign Cloud Storage the roles/storage.legacyBucketWriter role for the bucket:

gsutil iam ch group:[email protected]:legacyBucketWriter gs://<some-unique-prefix>-example-logs-bucket

and finally enable the logging for your main bucket:

gsutil logging set on -b gs://example-logs-bucket gs://<main-bucket>

Generate some activity on your main bucket, then wait for one hour at most, hence the reports are generated hourly and daily. You will be able to browse these events on the logs-bucket created at step 1:

logs-files-saved-in-aux-bucket

More info, can be found at https://cloud.google.com/storage/docs/access-logs

Upvotes: 7

Arthur Davis
Arthur Davis

Reputation: 51

In most cases, using Cloud Audit Logs is now recommended instead of using legacyBucketWriter.

Logging to a separate Cloud Storage bucket with legacyBucketWriter produces csv files, which you would have to then load into BigQuery yourself to make them actionable, and this would be done far from in real time. Cloud Audit Logs are easier to set up and work with by comparison, and logs are delivered almost instantly.

Upvotes: 0

Related Questions