【问题标题】:How get a metric sample from monitoring APIs如何从监控 API 中获取指标样本
【发布时间】:2020-08-16 10:22:45
【问题描述】:

我很仔细地看了monitoring API。据我所知,可以使用 gcloud 创建监控策略并编辑策略 (Using Aleert API)。

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

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

另一方面,我从result of a failed request读到

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

所以它在我脑海中敲响了警钟,我确实可以获得一个结果列表,例如在某个时期内所有失败的写入请求。但是怎么做呢?

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

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

PS.:这个问题最初是在Google Group 发布的,但我很高兴在这里问。

*** 在 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

【问题讨论】:

    标签: google-cloud-platform google-cloud-firestore google-cloud-datastore stackdriver google-cloud-shell


    【解决方案1】:

    听懂你说的有点困难,但这是我想出来的。

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

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

    在那个页面上,我使用了右侧的“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&amp;interval.endTime=2020-05-05T15%3A01%3A23.045123456Z&amp;key=API-KEY-GOES-HERE

    编辑: 以上返回 200,但带有一个空的 json 有效负载。 我们还需要添加以下条目来获取要填充的数据

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

    还可以尝试访问此处 console.cloud.google.com/monitoring/metrics-explorer 并在“查找资源类型和指标”框中输入 firestore,然后查看 google 自己的仪表板是否填充了数据。 (这是为了确认那里确实有数据供您获取)

    【讨论】:

    • 好吧,我仍然在努力完成这项工作。我将用图片编辑我的问题。简而言之,按照您的建议,我尝试了以下步骤:(1) 我从 Firestore 中读取了一个名为 firetestjimis 的文档 (2) 我尝试获取 Firestore 到明天之前遭受了多少次读取,然后结果就是 {}
    • 不幸的是,我使用的是数据存储而不是 Firestore,所以我无法准确了解您在做什么,但我尝试了它用于数据存储并且也刚刚得到了 {}。但我可以通过将interval.startTime 设置为2020-05-04T15:01:23.045123456Z 来修复它
    • 您可以尝试探索的另一个地方是指标资源管理器。转到此处console.cloud.google.com/monitoring/metrics-explorer 并在Find resource type and metric 框中输入firestore,看看谷歌自己的仪表板是否有数据填充
    • 当然,我的意思是您应该使用“metric explorer”来确认数据确实存在。设置interval.startTime 解决了什么问题?
    • 不幸的是,这对于 GCP 文档来说并不少见。这些年来他们一直在变得更好,但他们仍然有很多不足之处。我将编辑我的答案以包括 interval.startTime
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多