[GCP] 在 Google Cloud Platform 上,啟用 Stackdriver 監控程式,記錄記憶體與磁碟使用率
平常在 Google Cloud Platform 上的 WordPress 機器,
可以直接看到 CPU 使用率和網路流量,
但是記憶體和磁碟空間的使用量,就沒辦法看到…
不過這問題也不難解決,
在 GCP 的畫面上,按下 INSTALL 鈕:
這時會跳出一個說明視窗,會給你一行用來在虛擬機器中,
安裝監控工具 stackdriver-agent 的命令列,例如:
gcloud beta compute ssh wordpress-multisite-1-vm --project=my-project --zone=us-west1-a --command="curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh && sudo bash add-monitoring-agent-repo.sh --also-install && sudo service stackdriver-agent start"
也可以直接按「安裝代理程式」鈕:
下方會直接出現 Cloud Shell 並自動執行那行命令列,
按下「授權」讓它開始執行:
這時代理程式就會開始安裝,畫面上也會出現提示,
說要等待一兩分鐘…
理想狀況下,一兩分鐘後,畫面上應該就要開始出現記憶體的使用量。
但不幸的,我的機器並未如此…
連到那台虛擬機器後,看一下 stackdriver-agent 這個服務的狀態,
發現它是 active (exited),表示啟動後又停下來了:
testuser@wordpress-multisite-1-vm:~$ sudo service stackdriver-agent status ● stackdriver-agent.service - LSB: start and stop Stackdriver Agent Loaded: loaded (/etc/init.d/stackdriver-agent; generated) Active: active (exited) since Sun 2021-09-05 13:59:27 UTC; 34min ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 4915) Memory: 0B CGroup: /system.slice/stackdriver-agent.service Sep 05 13:59:27 wordpress-multisite-1-vm systemd[1]: Starting LSB: start and stop Stackdriver Agent... Sep 05 13:59:27 wordpress-multisite-1-vm stackdriver-agent[4292]: Starting Stackdriver metrics collection agent: stackdriver-agentdisabled via metadata ... (warning). Sep 05 13:59:27 wordpress-multisite-1-vm stackdriver-agent[4292]: (warning). Sep 05 13:59:27 wordpress-multisite-1-vm systemd[1]: Started LSB: start and stop Stackdriver Agent.
查了一下,原來因為我的虛擬機器是從 Google Cloud Marketplace 部署的,
在中繼資料這邊, google-monitoring-enable
這個值預設被停用 (設為 0)…
解決方法是按 X 刪除掉這個資料、或是將值設為 1 也可以:
處理好中繼資料之後,重新啟動 stackdriver-agent 服務,
再檢查一次,發現服務已經正常啟動了,狀態是 active (running):
testuser@wordpress-multisite-1-vm:~$ sudo service stackdriver-agent restart testuser@wordpress-multisite-1-vm:~$ sudo service stackdriver-agent status ● stackdriver-agent.service - LSB: start and stop Stackdriver Agent Loaded: loaded (/etc/init.d/stackdriver-agent; generated) Active: active (running) since Sun 2021-09-05 14:37:25 UTC; 2s ago Docs: man:systemd-sysv-generator(8) Process: 6410 ExecStart=/etc/init.d/stackdriver-agent start (code=exited, status=0/SUCCESS) Tasks: 14 (limit: 4915) Memory: 13.5M CGroup: /system.slice/stackdriver-agent.service ├─6432 /opt/stackdriver/collectd/sbin/stackdriver-collectdmon -P /var/run/stackdriver-agent.pid -c /opt/stackdriver/collectd/sbin/stackdriver-collectd -- -C /etc/stackdriver └─6433 /opt/stackdriver/collectd/sbin/stackdriver-collectd -C /etc/stackdriver/collectd.conf -f Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: plugin_load: plugin "write_gcm" successfully loaded. Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: plugin_load: plugin "match_regex" successfully loaded. Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: plugin_load: plugin "match_throttle_metadata_keys" successfully loaded. Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: plugin_load: plugin "stackdriver_agent" successfully loaded. Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: plugin_load: plugin "exec" successfully loaded. Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: plugin_load: plugin "aggregation" successfully loaded. Sep 05 14:37:25 wordpress-multisite-1-vm collectd[6433]: Initialization complete, entering read-loop. Sep 05 14:37:26 wordpress-multisite-1-vm collectd[6433]: uc_update: Value too old: name = wordpress-multisite-1-vm/processes-all/ps_rss; value time = 1630852646.021; last cache update Sep 05 14:37:26 wordpress-multisite-1-vm collectd[6433]: uc_update: Value too old: name = wordpress-multisite-1-vm/processes-all/ps_rss; value time = 1630852646.021; last cache update Sep 05 14:37:26 wordpress-multisite-1-vm collectd[6433]: tcpconns plugin: Reading from netlink succeeded. Will use the netlink method from now on.
再回到 GCP 畫面上看,果然開始出現記憶體與磁碟用量的資料囉:
參考資料:Troubleshooting Agent Installation
(本頁面已被瀏覽過 1,085 次)