Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How do we retrieve usage by instance? Thank you

How do we retrieve usage by instance? Thank you

Solved Solved
0 11 637
1 ACCEPTED SOLUTION

Hi @imissAWS welcome, please accept my answer as "Solution". Thank you. 

View solution in original post

11 REPLIES 11

Hi @imissAWS

Welcome to Google Cloud Community! 

First, you need to have the Google Cloud SDK installed and configured, and be authenticated to your Google Cloud account.

 View CPU Utilization of a Specific Instance Using Cloud Monitoring

  • Open the Cloud Console
  • Navigate to Monitoring and Metrics Explorer:
    • Click "+ Add query".
    • In the "Metric" dropdown, insert this on the filter compute.googleapis.com/instance/cpu/utilization and select the following resources and categories.

Bwekd8baGek2QFR (1).png

    • Click "Save Chart" to add it to your dashboard.

Note: Make sure to use the time-range selector on the upper right side if you want to view the data for the past week.

Get Basic Instance Information using gcloud

gcloud compute instances describe your-instance-name --zone your-instance-zone

This command will output a lot of information about the instance, including its machine type, zone, status, and more. It won't give you detailed, historical usage metrics, but it can be useful for getting a quick snapshot of the instance.


If you need further assistance, please reach out to our Google Cloud Support team.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

Thanks Reinc, does this mean that there is no way to check usage by instance without going through all these hoops of installation?

We are getting charged by usage, yet we are unable to retrieve the usage via your console without going through these myriad of steps that involves an SDK installation? How does Google track our usage to bill us then?

@imissAWS  Retrieving Google Cloud instance usage through the Google Cloud Console does not require any SDK installation. We can follow the same steps provided by the Google team @reinc to access instance usage.

Additionally, Google Cloud provides right-sizing recommendations in the instance list based on usage patterns. Following these recommendations can help optimize resource allocation and reduce costs. 

Thanks, 
Vinoth_GCP

@DarwinVinoth thanks for your response.  However, @reinc 's response included this line
"First, you need to have the Google Cloud SDK installed and configured, and be authenticated to your Google Cloud account."

Does that mean that you are able to retrieve the usage by instance without any SDK installation?

 

@imissAWS  Google SDK is not compulsory for accessing the GCP data over the Google Cloud console. One more option is to use the Cloud Shell access for gcloud command utility. 

If you haven't enabled billing export, follow:

Go to Billing → Billing Export in the Cloud Console.
Enable export to BigQuery.
Select the dataset where billing data will be stored.

Big Query Example: 

WITH instance_usage AS (
SELECT
usage_start_time,
project.id AS project_id,
resource.name AS instance_name,
resource.location AS region,
sku.description AS sku_name,
usage.amount AS hours_used,
cost,
currency
FROM `your-billing-project.billing_dataset.gcp_billing_export_table`
WHERE service.description = 'Compute Engine'
AND sku.description LIKE '%Instance%'
AND usage.unit = 'h'
AND DATE(usage_start_time) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) -- Last 30 days
)

SELECT
instance_name,
region,
project_id,
TIMESTAMP_TRUNC(usage_start_time, HOUR) AS usage_hour,
SUM(hours_used) AS total_hours,
SUM(cost) AS total_cost
FROM instance_usage
GROUP BY instance_name, region, project_id, usage_hour
ORDER BY usage_hour DESC;

The above query constructs following things in the background, please try it out. 


Filters only Compute Engine instance usage (sku.description LIKE '%Instance%').
Extracts per-instance usage per hour (TIMESTAMP_TRUNC(usage_start_time, HOUR)).
Summarizes total hours and cost per instance per hour.
Filters last 30 days of usage (DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)).

@reinc we tried your suggestion but that gives us utilisation. all we want to know is how are we charged for 11k hours when we only have 3 instances? that's all we want to know. if GCP charges by hour, why can't we get the per hour usage by instance? 

Hi @imissAWS,

You need detailed, granular data (from BigQuery or the Cost Management) to break down the 11,000 hours into instance-specific hourly usage.

Try to enable your billing export on @DarwinVinoth's recommendation and it will breakdown your GCP usage hourly cost.

Thank you.

hi @reinc thanks. we used BigQuery, and saw that the hours for 1 of our instance was 5885.100833. How is that possible, given that the maximum possible hours in a month for 4 vCPU would be only 2976? thank you

Hi @imissAWS,

You correctly calculated that with a 31-day month (some months have 31 days), and with 4 vCPU you get 31 days * 24 hours/day * 4 vCPU= 2976 vCPU hours.

An instance cannot run for more hours than exists in the period being measured. It's a physical impossibility unless something went wrong.

You can check this Export Cloud Billing data to BigQuery. 

hi @reinc thanks for sharing. We did run the query at BigQuery, and that's exactly what it told us. 5885.100833 hours for 1 of our instance. The other instances were at 2968.298889 which looks correct. 

Hi @imissAWS welcome, please accept my answer as "Solution". Thank you.