I want to get the recommendation to resize the instances which gcp shows on there ui for compute instances either through any gcloud command or any api which google provides for stackdriver. (any method would work, just need to get the data of there recommendations they provide of resizing the instances)
Google has made this available through its Recommender API (note that it still in beta).
You can interact with it with eitherthe gcloud command-line tool, for example, to list recommendations on Compute Engine instance type:
gcloud beta recommender recommendations list \
--project=example-project \
--location=us-central1-a \
--recommender=google.compute.instance.MachineTypeRecommender \
--format=json
or with the REST API. For example:
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: example-project" \
"https://recommender.googleapis.com/v1beta1/projects/example-project/locations/us-central1-a/recommenders/google.compute.instance.MachineTypeRecommender/recommendations"
You can have a look here to get more details info about available actions.