MuninにTomcatプラグインを追加して監視する方法
Muninにtomcat用のプラグインを設定して監視してみました。
以下のような環境に設定してみました。
- CentOS
- Tomcat 7.0.42
JVMのメモリー使用量がわかるのは大変ありがたいですね。
こちらの環境だけかもしれませんが、若干ハマリポイントがありましたので、そちらも説明したいと思います。
Tomcatの設定
TOMCAT_HOME/conf/tomcat-users.xmlにmunin用の監視ユーザーを追加します。
<role rolename="manager-status" /> <user username="munin" password="munin" roles="manager-status"/>
Tomcatを再起動しておきます。
TomcatのStatusのXMLが取得できるか確認
curlコマンドを使いました。
curl --user munin:munin http://localhost:8080/manager/status?XML=true
XML文章が出力されればOKです。
MuninにTomcatプラグインのインストール
シンボリックリンクを設定します。
ln -s /usr/share/munin/plugins/tomcat_access /etc/munin/plugins/ ln -s /usr/share/munin/plugins/tomcat_jvm /etc/munin/plugins/ ln -s /usr/share/munin/plugins/tomcat_threads /etc/munin/plugins/ ln -s /usr/share/munin/plugins/tomcat_volume /etc/munin/plugins/
MuninのTomcatプラグインの設定
設定ファイルを作成します。
# vim /etc/munin/plugin-conf.d/tomcat
以下の内容を入力します。
環境に合わせて内容を変更してください。
今回は監視コネクタにはajpを設定しています。
env.host localhost env.port 8080 env.request /manager/status?XML=true env.user munin env.password munin env.timeout 30 env.connector "ajp-bio-8009"
ハマったのは7行目の設定です。
JVM値は取得できたのですが、他の値がすべて取得できませんでした・・・。
でステータスXMLをテキストエディタで開いてみると、コネクタ名が""
でくくられていることがわかりました・・・。
これもしかしたら、server.xmlの設定なのかな・・・。
"" その他
ajpの場合だけかもしれませんが、threadsが取得できませんでした・・・。
/usr/share/munin/plugins/tomcat_threads
で
if($xml->{'connector'}->{$CONNECTOR}->{'threadInfo'}->[0]->{'currentThreadsBusy'} && $xml->{'connector'}->{$CONNECTOR}->{'threadInfo'}->[0]->{'currentThreadCount'}) {
というif文があり、xmlのcurrentThreadsBusyの値が0なんですよね。
httpコネクタの方は1だったんですけどね。
現在処理しているスレッド数みたいな感じなんですかね。ajpの場合は0固定なのかな、わかんないっす。
すいません。if文書き換えました。
if($xml->{'connector'}->{$CONNECTOR}->{'threadInfo'}->[0]->{'currentThreadCount'}) {
ダメな修正かもしれません。
参考までに、ステータスXMLは以下のようになります。
<?xml version='1.0' encoding='utf-8'?> <status> <jvm> <memory free="143752760" total="248381440" max="467927040"> <memorypool name="PS Eden Space" type="Heap memory" usageinit="8323072" usagecommitted="152174592" usagemax="153812992" usageused="28415272"> </memorypool> <memorypool name="PS Old Gen" type="Heap memory" usageinit="21954560" usagecommitted="85131264" usagemax="350945280" usageused="74098144"> </memorypool> <memorypool name="PS Survivor Space" type="Heap memory" usageinit="1310720" usagecommitted="11075584" usagemax="11075584" usageused="2115264"> </memorypool> <memorypool name="Code Cache" type="Non-heap memory" usageinit="2555904" usagecommitted="7995392" usagemax="50331648" usageused="7811520"> </memorypool> <memorypool name="PS Perm Gen" type="Non-heap memory" usageinit="21757952" usagecommitted="85983232" usagemax="85983232" usageused="66393808"> </memorypool> </memory> </jvm> <connector name='"ajp-bio-8009"'> <threadinfo maxthreads="200" currentthreadcount="10" currentthreadsbusy="0"> <requestinfo maxtime="6103" processingtime="36809" requestcount="2933" errorcount="22" bytesreceived="51728" bytessent="8091945"> <workers> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> <worker stage="R" requestprocessingtime="0" requestbytessent="0" requestbytesreceived="0" remoteaddr="?" virtualhost="?" method="?" currenturi="?" currentquerystring="?" protocol="?"> </worker> </workers> </requestinfo> </threadinfo> </connector> <connector name='"http-bio-8080"'> <threadinfo maxthreads="200" currentthreadcount="10" currentthreadsbusy="1"> <requestinfo maxtime="30" processingtime="313" requestcount="73" errorcount="0" bytesreceived="0" bytessent="351999"> <workers> <worker stage="S" requestprocessingtime="5" requestbytessent="0" requestbytesreceived="0" remoteaddr="127.0.0.1" virtualhost="localhost" method="GET" currenturi="/manager/status" currentquerystring="XML=true" protocol="HTTP/1.1"> </worker> </workers> </requestinfo> </threadinfo> </connector> </status>