I need to fetch the GCP metrics without using stackdriver api(without enabling the stackdriver api). Ex. Pub/Sub metrics -> pubsub.googleapis.com/subscription/ack_message_count.
1 Answers
You can interact directly with the Stackdriver Monitoring API to retrieve the metrics you're interested in.
However, this requires the Stackdriver Monitoring API to be enabled since this will start the metric collection (which is needed before you can start fetching them).
Having the API enabled has the additional advantage that has support for the Client Libraries, making metrics fetching easier.
As a partial workaround and specific for ack_message_count, you can use the libraries to take advantage of the seek method available in the PubSub API to get the retained messages in any given subscription:
Messages retained in the subscription that were published before this time are marked as acknowledged, and messages retained in the subscription that were published after this time are marked as unacknowledged. Note that this operation affects only those messages retained in the subscription
This implies that the data is constantly pulled and stored (if needed) in your own persistence layer for latter usage/aggregation.