0

I'm looking for how can I get GCE instance average CPU usage per day using stackdriver python libraries.

I can see per interval series but per day in google docs.

1 Answers1

0

You can do something like this:

curl \
  'https://monitoring.googleapis.com/v3/projects/YOUR_PROJECT_ID/timeSeries?aggregation.alignmentPeriod=86400s&aggregation.perSeriesAligner=ALIGN_MEAN&filter=metric.type%3D%22compute.googleapis.com%2Finstance%2Fcpu%2Fusage_time%22%20AND%20metric.labels.instance_name%3D%22YOUR_INSTANCE_NAME%22&interval.endTime=2020-10-03T00%3A00%3A00Z&interval.startTime=2020-10-01T00%3A00%3A00Z' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

With precision:

  • Replace YOUR_PROJECT_ID by your project ID
  • Replace YTOUR_INSTANCE_NAME by the instance that you want to observe
  • Change your interval.startTime and interval.endTime to match the interval that you want to observe
  • aggregation.alignmentPeriod=86400 means that I ask for a value aggregation per day. But how?? (line below)
  • aggregation.perSeriesAligner=ALIGN_MEAN means that I perform a MEAN for the aggregation.

Therefore, I take the CPU usage of my VM, and I ask a MEAN aggregation every 86400s (every day).

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76