normalian blog

Let's talk about Microsoft Azure, ASP.NET and Java!

クラウドサービスで Application Insights の Java SDK を利用する場合の TIPS

本ブログで何度も紹介させて頂いている Application Insights だが、クラウドサービスの利用時に AVAILBABLE MEMORY, PROCESS IO RATE, PROCESSOR TIME が以下の様に出力されない場合がある。
f:id:waritohutsu:20151129143045j:plain

解決方法を先に言ってしまうと、クラウドサービスのスタートアップタスクで Visual C++ Redistributable Packages for Visual Studio 2013 をインストールすればよい。

何でログが出ないの?

クラウドサービスで利用する OS は Windows Server(設定によってバージョンは変わる)なのは周知だと思うが、Java SDK の JniPCConnector.java を確認すればわかるが、JNI を利用してネイティブコードを呼び出している。
さらにソースコード内で ApplicationInsights-Java の C++ ソースを確認すればわかる通り、ネイティブコードを利用してパフォーマンスカウンタに登録していることがわかる。
これらの処理を行う際、Windows Server では Visual C++ Redistributable Packages for Visual Studio 2013 のセットアップが必要になるが、本モジュールが不足しているために AVAILBABLE MEMORY, PROCESS IO RATE, PROCESSOR TIME が出力されないという問題が発生する。

対応方法

Azure Toolkit for Eclipse を利用したプロジェクト構成が前提となるが、以下の手順で問題は解決できる。

  • Visual C++ Redistributable Packages for Visual Studio 2013 から vcredist_x64.exe ファイルを取得
  • "project name"\WorkerRole1\approot\vcredist_x64.exe にモジュールを配置する
  • 以下のバッチファイルを参考に、"project name"\WorkerRole1\approot\startup.cmd に対して vcredist_x64.exe のセットアップ処理を記載する
:: *** This script will run whenever Azure starts this role instance.
:: *** This is where you can describe the deployment logic of your server, JRE and applications 
:: *** or specify advanced custom deployment steps
::     (Note though, that if you're using this in Eclipse, you may find it easier to configure the JDK,
::     the server and the server and the applications using the New Azure Deployment Project wizard 
::     or the Server Configuration property page for a selected role.)

echo Hello World!
vcredist_x64.exe /install /quiet