設定 JMX 計量Configuring JMX metrics

Application insights JAVA 3.0 代理程式預設會收集一些 JMX 計量,但在許多情況下,這並不足夠。Application insights Java 3.0 agent collects some of the JMX metrics by default, but in many cases this is not enough. 本檔說明 JMX 設定選項的詳細資料。This document describes the JMX configuration option in details.

如何? 收集其他 JMX 計量?How do I collect additional JMX metrics?

您可以藉由將區段新增至檔案中的 applicationinsights.js,來設定 JMX 計量集合 "jmxMetrics"JMX metrics collection can be configured by adding a "jmxMetrics" section to the applicationinsights.json file. 您可以在 application insights 資源的 Azure 入口網站中,以您想要的方式指定度量的名稱。You can specify the name of the metric the way you want it to appear in Azure portal in application insights resource. 您必須為每個想要收集的計量定義物件名稱和屬性。You have to define the object name and attribute for each of the metrics you want collected.

如何? 知道有哪些計量可以設定?How do I know what metrics are available to configure?

您可以答對它-您必須知道物件名稱和屬性,這些屬性在不同的程式庫、架構和應用程式伺服器中都是不同的,而且通常不會有詳細的記載。You nailed it - you must know the object names and the attributes, those properties are different for various libraries, frameworks, and application servers, and are often not well documented. 若要取得物件名稱和屬性,您需要查看 MBean 樹狀目錄。To get the object names and attributes, you need to view the MBean tree. MBean 是受管理的 JAVA 物件,可代表裝置、應用程式或資源,而且具有一組屬性。An MBean is a managed Java object, that can represent a device, an application, or a resource, and has a set of attributes.

若要查看可用的計量,並流覽可用的度量,我們建議使用 JAVA 任務控制To view the available metrics and browse through the available metrics, we recommend using Java Mission Control.

如何流覽 JAVA 任務控制項以取得正確的計量?How to navigate the Java Mission Control to get to the right metrics?

當您執行 JAVA 任務控制工具時,您會在左側選擇可用的 Jvm,請按一下 [JVM 瀏覽器] 索引標籤底下的相關進程。等到 JMC 載入處理常式的儀表板,選取底部的 [MBean 瀏覽器] 索引標籤, (見下面) 。When you run the Java Mission Control tool, you'll have a selection of JVMs available on the left side, click on the relevant process under the 'JVM Browser' tab. Wait until JMC loads the dashboard for the process, select 'MBean Browser' tab on the bottom (see below). JMC 必須位於與 JVM 相同的資料夾中,而且您的進程/應用程式必須啟動並執行。The JMC must be located in the same folder as the JVM and your process/app must be up and running.

JMC MBean 瀏覽器的螢幕擷取畫面

如何取得我想要的計量,以及必要的屬性?How to get to the metrics I want, and the necessary attributes?

MBean 瀏覽器會以可展開的類別清單開啟 MBean 樹狀目錄。The MBean browser opens the MBean tree with the list of categories that can be expanded. 選取左側的類別會開啟右側的屬性清單。Selecting a category on the left opens the list of attributes on the right. 以下是度量、其物件名稱和屬性的範例。Below is an example of a metric, its object name, and the attributes. 屬性可能會進行嵌套,如下列範例所示。The attributes may be nested, as in the example below.

JMC MBean 樹狀結構的螢幕擷取畫面

設定範例Configuration example

從上圖中所示的選取專案,讓我們設定一些計量。From the selection as shown in the image above, lets configure a few metrics. 第一個是嵌套計量的範例, LastGcInfo 其中包含數個屬性,而我們想要捕獲 GcThreadCountThe first one is an example of a nested metric - LastGcInfo that has several properties, and we want to capture the GcThreadCount.

"jmxMetrics": [
      {
        "name": "Demo - GC Thread Count",
        "objectName": "java.lang:type=GarbageCollector,name=PS MarkSweep",
        "attribute": "LastGcInfo.GcThreadCount"
      },
      {
        "name": "Demo - GC Collection Count",
        "objectName": "java.lang:type=GarbageCollector,name=PS MarkSweep",
        "attribute": "CollectionCount"
      },
      {
        "name": "Demo - Thread Count",
        "objectName": "java.lang:type=Threading",
        "attribute": "ThreadCount"
      }
],

收集的計量和可用設定選項的類型?Types of collected metrics and available configuration options?

我們支援數值和布林值的 JMX 計量,而其他類型則不受支援,將會予以忽略。We support numeric and boolean JMX metrics, while other types aren't supported and will be ignored.

目前並不支援萬用字元和匯總屬性,因此必須個別設定每個屬性的「物件名稱」/「屬性」配對。Currently, the wildcards and aggregated attributes aren't supported, that's why every attribute 'object name'/'attribute' pair must be configured separately.

哪裡可以找到 application insights 中的 JMX 計量?Where do I find the JMX Metrics in application insights?

當您的應用程式正在執行且已收集 JMX 計量時,您可以移至 Azure 入口網站並流覽至您的 application insights 資源來加以查看。As your application is running and the JMX metrics are collected, you can view them by going to Azure portal and navigate to your application insights resource. 在 [計量] 索引標籤上,選取如下所示的下拉式清單,以查看度量。Under Metrics tab, select the dropdown as shown below to view the metrics.

入口網站中計量的螢幕擷取畫面