如何在 GCP 中监控 VM 服务?

How can I monitor VM services in GCP?

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

Google 提供了 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 如何安装代理的指南。

假设您使用的是 Ubuntu-based 发行版并且 SQL 服务是 MySQL 也许 this 指南可能更相关。本质上你需要做的是:

  1. 添加监控代理程序包存储库:

    curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
    sudo bash add-monitoring-agent-repo.sh
    sudo apt-get update
    
  2. 安装监控代理:

    sudo apt-get install stackdriver-agent
    
  3. 开始吧:

    sudo service stackdriver-agent start
    
  4. 安装MySQL监控:

    sudo apt-get install libmysqlclient20
    
  5. 下载 mysql.conf 并将其放在监控代理运行的目录 /opt/stackdriver/collectd/etc/collectd.d/ 中:

    (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. 编辑配置文件并将DATABASE_NAME替换为 您要监视的数据库的名称以及任何其他变量 这可能适用于您的数据库。

  7. 重新启动监控代理:

    sudo service stackdriver-agent restart
    

完成后,以 Resource Type: 的身份转到 Cloud Monitoring page、select VM 实例并向下滚动,直到看到 Agent Metrics 以查看由监控代理。

您也可以选择安装 Cloud Logging agent which will ingest logs from the application. You'd install 它:

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

请记住,一旦您超过了特定的数据存储阈值,就会将某些 pricing 应用到 Cloud Logging,因此如果您不想意外产生费用,请记住这一点。最后,如果您确实使用 Ubuntu 发行版和 MySQL,则这些步骤适用,如果不是,请检查链接并 select 相应地满足您的配置的选项。