如何从监控API中获取度量样本?

问题描述 投票:1回答:1

我很认真地看了一下,以 监控API. 据我所知,它是可以使用gcloud创建监控策略和编辑策略( 使用Aleert API).

然而,从一方面来看,gcloud似乎只能创建和编辑策略选项,而不能读取这些策略的结果。我从这个页面读到了这个选项。

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.

所以,我心中一惊,我确实可以得到一个结果列表,比如某段时间内所有失败的请求写。但是如何获取呢?

拜托,我的直接问题是:我能否以某种方式监听警报事件或获取警报结果列表,抛出 监控API v3?.

我明白了 tag_firestore_instance 某种程度上与firestore有关,但如何使用它,我可以搜索哪些信息?我在任何地方都找不到如何使用它。也许作为常见的得到(如Postmancurl)或从gcloud shell。

PS.: 这个问题最初发布在 谷歌集团 但我还是想在这里问一下。

*** 根据Alex的建议进行了编辑

我有一个Angular页面从我的Firestore数据库中监听一个文档。

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 };
      });
    });
  }
}

所以,我明白至少有一个读者数是来自于

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

Try This API

google-cloud-platform google-cloud-firestore google-cloud-datastore stackdriver google-cloud-shell
1个回答
1
投票

这是一个有点困难,按照你在说什么,但这里是我已经想通了。

这是一个可用的Firestore指标的列表。https:/cloud.google.commonitoringapimetrics_gcp#gcp-firestore。

然后你可以将这些度量类型传递给这个APIhttps:/cloud.google.commonitoringapiref_v3restv3projects.timeSerieslist。

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

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

EDIT:上面的返回是200,但是是一个空的json payload.我们还需要添加下面的条目来获取数据来填充:

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

也可以尝试在这里控制台.云.谷歌.commonitoringmetrics-explorer,然后输入 firestore 在 "查找资源类型和指标 "框中,看看google自己的dashboards是否有数据弹出。(这是为了确认那里确实有数据供你取用)

© www.soinside.com 2019 - 2024. All rights reserved.