简体   繁体   English

通过命令行/bash 脚本将 CPU 利用率等指标提取到报告中?

[英]Extracting metrics such as CPU utilization into reports via command line/bash scripts?

In Azure for example, I created a few bash scripts give me things like average daily CPU utilization over whatever time period I want for any/all VMs using their command line tool.例如,在 Azure 中,我创建了一些 bash 脚本,使用他们的命令行工具为我提供任何/所有虚拟机在任何时间段内的平均每日 CPU 利用率。

I can't seem to figure out how to do this in Google cloud except by manually using the console (automatically generated daily usage reports don't seem to give me any CPU info either), so far numerous searches have told me that using the monitoring function in the google cloud console is basically the only way I can do this, as the cli "gcloud" will only report quotas back which isn't really what I'm after here.我似乎无法弄清楚如何在谷歌云中执行此操作,除非手动使用控制台(自动生成的每日使用情况报告似乎也没有给我任何 CPU 信息),到目前为止,大量搜索告诉我使用在谷歌云控制台中监控 function 基本上是我能做到这一点的唯一方法,因为 cli“gcloud”只会报告配额,这并不是我真正想要的。 I haven't bothered with the ops agent install yet, as my understanding is that this is just for adding additional metrics (to the console) and not functionality to the google cloud cli.我还没有为 ops agent 安装而烦恼,因为我的理解是这只是为了添加额外的指标(到控制台)而不是谷歌云 cli 的功能。 Up to this point I've only ever managed Azure and some AWS, so maybe what I'm trying to do isn't even possible in Google cloud?到目前为止,我只管理过 Azure 和一些 AWS,所以也许我想做的事情在谷歌云中是不可能的?

Monitoring (formerly Stackdriver) does seem to be neglected by the CLI ( gcloud ). CLI ( gcloud ) 似乎忽略了监控(以前称为 Stackdriver)。

There is a gcloud monitoring "group" but even the gcloud alpha monitoring and gcloud beta monitoring commands are limited (and don't include eg metrics).有一个gcloud monitoring “组”,但即使是gcloud alpha monitoringgcloud beta monitoring命令也是有限的(并且不包括例如指标)。

That said, gcloud implements Google's underlying (service) APIs and, for those (increasingly fewer) cases where the CLI does not yet implement an API and its methods, you can use APIs Explorer to find the underlying eg Monitoring service directly.也就是说, gcloud实现了 Google 的底层(服务)API,对于 CLI 尚未实现 API 及其方法的那些(越来越少的)情况,您可以使用APIs Explorer直接找到底层的监控服务。

Metrics can be access through a query over the underlying time-series data, eg projects.timeseries.query .可以通过对底层时间序列数据的查询来访问指标,例如projects.timeseries.query The interface provides a form that enables you to invoke service methods from the browser too.该接口提供了一种形式,使您也可以从浏览器调用服务方法。

You could then use eg curl to construct the queries you need for your bash scripts and other tools (eg jq ) to post-process the data.然后,您可以使用例如curl来构造您的 bash 脚本和其他工具(例如jq )所需的查询以对数据进行后处理。

Alternatively, and if you want a more programmatic experience with good error-handling and control over the output formatting, you can use any of the language-specific SDKs ( client libraries ).或者,如果您想要更好的错误处理和控制 output 格式的编程体验,您可以使用任何特定于语言的 SDK(客户端库)。

I'd be surprised if someone hasn't written a CLI tool to complement gcloud for monitoring as it's a reasonable need.如果有人没有编写 CLI 工具来补充gcloud进行监控,我会感到惊讶,因为这是合理的需要。

It may be worth submitting a feature request on Google's Issue Tracker.在 Google 的问题跟踪器上提交功能请求可能是值得的。 I'm unsure whether it would best be placed under Cloud CLI or Monitoring .我不确定最好将它放在Cloud CLI还是Monitoring下。 Perhaps try Monitoring .也许试试Monitoring

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

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