apigeectl diagnostic 指令叫用診斷收集器。系統會擷取哪些系統資料?
診斷資訊收集器會擷取下列類型的資料:
- 變更記錄層級。
- Jstack。
- POD 設定 YAML。
- PS -ef 輸出內容。
- TCP 傾印。
- TOP 輸出內容。
資料會受到什麼影響?
診斷資訊收集器擷取資料後,會上傳至 Google Cloud 專案中的儲存空間 bucket。您可以在 Google Cloud Platform:Cloud Storage 瀏覽器中查看儲存的資料。
建立支援單時,您可以選擇是否要與 Google Apigee 支援團隊分享這項資料。
執行診斷收集器的必要條件
使用診斷資訊收集器前,請先完成下列必要條件:
Google Cloud Storage bucket
在 Google Cloud 專案中建立 Google Cloud Storage bucket,並給予不重複的名稱。您可以使用 gcloud storage 指令或 Google Cloud Platform:Cloud Storage 瀏覽器,建立及管理值區。
例如:
gcloud storage buckets create gs://apigee_diagnostic_data
Creating gs://apigee_diagnostic_data/...
如需操作說明,請參閱「建立儲存空間值區」。
服務帳戶
在專案中建立具有儲存空間管理員角色 (roles/storage.admin) 的服務帳戶,並下載服務帳戶 .json 金鑰檔案。
服務帳戶可使用任何不重複的名稱。本指南使用「apigee-diagnostic」做為服務帳戶名稱。
例如:
gcloud config set project ${PROJECT_ID}gcloud iam service-accounts create apigee-diagnostic
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member="serviceAccount:apigee-diagnostic@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/storage.admin"gcloud iam service-accounts keys create ${PROJECT_ID}-apigee-diagnostic.json \
--iam-account=apigee-diagnostic@${PROJECT_ID}.iam.gserviceaccount.com請參閱:
使用診斷收集器
使用診斷收集器的順序如下:
- 在
overrides.yaml檔案中設定 Diagnostic 節,選取資訊類型、Apigee 容器,以及要從中取得診斷資料的個別 Pod。請參閱「為診斷收集器設定overrides.yaml」。 - 使用下列
apigeectl指令執行診斷收集器。apigeectl diagnostic -f OVERRIDES_FILE
其中 OVERRIDES_FILE 是
overrides.yaml檔案的路徑。 - 檢查記錄:
- 取得
apigee-diagnostic命名空間中的 Pod。kubectl get pods -n apigee-diagnostic
- 記下名稱包含
diagnostic-collector的 Pod - 使用下列指令檢查記錄:
kubectl -n apigee-diagnostic logs -f POD_NAME
其中 POD_NAME 是診斷收集器 Pod 的名稱。
您也可以在 Google Cloud Platform 的 Cloud Storage 瀏覽器中查看收集到的記錄。
- 取得
- 收集完資料後,請刪除診斷收集器。您必須先刪除,才能再次執行。
apigeectl diagnostic delete -f OVERRIDES_FILE
設定診斷收集器的 overrides.yaml
您必須先在 overrides.yaml 檔案中設定診斷收集器,才能執行該工具。
如需 diagnostic 設定屬性的完整參考資料,請參閱設定屬性參考資料:diagnostic。
必要屬性
診斷收集器必須具備下列屬性才能執行。
diagnostic.serviceAccountPath:服務帳戶金鑰檔案的路徑,該服務帳戶在必要條件中具有 Storage Admin 角色。diagnostic.operation:指定要收集所有統計資料,還是只收集記錄。值為:
"ALL"或"LOGGING"如果將
diagnostic.operation設為"LOGGING",則必須使用以下屬性:diagnostic.bucket:Google Cloud Storage 值區的名稱,診斷資料會存放在這個值區。這是您在必要條件中建立的值區。diagnostic.container:指定要從哪個類型的 Pod 擷取資料。可能的值如下:container值Apigee 元件 Kubernetes 命名空間 這個容器中的 Pod 名稱範例 apigee-cassandraCassandra apigeeapigee-cassandra-default-0istio-proxyIstio Ingress istio-systemistio-ingressgateway-696879cdf8-9zzzfapigee-mart-serverMART apigeeapigee-mart-hybrid-example-d89fed1-151-jj2ux-l7nlbapigee-runtime訊息處理器 apigeeapigee-runtime-hybrid-example-3b2ebf3-151-s64bh-g9qmvapigee-synchronizer同步處理工具 apigeeapigee-synchronizer-hybrid-example-3b2ebf3-151-xx4z6cg78apigee-udcaUDCA apigeeapigee-udca-hybrid-example-3b2ebf3-151-q4g2c-vnzg9apigee-watcherWatcher apigeeapigee-watcher-hybrid-example-d89fed1-151-cpu3s-sxxdfdiagnostic.namespace:您要收集資料的 Pod 所在的 Kubernetes 命名空間。命名空間必須與您透過diagnostic.container指定的容器相符。diagnostic.podNames:要收集診斷資料的個別 Pod 名稱。例如:diagnostic: … podNames: - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-2wcjn - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-6xzn2
只有在作業設為 LOGGING 時才需要的屬性
只有在搭配 diagnostic.operation 執行診斷收集器時,才需要下列屬性。LOGGING
diagnostic.loggerNames:依名稱指定要從哪些記錄器收集資料。如果是 Apigee Hybrid 1.6.0 版,唯一支援的值是ALL,也就是所有記錄器。例如:diagnostic: … loggingDetails: loggerNames: - ALL
diagnostic.logLevel:指定要收集的記錄資料精細程度。 在 Apigee Hybrid 1.6 中,系統僅支援FINE。diagnostic.logDuration:收集記錄資料的時間長度 (以毫秒為單位)。一般值為30000。
選用屬性
以下屬性為選用項目。
diagnostic.tcpDumpDetails.maxMsgs:設定要收集的tcpDump訊息數量上限。Apigee 建議最大值不超過1000。diagnostic.tcpDumpDetails.timeoutInSeconds:設定等待tcpDump傳回訊息的時間長度 (以秒為單位)。diagnostic.threadDumpDetails.delayInSeconds:收集每個執行緒傾印之間的延遲時間 (以秒為單位)。必須搭配diagnostic.threadDumpDetails.iterations使用。diagnostic.threadDumpDetails.iterations:要收集的 jstack 執行緒傾印疊代次數。必須搭配diagnostic.threadDumpDetails.delayInSeconds使用。
一般範例
以下是 diagnostic 節的範例,顯示所有可能的項目:
diagnostic: # required properties: serviceAccountPath: "service-accounts/apigee-diagnostics.json" operation: "ALL" bucket: "diagnostics_data" container: "apigee-runtime" namespace: "apigee" podNames: - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-2wcjn - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-6xzn2 # required if operation is Logging loggingDetails: loggerNames: - ALL logLevel: FINE logDuration: 30000 # optional properties: tcpDumpDetails: maxMsgs: 10 timeoutInSeconds: 100 threadDumpDetails: iterations: 5 delayInSeconds: 2
常見用途
以下範例說明如何在常見情況下設定及使用診斷收集器。
Proxy 延遲時間過長
在本例中,Apigee-runtime 處理要求的時間過長,導致客戶看到高代理伺服器延遲。您需要收集 Jstack 和 TOP 輸出內容。
- 選取任意 2 個執行階段 Pod。
- 請使用下列結構建立
diagnostic節:diagnostic: serviceAccountPath: "service-accounts/apigee-diagnostics.json" operation: "ALL" bucket: "diagnostics_data" container: "apigee-runtime" namespace: "apigee" podNames: - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-2wcjn - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-6xzn2 tcpDumpDetails: maxMsgs: 10 threadDumpDetails: iterations: 15 delayInSeconds: 1
- 設定
diagnostic節後,執行診斷收集器。apigeectl diagnostic -f OVERRIDES_FILE
- 收集記錄檔,然後刪除診斷收集器。
apigeectl diagnostic delete -f OVERRIDES_FILE
網路 / 連線問題
您需要對 apigee-runtime 和 Ingress 閘道 Pod 執行診斷。
- 選取任意 2 個執行階段 Pod。
- 請使用下列結構建立
diagnostic節:diagnostic: serviceAccountPath: "service-accounts/apigee-diagnostics.json" operation: "ALL" bucket: "diagnostics_data" container: "apigee-runtime" namespace: "apigee" podNames: - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-2wcjn - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-6xzn2 tcpDumpDetails: maxMsgs: 1000
- 設定
diagnostic節後,執行診斷收集器。apigeectl diagnostic -f OVERRIDES_FILE
- 收集記錄檔,然後刪除診斷收集器。
apigeectl diagnostic delete -f OVERRIDES_FILE
- 從 Istio Ingress 閘道選取兩個 Pod。
- 使用 Istio Ingress Pod 重新設定
diagnostic節:diagnostic: serviceAccountPath: "service-accounts/apigee-diagnostics.json" operation: "ALL" bucket: "diagnostics_data" container: "istio-proxy" namespace: "istio-system" podNames: - istio-ingressgateway-696879cdf8-9zzzf - istio-ingressgateway-696879cdf8-6abc7 tcpDumpDetails: maxMsgs: 1000
- 設定
diagnostic節後,執行診斷收集器。apigeectl diagnostic -f OVERRIDES_FILE
- 收集記錄檔,然後刪除診斷收集器。
apigeectl diagnostic delete -f OVERRIDES_FILE
Proxy 發生非預期錯誤,或未套用新合約
在這種情況下,您需要將記錄層級變更為偵錯,至少 5 分鐘,甚至 10 分鐘 (如本範例所示)。這會增加記錄量,但記錄的資訊會很有幫助。 您將執行兩次診斷收集器,一次在 Apigee 執行階段,另一次在 Apigee 同步器。
- 選取任意 2 個執行階段 Pod。
- 請使用下列結構建立
diagnostic節:diagnostic: serviceAccountPath: "service-accounts/apigee-diagnostics.json" operation: "LOGGING" bucket: "diagnostics_data" namespace: "apigee" container: "apigee-runtime" podNames: - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-2wcjn - apigee-runtime-hybrid-example-3b2ebf3-150-8vfoj-6xzn2 loggingDetails: loggerNames: - ALL logLevel: FINE logDuration: 60000
- 設定
diagnostic節後,執行診斷收集器。apigeectl diagnostic -f OVERRIDES_FILE
- 收集記錄檔,然後刪除診斷收集器。
apigeectl diagnostic delete -f OVERRIDES_FILE
- 選取任意 2 個同步器 Pod。
- 請使用下列結構建立
diagnostic節:diagnostic: serviceAccountPath: "service-accounts/apigee-diagnostics.json" operation: "LOGGING" bucket: "diagnostics_data" namespace: "apigee" container: "apigee-synchronizer" podNames: - apigee-synchronizer-hybrid-example-3b2ebf3-150-xx4z-6cg78 - apigee-synchronizer-hybrid-example-3b2ebf3-150-xx4z-1a2b3 loggingDetails: loggerNames: - ALL logLevel: FINE logDuration: 60000
- 設定
diagnostic節後,執行診斷收集器。apigeectl diagnostic -f OVERRIDES_FILE
- 收集記錄檔,然後刪除診斷收集器。
apigeectl diagnostic delete -f OVERRIDES_FILE