分享方式:


在 Azure 監視器中使用 Log Analytics Linux 代理程式收集自訂 JSON 資料來源

注意

Microsoft Operations Management Suite 正在轉換為 Azure 監視器,而適用於 Windows 或 Linux 的 Operations Management Suite 代理程式屬於此轉換的一部份,之後會將其稱為適用於 Windows 的 Log Analytics 代理程式和適用於 Linux 的 Log Analytics 代理程式。

您可以使用 Log Analytics Linux 代理程式將自訂 JSON 資料來源收集到 Azure 監視器中。 這些自訂資料來源可以是會傳回 JSON 的簡單指令碼,例如 curlFluentD 的 300 個以上的外掛程式之一。 本文說明此資料收集所需的設定。

注意

需要有 Log Analytics Linux 代理程式 v1.1.0-217+ 才能收集自訂 JSON 資料。 此收集流程僅適用於 MMA。 請考慮移至 AMA 代理程式,並使用該處可用的其他集合功能

組態

設定輸入外掛程式

若要在 Azure 監視器中收集 JSON 資料,請將 oms.api. 新增至輸入外掛程式中的 FluentD 標記開頭。

例如,以下是 /etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.d/ 中的個別設定檔 exec-json.conf。 這會使用 FluentD 外掛程式 exec 每隔 30 秒執行一次 curl 命令。 此命令的輸出由 JSON 輸出外掛程式所收集。

<source>
  type exec
  command 'curl localhost/json.output'
  format json
  tag oms.api.httpresponse
  run_interval 30s
</source>

<match oms.api.httpresponse>
  type out_oms_api
  log_level info

  buffer_chunk_limit 5m
  buffer_type file
  buffer_path /var/opt/microsoft/omsagent/<workspace id>/state/out_oms_api_httpresponse*.buffer
  buffer_queue_limit 10
  flush_interval 20s
  retry_limit 10
  retry_wait 30s
</match>

對於在 /etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.d/ 下新增的設定檔,必須使用下列命令變更其擁有權。

sudo chown omsagent:omiusers /etc/opt/microsoft/omsagent/conf/omsagent.d/exec-json.conf

設定輸出外掛程式

將下列輸出外掛程式設定新增至 /etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.conf 中的主要設定,或新增為個別的設定檔再放入 /etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.d/

<match oms.api.**>
  type out_oms_api
  log_level info

  buffer_chunk_limit 5m
  buffer_type file
  buffer_path /var/opt/microsoft/omsagent/<workspace id>/state/out_oms_api*.buffer
  buffer_queue_limit 10
  flush_interval 20s
  retry_limit 10
  retry_wait 30s
</match>

重新啟動 Log Analytics Linux 代理程式

使用下列命令重新啟動 Log Analytics Linux 代理程式服務。

sudo /opt/microsoft/omsagent/bin/service_control restart 

輸出

資料將收集到 Azure 監視器中,記錄類型為 <FLUENTD_TAG>_CL

例如,Azure 監視器中的自訂標籤 tag oms.api.tomcat,記錄類型為 tomcat_CL。 您可以使用下列記錄查詢來擷取此類型的所有記錄。

Type=tomcat_CL

支援巢狀 JSON 資料來源,但編製索引是以父欄位作為基礎。 例如,下列 JSON 資料從記錄查詢傳回為 tag_s : "[{ "a":"1", "b":"2" }]

{
    "tag": [{
      "a":"1",
      "b":"2"
    }]
}

下一步

  • 了解記錄查詢,以分析從資料來源和解決方案收集到的資料。