简体   繁体   中英

How to pull pubsub metrics from google api

We are using our own logging solution because stackdriver is su...bpar. I want to pull the metrics on how many unacknowledged messages there are in the pubsub. Started to read the docs on that and they are all over the place.

Found this page: https://cloud.google.com/monitoring/api/metrics Despite being under the api it does not describe any api calls, but does contain the description of the metric I want to extract.

Now I am thinking I need to use the monitoring api to extract what I need somehow: https://cloud.google.com/monitoring/api/ref_v3/rest/

So I use the api explorer to try a couple of methods: https://developers.google.com/apis-explorer/#search/monitoring/monitoring/v3/monitoring.projects.groups.list

I query and gives me an available url:

GET https://monitoring.googleapis.com/v3/projects/myprojectname/groups?key={YOUR_API_KEY}

I go to my project's console (api & credentials page) and generate an api key without restrictions and paste it in trying to curl.

curl https://monitoring.googleapis.com/v3/projects/myproject/groups?key=myrandomkeylkjlkj
{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

Why is this happening? How can I get the metrics? I went to the url provided but it explains oauth token creation and has nothing regarding the api keys. I just need to curl things to make sure I am going the right way.

Why does this have to be so hard? Killed several hours of my life trying to get this.

curl -H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://monitoring.googleapis.com/v3/projects/myproject/groups

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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