Broda Noel
Broda Noel

Reputation: 2026

How to measure my clients API and Bandwidth (Store) usage in Google Cloud Platform?

I have an App that consumes my own API (Google Cloud Functions) and my own Storage (there are images).

Now, I have a couple of clients, that wants to consume my API and my Storage (A Google Cloud Bucket).

The Cloud Storage is a bucket that contains a lot of photo that have Public Read Access.

I'm trying to define a tier pricing model, in which the price depends on 2 things:

  1. The number of API calls,
  2. The Cloud Storage Bandwidth

Meaning, I want to set some pricing in relation to the costs they are consuming on my Google Cloud account.

To give an example: If a client does between 1 and 500.000 API calls, I'll change them 10 dollars. Between 500.001 and 1.000.000, I'll charge 18 dollars, etc, etc.

Same thing for the Cloud Storage Bandwidth, if they consume between 0GM and 10GB, it's going to cost 10 dollars. If they consume between 10GB and 100GB, it's going to cost 18 dollars, etc, etc.

How can I do it with Google Cloud? How can I know how my clients are consuming? And is there a way to share that information with them, so they are able to monitor the usage every day?

I'm thinking that measuring the API usage is not going to be THAT hard, because I can just save a value in the DB every time the user calls the API, but if there is a way to avoid it, will be good, due to Google Cloud is going to charge me for that DB write action (that I use to track the API usage).

On the other hand, for measuring the Cloud Storage, I was thinking something like this:

Let's suppose I have a Public Bucket with photos in the URL: buckets.google.com/photos. If my client wants to get the /cats/ugly-cat.jpg photo, I can ask them to call A FUNCTION in /api/get-photo/?url=/cats/ugly-cat.jpg, so there in that Function a can track that the user just get a photo, and then I redirect the call to the real URL where the user is going to see the photo (buckets.google.com/photos/cats/ugly-cat.jpg). As you can see, this idea seems to be too ppor performant, due to it's going to charge the Function usage, the DB write, and also the Storage bandwidth usage. And even, that way doesn't track the Bandwidth. It only tracks the number of photos that the client wants to show.

As you can see, both ideas are a bit ugly, with poor performance. There should be something already done that makes it beautiful.

Obviously, the API call (and also the photo link) may have the client API-KEY, to help to measure the usage. Something like:

Where 111 identifies the client 111.

So, the question: Do you know if there is a "best-known" way to do measure those usages?

Upvotes: 0

Views: 652

Answers (1)

Corinne White
Corinne White

Reputation: 446

I think Cloud Endpoints is the best solution for you because managing your API as you suggest might get unwieldy quickly.

Endpoints provides all the tools to control authentication, quota and cost management and a developer portal so your users can access documentation and interact with your API. It also integrates with all Cloud Platform products including Cloud Functions.

Upvotes: 1

Related Questions