简体   繁体   English

如何通过python获取GCP实例每天的平均CPU使用率?

[英]how to get the average CPU usage of GCP instance per day via python?

I'm looking for how can I get GCE instance average CPU usage per day using stackdriver python libraries.我正在寻找如何使用 stackdriver python 库获得 GCE 实例每天的平均 CPU 使用率。

I can see per interval series but per day in google docs.我可以在谷歌文档中看到每个间隔系列但每天。

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用您的项目 ID 替换 YOUR_PROJECT_ID
  • Replace YTOUR_INSTANCE_NAME by the instance that you want to observe将 YTOUR_INSTANCE_NAME 替换为您要观察的实例
  • Change your interval.startTime and interval.endTime to match the interval that you want to observe更改您的 interval.startTime 和 interval.endTime 以匹配您要观察的间隔
  • aggregation.alignmentPeriod=86400 means that I ask for a value aggregation per day. Aggregation.alignmentPeriod=86400 意味着我要求每天进行一次价值聚合。 But how??但是怎么样?? (line below) (下面一行)
  • aggregation.perSeriesAligner=ALIGN_MEAN means that I perform a MEAN for the aggregation. Aggregation.perSeriesAligner=ALIGN_MEAN 表示我对聚合执行 MEAN。

Therefore, I take the CPU usage of my VM, and I ask a MEAN aggregation every 86400s (every day).因此,我计算了我的 VM 的 CPU 使用率,并且每 86400 秒(每天)询问一次 MEAN 聚合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM