如何从监视API获取指标样本 [英] How get a metric sample from monitoring APIs

本文介绍了如何从监视API获取指标样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常仔细地查看了监视API .据我所知,可以使用gcloud创建监控策略并编辑策略(

I took a look very carefully to monitoring API. As far as I have read, it is possible to use gcloud for creating Monitoring Policies and edit the Policies ( Using Aleert API).

尽管如此,从一方面来看,gcloud似乎只能创建和编辑策略选项,而不能读取此类策略的结果.在此页面上,我阅读了以下选项:

Nevertheless, from one hand it seems gcloud is able only to create and edit policies options not for reading the result from such policies. From this page I read this options:

Creating new policies
Deleting existing policies
Retrieving specific policies
Retrieving all policies
Modifying existing policies

另一方面,我从结果请求失败

Summary of the result of a failed request to write data to a time series.

因此,我确实可以得到一个结果列表,例如一段时间内所有失败的写入请求.但是如何?

So it rings a bell in my mind that I do can get a list of results like all failed request to write during some period. But how?

请,我的直接问题是:我能以某种方式收听警报事件或获取引发警报结果的列表吗?

Please, my straigh question is: can I somehow either listen alert events or get a list of alert reults throw Monitoring API v3?.

我看到 tag_firestore_instance 在某种程度上与Firestore有关,但如何使用和我可以搜索哪些信息?我在任何地方都找不到如何使用它.可能是常见的获取方式(例如Postman/curl)或来自gcloud shell.

I see tag_firestore_instance somehow related to firestore but how to use it and which information can I search for? I can't find anywhere how to use it. Maybe as common get (eg. Postman/curl) or from gcloud shell.

PS:此问题最初发布在 Google网上论坛,但我被迫在这里提问.

PS.: This question was originally posted in Google Group but I was encoraged to ask here.

***根据亚历克斯的建议进行编辑

*** Edited after Alex's suggestion

我有一个Angular页面,它正在监听Firestore数据库中的文档

I have an Angular page listening a document from my Firestore database

export class AppComponent {
  public transfers: Observable<any[]>;

  transferCollectionRef: AngularFirestoreCollection<any>;

  constructor(public auth: AngularFireAuth, public db: AngularFirestore) {
    this.listenSingleTransferWithToken();
  }

  async listenSingleTransferWithToken() {
    await this.auth.signInWithCustomToken("eyJ ... CVg");
    this.transferCollectionRef = this.db.collection<any>('transfer', ref => ref.where("id", "==", "1"));
    this.transfers = this.transferCollectionRef.snapshotChanges().map(actions => {
      return actions.map(action => {
        const data = action.payload.doc.data();
        const id = action.payload.doc.id;
        return { id, ...data };
      });
    });
  }
}

所以,我知道至少有一个读者要从中返回

So, I understand there is at least one reader count to return from

name: projects/firetestjimis
filter: metric.type = "firestore.googleapis.com/document/read_count"
interval.endTime: 2020-05-07T15:09:17Z

推荐答案

要听懂您说的话有点困难,但这就是我的想法.

It was a little difficult to follow what you were saying, but here's what I've figured out.

这是可用的Firestore指标列表: https://cloud. google.com/monitoring/api/metrics_gcp#gcp-firestore

This is a list of available Firestore metrics: https://cloud.google.com/monitoring/api/metrics_gcp#gcp-firestore

然后您可以将这些指标类型传递给此API https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list

You can then pass these metric types to this API https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list

在该页面上,我使用了右侧的尝试使用此API"工具,并填写了以下内容

On that page, I used the "Try This API" tool on the right side and filled in the following

name = projects/MY-PROJECT-ID

filter = metric.type = "firestore.googleapis.com/api/request_count"

interval.endTime = 2020-05-05T15:01:23.045123456Z

在chrome的检查器中,我可以看到这是该工具发出的GET请求: https://content-monitoring.googleapis.com/v3/projects/MY-PROJECT-ID/timeSeries?filter=metric.type%20%3D%20%22firestore.googleapis.com%2Fapi%2Frequest_count%22&interval.endTime=2020-05-05T15%3A01%3A23.045123456Z&key=API-KEY-GOES-HERE

In chrome's inspector, i can see that this is the GET request that the tool made: https://content-monitoring.googleapis.com/v3/projects/MY-PROJECT-ID/timeSeries?filter=metric.type%20%3D%20%22firestore.googleapis.com%2Fapi%2Frequest_count%22&interval.endTime=2020-05-05T15%3A01%3A23.045123456Z&key=API-KEY-GOES-HERE

上面返回了200,但是有一个空的json有效负载. 我们还需要添加以下条目以填充数据

The above returned 200, but with an empty json payload. We also needed to add the following entry to get data to populate

interval.startTime = 2020-05-04T15:01:23.045123456Z

也请尝试转到此处console.cloud.google.com/monitoring/metrics-explorer,然后在查找资源类型和指标"框中键入firestore,以查看Google自己的仪表板是否填充了数据. (这是为了确认确实有数据供您提取)

Also try going here console.cloud.google.com/monitoring/metrics-explorer and type firestore in the "Find resource type and metric" box and see if google's own dashboards has data populating. (This is to confirm that there is actually data there for you to fetch)

这篇关于如何从监视API获取指标样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆