I am using Pubsub as a queuing mechanism tool and want to know the count of the messages residing inside the topic of Pubsub. For the same purpose, I have decided to use the Google API metric pubsub.googleapis.com/subscription/num_undelivered_messages
but I am unable to figure out how can this be achieved using python client library monitoring_v3.
from google.cloud import monitoring_v3
import time,os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/key.json"
client = monitoring_v3.MetricServiceClient()
project = 'project_name'
project_name = client.project_path(project)
metric_type = "pubsub.googleapis.com/subscription/num_undelivered_messages"
Can you please guide me on how to proceed further and query this google api metric named as num_undelivered_messages?
This works for me but I am not sure if it's the creator's intention.
from google.cloud import monitoring_v3
from google.cloud.monitoring_v3 import query
project = "..."
client = monitoring_v3.MetricServiceClient()
result = query.Query(
client,
project,
'pubsub.googleapis.com/subscription/num_undelivered_messages',
minutes=1).as_dataframe()