简体   繁体   中英

How can I monitor VM services in GCP?

我有一个包含 SQL 服务的 VM 实例,我想监视这个 SQL 服务,我该怎么做?

Google provides a Cloud Monitoring agent that can be used in Compute Engine to collect more detailed metrics from the Compute Engine instance itself and third-party applications it might contain, displaying this information at the Cloud Monitoring page. Here's a list of the applications it can gather the metrics from. Here's a guide on how to install the agent.

Assuming you're using an Ubuntu-based distro and the SQL service is MySQL perhaps this guide may be more relevant. In essence what you'd have to do is:

  1. Add the Monitoring agent's package repository:

     curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh sudo bash add-monitoring-agent-repo.sh sudo apt-get update
  2. Install the Monitoring agent:

     sudo apt-get install stackdriver-agent
  3. Start it:

     sudo service stackdriver-agent start
  4. Install MySQL monitoring:

     sudo apt-get install libmysqlclient20
  5. Download mysql.conf and place it in the directory /opt/stackdriver/collectd/etc/collectd.d/ which is where the Monitoring agent operates on:

     (cd /opt/stackdriver/collectd/etc/collectd.d/ && sudo curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/mysql.conf)
  6. Edit the configuration file and replace DATABASE_NAME with the name of the database you want to monitor, and any other variables that might apply to your database.

  7. Restart the Monitoring agent:

     sudo service stackdriver-agent restart

Once that's done, go to the Cloud Monitoring page , select the VM instance as Resource Type: and scroll down until you see Agent Metrics to view the metrics collected by the Monitoring agent.

Optionally you can also install a Cloud Logging agent which will ingest logs from the application. You'd install it with:

curl -sSO https://dl.google.com/cloudagents/add-logging-agent-repo.sh
sudo bash add-logging-agent-repo.sh
sudo apt-get update

sudo apt-get install -y google-fluentd-catch-all-config-structured

sudo service google-fluentd start

Keep in mind a certain pricing is applied to Cloud Logging once you pass a specific threshold of data storage so that's something to keep in mind if you don't want to accidentally incurr costs. Lastly and again, these steps are applicable if you're indeed using an Ubuntu distro and MySQL, if not, check the links and select the options that meet your configuration accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM