How get a metric sample from monitoring APIs

家住魔仙堡 提交于 2020-06-16 07:06:51

问题


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).

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

On another hand I read from result of a failed request

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?.

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.: This question was originally posted in Google Group but I was encoraged to ask here.

*** Edited after Alex's suggestion

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


回答1:


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

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

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

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

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

EDIT: 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

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)



来源:https://stackoverflow.com/questions/61550776/how-get-a-metric-sample-from-monitoring-apis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!