スクリプトを使用したモニタリング拡張機能の作成
モニタリング拡張スクリプト(別名、カスタムモニターまたはハードウェアモニター)を作成して、Splunk AppDynamics がすでに収集してコントローラにレポートしているメトリックセットにカスタムメトリックを追加できます。スクリプトは、1 分ごとにカスタムメトリックをマシンエージェントに報告します。マシンエージェントは、これらのメトリックをコントローラに渡します。
このページでは、シェルスクリプトを使用してカスタムメトリックを追加する手順について説明します。この手順には例が含まれます。
既存の拡張機能の確認
独自の拡張機能を作成する前に、作成され、Splunk AppDynamics コミュニティのメンバー間で共有されている拡張機能を確認してください。新しい拡張機能が継続的に追加されています。他のユーザが必要なもの、または必要なものに近いものをすでに作成している可能性があります。必要なものに近いものをダウンロードし、変更をいくつか加えれば使用できる場合があります。
無料ダウンロードについては、製品ページを参照してください。
エージェントの設定要件
controller-info.xml でマシンエージェントが正しく設定されていることを確認し、マシンエージェントの設定プロパティを起動します。
モニタリング拡張機能の作成
スクリプトを使用してモニタリング拡張機能を作成するには、次のようにします。
- スクリプトを作成します。「スクリプトファイルの作成」を参照してください。
monitor.xml構成ファイルを作成します。「monitor.xml ファイルの作成」を参照してください<machine_agent_home>/monitorsにサブディレクトリ(<your_extension_dir>)を作成します。「マシンエージェントのモニターディレクトリの下にディレクトリを作成する」を参照してください。- スクリプトファイルと monitor.xml をコピーします。
- マシンエージェントを再起動します。
メトリックの定義
メトリック名は、同じメトリックパス内で一意である必要がありますが、メトリック階層全体に対して一意である必要はありません。メトリックブラウザに表示されるときに名前全体が表示されるように、短いメトリック名を使用することを推奨します。メトリックをコントローラにアップロードするときにメトリック名の前にメトリックパスを付加します。
メトリック処理修飾子
コントローラには、メトリックの処理方法(集約、時間ロールアップ、および階層ロールアップ)を示すさまざまな修飾子があります。メトリック修飾子には、次の 3 つのタイプがあります。
- アグリゲータ修飾子
- 時間ロールアップ修飾子
- クラスタロールアップ修飾子
スクリプトで、メトリックの名前と値のペアの後にメトリック修飾子を指定します。スクリプトファイル内の一般的なメトリックエントリは、次のような構造です。
name=<metric name>,value=<long value>,aggregator=<aggregator type>, time-rollup=<time-rollup strategy>, cluster-rollup=<cluster-rollup strategy>
アグリゲータ修飾子
集約修飾子では、1 分間にレポートされた値をマシンエージェントでどのように集約するかを指定します。集約修飾子は、aggregator="aggregator type" として指定します。この値は列挙型です。その 1 分の間に値がレポートされない場合、コントローラにはデータはレポートされず、そのメトリックについてマシンエージェントログに UNCHANGED 通知が表示されます。有効な値は次のとおりです。
| アグリゲータタイプ | 説明 |
|---|---|
|
AVERAGE |
(デフォルト)その 1 分にレポートされたすべての値の平均 |
|
SUM |
その 1 分にレポートされたすべての値の合計。これにより、メトリックはカウンタと同様に動作します |
|
OBSERVATION |
その 1 分にレポートされた最後の値 |
時間ロールアップ修飾子
時間ロールアップ修飾子では、時間が経過して 1 分単位のテーブルから 10 分単位のテーブル、および 60 分単位のテーブルに変換するときに、コントローラで値をどのようにロールアップするかを指定します。値は列挙型です。有効な値は次のとおりです。
| ロールアップ戦略 | 説明 |
|---|---|
|
AVERAGE |
1 分間のすべての値の平均(10 分単位のテーブルに追加する場合)。または 10 分間のすべての値の平均(60 分単位のテーブルに追加する場合) |
|
SUM |
1 分間のすべての値の合計(10 分単位のテーブルに追加する場合)。または 10 分間のすべての値の合計(60 分単位のテーブルに追加する場合) |
|
CURRENT |
その 10 分間隔で最後にレポートされた 1 分間の値。またはその 60 分間隔で最後にレポートされた 10 分間の値 |
クラスタロールアップ修飾子
クラスタロールアップ修飾子では、コントローラで階層(ノードのクラスタ)内のメトリック値をどのように集約するかを指定します。値は列挙型です。有効な値は次のとおりです。
| ロールアップ戦略 | 説明 |
|---|---|
|
個人 |
階層内の各ノードでのメトリック値を平均して、メトリック値を集計します |
|
COLLECTIVE |
階層内のすべてのノードのメトリック値を合計して、メトリック値を集計します |
たとえば、階層に 2 つのノード、ノード A とノード B があり、ノード A に 1 分あたり 3 個のエラーがあり、ノード B に 1 分あたり 7 個のエラーがある場合、INDIVIDUAL 修飾子では 1 分あたり 5 個のエラーが値としてレポートされ、COLLECTIVE 修飾子では 1 分あたり 10 個のエラーがレポートされます。INDIVIDUAL は、各ノードの値が必要な CPU 使用率(% CPU Busy)などのメトリックに適しています。COLLECTIVE は、階層全体の値が必要なコール数(Number of Calls)などのメトリックに適しています。
Add a Monitoring Extension Script
To add a monitoring extension script:
- 1 Create a Subdirectory Under the Machine Agent Monitors Directory
- 2 Create the Script File
- 3 Copy the Script File to the Subdirectory Created in Step 1
- 4 Create the monitor.xml File
- 5 Copy the monitor.xml file to the Subdirectory Created in Step 1
- 6 Restart the Machine Agent
- 7 Verify Execution of the Monitoring Extension Script
Create a Subdirectory Under the Machine Agent Monitors Directory
The <machine_agent_home>/monitors directory is the repository for the Machine Agent extensions. For each new extension, create a subdirectory under the /monitors directory. The user running the Agent requires read, write, and execute permissions to this subdirectory.
For example to create an extension that monitors open files in the JVM, create a subdirectory named "openfiles" under <machine_agent_home>/monitors. The structure looks like:
Create the Script File
A script writes data to STDOUT. The Machine Agent parses STDOUT and sends information to the Controller every minute. Use these instructions to create the script file:
For Windows custom metrics, PowerShell and VBScript are recommended over .bat files
To generate custom metrics on Windows, we recommend that you use PowerShell and VBasic scripts instead of .bat files. When a standard Windows batch (.bat) script echoes metric names, it surrounds the names with quotes. The quotes will cause the Machine Agent to ignore these metrics. PowerShell and VBasic scripts do not have this issue.
-
Specify a
name-valuepair for the metrics.Each metric has aname-valuepair that is converted to a java'long'value. A typical metric entry in the script file has this structure:name=<metric name>,value=<long value>,aggregator=<aggregator type>, time-rollup=<time-rollup strategy>, cluster-rollup=<cluster-rollup strategy>
Form Format Standard Form
Hardware Resources| Instrument Name=Instrument Value
Fully Qualified Form
Hardware Resources| <metric name>,value=<long value>
-
Define the category of the metric, for example:
-
Infrastructure (for the default hardware metrics, see Machine Agent)
-
JVM
-
Custom Metrics, where Custom Metrics must have the path prefixes:
- Custom Metrics
- Server|Component:<tier-name-or-tier-id>
-
-
Metrics with the Custom Metrics prefix are common across all tiers in your application. Metrics with the Server|Component:<tier-name-or-tier-id> prefix appear only under the specified tier.
To find the component ID of a tier, open the dashboard for the tier and review the URL. The ID appears as the component value in the URL:
Warning: The Machine Agent has to be associated with the target or destination for the metrics. If you attempt to publish metrics to a tier that is not associated with the Machine Agent, the metrics are not reported.The "|" character separates the branches in the metric hierarchy notifying the Controller where the metric should appear in the metric tree:
Custom Metrics|Hardware Resources|Disks|Total Disk Usage % Custom Metrics|Hardware Resources|Disks|Disk 1|Current Disk Usage %
You can insert a custom metric next to an existing type of metric. For example, the following declaration causes the custom metric named
pool usageto appear next to theJMXmetrics:Server|Component:18|JMX|Pool|First|pool usage -
You can then use the metric in health rules as would other types of JMX metrics.To monitor multiple metrics with the same script file, edit the script to write a different line for each one to STDOUT. For example:
name=Custom Metrics|Hardware Resources|Disks|Total Disk Usage %, value=23 name=Custom Metrics|Hardware Resources|Disks|Disk 1|Current Disk Usage %, value=56
Copy the Script File to the Subdirectory Created in Step 1
Ensure that the Agent process has execute permissions for the script file and for the contents of the file.
Create the monitor.xml File
For each custom monitoring extension script, create a monitor.xml file. The monitor.xml file executes the script file created in Step 2. You can edit the following sample file to create your own file:
<monitor> <name>HardwareMonitor</name> <type>managed</type> <description>Monitors system resources - CPU, Memory, Network I/O, and Disk I/O.</description> <monitor-configuration> </monitor-configuration> <monitor-run-task> <!-- Edit execution-style as needed. --> <execution-style>continuous</execution-style> <name>Run</name> <type>executable</type> <task-arguments></task-arguments> <executable-task> <type>file</type> <!-- Use only one file element per os-type. --> <file os-type="linux">linux-stat.sh</file> <file os-type="mac">macos-stat.sh</file> <file os-type="windows">windows-stat.bat</file> <file os-type="solaris">solaris-stat.sh</file> <file os-type="sunos">solaris-stat.sh</file> <file os-type="aix">aix-stat.sh</file> </executable-task> </monitor-run-task> </monitor>
The os-type attribute is optional for the executable-task file element when only one os-type is specified. One monitor.xml file executes one script per os-type.
-
Select the execution style:
continuousorperiodic.Execution Style Description Example continuous
Select
continuousif you want data collection averaged over time. For example, average CPU usage over a minute.For the monitor to be declared as 'continuous', the script should also run in an infinite loop. This ensures that the script keeps running until the Machine Agent process is terminated.while [ 1 ]; do... the actual script goes here ...sleep 60doneperiodic
Select
periodicto report data from system performance counters periodically. The periodic task runs every minute by default, and the data is aggregated.To specify a different frequency, use the
execution-frequency-in-secondselement. The execution frequency must be less than 60. For periodic execution style, you can also specify the timeout setting (shown in the example).<monitor-run-task>
...
<execution-style>periodic</execution-style> <execution-frequency-in-seconds>30</execution-frequency-in-seconds> <execution-timeout-in-secs>30</execution-timeout-in-secs>
...
</monitor-run-task>
Note: Do not set the<execution-frequency-in-seconds>higher than 300 seconds (five minutes). The extension must collect metrics at least once every five minutes. -
Add the name of your script file to the
<file>element in themonitor.xmlfile. Be sure to use the correctos-typeattribute. Theos-typevalue should match the value returned from callingSystem.getProperty("os.name").<file os-type="your-os-type">{script file name}</file>You can use either the relative or absolute path of the script.
Copy the monitor.xml file to the Subdirectory Created in Step 1
Restart the Machine Agent
Required Agent Properties
Ensure that you have correctly configured the Agent in the controller-info.xml file and on the Agent start command on the command line. See Database Agent Configuration Properties.
After restarting the Machine Agent, you should see following message in your log file:
Executing script [<script_name>] on the console to make sure your changes work with the machine agent.
Verify Execution of the Monitoring Extension Script
To verify the execution of extension, wait at least one minute and check the metric data in the Metric Browser.
You can now create alerts based on any of these metrics.
例:UNIX でのオープンファイル用のモニタリング拡張機能の作成
JVM のすべてのオープンファイルをモニタするためのカスタムモニタを作成するには、次の手順を実行します。
- カスタムモニタリポジトリに新しいディレクトリを作成します。
-
特定のプロセス名(たとえば、Author、Publish など)に対応するようにこの UNIX スクリプトを変更して、スクリプトファイルを作成します。
lookfor="<process name 1>" pid=`ps aux | grep "$lookfor" | grep -v grep | tr -s " " | cut -f2 -d' '` count1=`lsof -p $pid | wc -l | xargs` lookfor="<process name 2>" pid=`ps aux | grep "$lookfor" | grep -v grep | tr -s " " | cut -f2 -d' '` count2=`lsof -p $pid | wc -l | xargs` echo "name=JVM|Files|<process name 1>,value="$count1 echo "name=JVM|Files|<process name 2>,value="$count2
-
次の
monitor.xmlファイルを作成し、ステップ 2 で示した UNIX スクリプトをポイントします。<monitor> <name>MyMonitors</name> <type>managed</type> <description>Monitor open file count </description> <monitor-configuration> </monitor-configuration> <monitor-run-task> <execution-style>continuous</execution-style> <name>Run</name> <type>executable</type> <task-arguments> </task-arguments> <executable-task> <type>file</type> <file>openfilecount.sh</file> </executable-task> </monitor-run-task> </monitor>
例:Windows でのプロセスステータスを確認するためのモニタリング拡張機能の作成
- カスタムモニタリポジトリに新しいディレクトリを作成します。
-
特定のプロセス名(たとえば、Author、Publish など)に対応するようにこの Windows PowerShell スクリプトを変更して、スクリプトファイルを作成します。次の Windows PowerShell スクリプトは、プロセスインスタンスがマシンで実行されているかどうかを確認します。
注: Windows でカスタムメトリックを生成する場合は、.bat ファイルではなく PowerShell および VBasic スクリプトを使用することをお勧めします。標準の Windows バッチ(.bat)スクリプトでメトリック名がエコーされると、名前が引用符で囲まれます。引用符が原因で、マシンエージェントはこれらのメトリックを無視します。PowerShell スクリプトと VBasic スクリプトにはこの問題はありません。$procName='<PROCESS_NAME>' $procStatus=Get-Process -Name $procName -ErrorAction SilentlyContinue if($procStatus) { write-output "name=Custom Metrics|Process|$procName|Running, value=1" } else { write-output "name=Custom Metrics|Process|$procName|Running, value=0" } -
次の
monitor.xmlファイルを作成し、ステップ 2 で示した Windows PowerShell スクリプトをポイントします。エラーが発生した場合は、「例:カスタマイズされたコマンドと引数を使用してマシンエージェントのカスタム拡張機能を実行」を試してみてください。CODE<monitor> <name>MyMonitors</name> <type>managed</type> <description>Monitor open file count </description> <monitor-configuration> </monitor-configuration> <monitor-run-task> <execution-style>continuous</execution-style> <name>Run</name> <type>executable</type> <task-arguments> <argument name="" default-value="-Command"></argument> <argument name="" default-value="C:\\absolute\\path\\to\\powershell\\script\\mp.ps1"></argument> </task-arguments> <executable-task> <type>command</type> <command>C:\\absolute\\path\\to\\powershell\\executable\\powershell.exe</command> </executable-task> </monitor-run-task> </monitor>
マシンエージェントに PowerShell プログラムを提供していて、カスタムメトリックを表示できない場合は、次の手順を実行します。
-
PowerShell スクリプトと
monitor.xmlファイルを作成したフォルダと同じフォルダに.batファイルを作成します。.bat ファイルの例CODEprocess_checker.bat -
次のコードの行を
.batファイルに追加します。正しい PowerShell スクリプトファイル名を使用していることを確認します。この例では、PowerShell スクリプトファイル名はprocess_status_checker.ps1です。CODE@echo off Powershell.exe -executionpolicy remotesigned -File process_status_checker.ps1 -
次のコードの行を
monitor.xmlファイルに追加します。正しい.batファイル名を使用していることを確認します。この例では、.bat ファイル名はprocess_checker.batです。CODE<monitor> <name>MyMonitors</name> <type>managed</type> <description>Monitor process status</description> <monitor-configuration> </monitor-configuration> <monitor-run-task> <execution-style>periodic</execution-style> <execution-frequency-in-seconds>60</execution-frequency-in-seconds> <execution-timeout-in-secs>60</execution-timeout-in-secs> <name>MyMonitors</name> <type>executable</type> <task-arguments></task-arguments> <executable-task> <type>file</type> <file os-type=“windows”>process_checker.bat</file> </executable-task> </monitor-run-task> </monitor>
例:カスタマイズされたコマンドと引数を使用してマシンエージェントのカスタム拡張機能を実行
デフォルトでは、マシンエージェントはシェルスクリプトとして bash シェルスクリプトを実行します。この例は、bash シェルスクリプトを bash スクリプトとして実行する方法を示します。
スクリプト example.sh では、以下の monitor.xml ファイルを作成するとスクリプトが ./example.sh として実行されます。
<monitor>
<name>HardwareMonitor</name>
<type>managed</type>
<enabled>false</enabled>
<enable-override os-type="solaris">true</enable-override>
<enable-override os-type="sunos">true</enable-override>
<description>Monitors system resources - CPU, Memory, Network I/O, and Disk I/O.
</description>
<monitor-configuration>
</monitor-configuration>
<monitor-run-task>
<execution-style>continuous</execution-style>
<name>Run</name>
<type>executable</type>
<task-arguments>
</task-arguments>
<executable-task>
<type>file</type>
<file>example.sh</file>
</executable-task>
</monitor-run-task>
</monitor>
スクリプトを "bash example.sh" として実行するには、次の手順を実行します。
-
以下に示すように
monitor.xmlファイルを変更します。<task-arguments>オプションと<executable-task>オプションは実装の変更に合わせて調整します。CODE<monitor> <name>ExampleMonitor</name> <type>managed</type> <enabled>true</enabled> <description>Monitors system resources - CPU, Memory, Network I/O, and Disk I/O. </description> <monitor-configuration> </monitor-configuration> <monitor-run-task> <execution-style>continuous</execution-style> <name>Run</name> <type>executable</type> <task-arguments> <argument name="arg1" is-required="true" default-value="example.sh"/> </task-arguments> <executable-task> <type>command</type> <command>bash</command> <arguments-pattern>$arg1</arguments-pattern> <wait-for-process-exit>true</wait-for-process-exit> </executable-task> </monitor-run-task> </monitor>