'GCP Compute Engine won't show memory metrics

I want my compute engine VM to show memory usage metrics in the console, I went to this page and install Ops-Agents, restart the service and went to the VM observability section, but still saw a message that the agent is not installed (in the memory usage metric): enter image description here I thought maybe by default the memory usage is not installed (it's not mentioned anywhere, just a guess) and I need to modify the config. I went to this docs and added this code to /etc/google-cloud-ops-agent/config.yaml:

metrics:
  receivers:
    agent.googleapis.com/memory/bytes_used:
      type: hostmetrics
      collection_interval: 1m

According to the docs, this config will be merged with the built-in configuration when the agent restarts. I restarted the agent service, went back to the dashboard but still it shows the message "Requires Ops Agent". I don't know what I'm doing wrong, the documentations are really poor for that topic IMO, I couldn't find any example on how to turn on memory usage metrics.

EDIT Running sudo systemctl status google-cloud-ops-agent"*" I can see this error message:

otelopscol[2763]: 2022-05-02T14:07:02.780Z#011error#[email protected]/metrics.go:235#011could not export time series to GCM#011{"error": "rpc error: code = InvalidArgument desc = Name must begin with '{resource_container_type}/{resource_container_id}', got: projects/"}

EDIT2 If I click INSTALL via the console, I see this installation instructions:

:> agents_to_install.csv && \
echo '"projects/<project>/zones/europe-west1-b/instances/<instance>","[{""type"":""ops-agent""}]"' >> agents_to_install.csv && \
curl -sSO https://dl.google.com/cloudagents/mass-provision-google-cloud-ops-agents.py && \
python3 mass-provision-google-cloud-ops-agents.py --file agents_to_install.csv

It's differente from the one here: https://cloud.google.com/monitoring/agent/monitoring/installation#joint-install

curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
sudo bash add-monitoring-agent-repo.sh --also-install

Not sure what installed what, tried both.



Solution 1:[1]

Regarding your questions “I couldn't find any example on how to turn on memory usage metrics” and “Is it installed but the configurations need to be modified for the memory usage metrics?” the answer is yes, you need to customize which group or groups of metrics to enable as specified here. The metric type strings must be prefixed with agent.googleapis.com/agent/. For memory metrics, the examples are:

agent.googleapis.com/agent/memory_usage

agent.googleapis.com/agent/memory_utilization

That prefix has been omitted from the entries in the table that I’m sharing here.

Now, you need to select the setting based on the target VM that you need to get metrics from, for example, Linux only:

agent.googleapis.com/memory/usage

Also, you can play with other options, changing the final criteria, for example:

agent.googleapis.com/memory/bytes_used

Ensure that you didn’t miss anything regarding the agent’s installation, follow these instructions to install it from the CLI. Then go to:

  • Resources -> Instances: You should see your VM instance.

  • Click on your instance -> click on Agent -> Scroll down and you see your memory and your swap usage.

Finally, you can follow this troubleshooting guide for Ops Agent issues, and these threads for more empirical cases and solutions Memory Usage Monitoring in GCP Compute Engine and No metric found.

Solution 2:[2]

Have you tried running it in Cloud Shell with the contents of Edit2? It didn't work when I ran the Docs below as I was also attached to SSH with IAP. It worked when I ran it in Cloud Shell.

https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/installation#install-latest-version

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nestor Daniel Ortega Perez
Solution 2 MaSeungWoo