I am currently trying to install the ops agent on some ubuntu 18.04 gcloud VM instance I am creating with a bash script, based off the gcloud guide accessible here. The script goes as following:
echo "Installing components for agent policies"
gcloud components install beta
echo "Enabling API and setting proper permissions for monitoring"
sh set-permissions.sh --project=XXX
gcloud beta compute instances ops-agents policies create ops-agents-policy-safe-rollout \
--agent-rules="type=logging,version=current-major,package-state=installed,enable-autoupgrade=true;type=metrics,version=current-major,package-state=installed,enable-autoupgrade=true" \
--os-types=short-name=ubuntu,version=18.04 \
--project=XXX \
--instances=zones/us-central1-a/instances/instance-XXX
...
gcloud compute instances create instance-XXX --boot-disk-size=100GB \
--boot-disk-type=pd-ssd --metadata=enable-oslogin=TRUE \
--image-family=ubuntu-minimal-1804-lts --image-project=ubuntu-os-cloud \
--no-service-account --no-scopes --project=XXX --zone=us-central-1 \
--network-interface "" --network-interface subnet=.../regions/us-central1/subnetworks/XXX,no-address
I am not getting any errors when executing this script, but when I go to GCP and try to look for metrics for my instance the charts for Memory Utilization and Disk Space Utilization say that the Ops Agent is required and that I should install it. Following the guide, and after verifying that the OS config agent is installed, I follow the steps in "The OS Config agent is installed but does not install the Ops agents". When I do so I get two errors. None of them is addressed in the guide:
Dec 14 15:34:34 bastion OSConfigAgent[600]: 2021-12-14T15:34:34.1627Z OSConfigAgent Error policies.go:49: Error running LookupEffectiveGuestPolicies: error getting token from metadata: metadata: GCE metadata "instance/service-accounts/default/identity?audience=osconfig.googleapis.com&format=full" not defined
Dec 14 15:34:36 bastion OSConfigAgent[600]: 2021-12-14T15:34:36.9551Z OSConfigAgent Error inventory.go:76: Error reporting inventory checksum: error getting token from metadata: metadata: GCE metadata "instance/service-accounts/default/identity?audience=osconfig.googleapis.com&format=full" not defined
How can I fix these errors to effectively install the Ops Agent? Thank you!
The log which you've provided tells little and this could have many reasons.
Make sure that eg. all of
/etc/apt/sources.list.d/
are valid repositories.Also make sure that the metadata is a) set up correctly and b) can be accessed:
This may well have to do with the
--agent-rules
argument, which you're passing.Ever thought about a start-up script, which would simply install the agent?
Also see: Managing Agent Policies - Troubleshooting.