Google Cloud Platform: how to monitor memory usage of VM instances

前端 未结 5 674
挽巷
挽巷 2020-12-10 00:47

I have recently performed a migration to Google Cloud Platform, and I really like it.

However I can\'t find a way to monitor the memory usage of the VM intances. As

相关标签:
5条回答
  • 2020-12-10 01:00

    The agent metrics page may be useful: https://cloud.google.com/monitoring/api/metrics_agent

    You'll need to install stackdriver. See: https://app.google.stackdriver.com/?project="your project name"

    The stackdriver metrics page will provide some guidance. You will need to change the "project name" (e.g. sinuous-dog-133823) to suit your account:

    https://app.google.stackdriver.com/metrics-explorer?project=sinuous-dog-133823&timeSelection={"timeRange":"6h"}&xyChart={"dataSets":[{"timeSeriesFilter":{"filter":"metric.type=\"agent.googleapis.com/memory/bytes_used\" resource.type=\"gce_instance\"","perSeriesAligner":"ALIGN_MEAN","crossSeriesReducer":"REDUCE_NONE","secondaryCrossSeriesReducer":"REDUCE_NONE","minAlignmentPeriod":"60s","groupByFields":[],"unitOverride":"By"},"targetAxis":"Y1","plotType":"LINE"}],"options":{"mode":"COLOR"},"constantLines":[],"timeshiftDuration":"0s","y1Axis":{"label":"y1Axis","scale":"LINEAR"}}&isAutoRefresh=true

    This REST call will get you the cpu usage. You will need to modify the parameters to suite your project name (e.g. sinuous-dog-133823) and other params to suit needs.

    GET /v3/projects/sinuous-cat-233823/timeSeries?filter=metric.type="agent.googleapis.com/memory/bytes_used" resource.type="gce_instance"& aggregation.crossSeriesReducer=REDUCE_NONE& aggregation.alignmentPeriod=+60s& aggregation.perSeriesAligner=ALIGN_MEAN& secondaryAggregation.crossSeriesReducer=REDUCE_NONE& interval.startTime=2019-03-06T20:40:00Z& interval.endTime=2019-03-07T02:51:00Z& $unique=gc673 HTTP/1.1
    Host: content-monitoring.googleapis.com
    authorization: Bearer <your token>
    cache-control: no-cache
    Postman-Token: 039cabab-356e-4ee4-99c4-d9f4685a7bb2
    
    0 讨论(0)
  • 2020-12-10 01:01

    Well you can use the /proc/meminfo virtual file system to get information on current memory usage. You can create a simple bash script that reads the memory usage information from /proc/meminfo. The script can be run periodically as a cron job service. The script can send an alert email if the memory usage exceeds a given threshold.

    See this link: https://pakjiddat.netlify.app/posts/monitoring-cpu-and-memory-usage-on-linux

    0 讨论(0)
  • 2020-12-10 01:02

    By installing the Stackdriver agent in GCE VMs additional metrics like memory can be monitored. Stackdriver also offers you alerting and notification features. Nevertheless agent metrics are only available for premium tier accounts.

    0 讨论(0)
  • 2020-12-10 01:08

    The stackdriver agent only supports monitoring of RAM of the E2 family at the moment. Other instance types such as N1, N2,... are not supported.

    See the latest documentation of what is supported; https://cloud.google.com/monitoring/api/metrics_gcp#gcp-compute

    0 讨论(0)
  • 2020-12-10 01:09

    The most up-to-date answer here.

    How to see memory usage in GCP?

    1. Install the agent on your virtual machine. Takes less than 5 minutes.
    curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
    sudo bash add-monitoring-agent-repo.sh
    sudo apt-get update
    sudo apt-get install stackdriver-agent
    

    the code snippet should install the most recent version of the agent, but for up-to-date guide you can always refer to https://cloud.google.com/monitoring/agent/installation#joint-install.

    1. After it's installed, in a minute or two, you should see the additional metrics in Monitoring section of GCP. https://console.cloud.google.com/monitoring

    Explanation and why it's invisible by default?

    The metrics (such as CPU usage or memory usage) can be collected at different places. For instance, CPU usage is a piece of information that the host (machine with special software running your virtual machine) can collect. The thing with memory usage and virtual machines, is, it's the underlying operating system that manages it (the operating system of your virtual machine). Host cannot really know how much is used, for all it can see in the memory given to that virtual machine, is a stream of bytes.

    That's why there's an idea to install agents inside of that virtual machine that would collect the metrics from inside and ship it somewhere where they can be interpreted. There are many types of agents available out there, but Google promotes their own - Monitoring Agent - and it integrates into the entire GCP suite well.

    0 讨论(0)
提交回复
热议问题