Top/Devel/Java/jvmstat/MRTGと組み合わせる

MRTGと組み合わせるはてなブックマーク

今回はJBossのパフォーマンス情報をMIBに登録し、外部のMRTGでグラフを書きます。

JBoss側の設定


vi /usr/local/jboss/bin/run.sh
#JAVA_OPTS="$JAVA_OPTS -Dprogram.name=$PROGNAME"
JAVA_OPTS="$JAVA_OPTS -Dprogram.name=$PROGNAME -XX:+UsePerfData"
/etc/rc.d/init.d/jboss restart

jvmstatとsnmp

vi /usr/local/jvmstat/bin/run.sh
#!/bin/bash

case "$1" in
  gcSurvivor0)
    /usr/local/jvmstat/bin/jvmstat -gcutil `pgrep -f UsePerfData | head -1` | awk 'NR==2{print $1}'
    ;;
  gcSurvivor1)
    /usr/local/jvmstat/bin/jvmstat -gcutil `pgrep -f UsePerfData | head -1` | awk 'NR==2{print $2}'
    ;;
  gcEden)
    /usr/local/jvmstat/bin/jvmstat -gcutil `pgrep -f UsePerfData | head -1` | awk 'NR==2{print $3}'
    ;;
  gcOld)
    /usr/local/jvmstat/bin/jvmstat -gcutil `pgrep -f UsePerfData | head -1` | awk 'NR==2{print $4}'
    ;;
  gcPermanent)
    /usr/local/jvmstat/bin/jvmstat -gcutil `pgrep -f UsePerfData | head -1` | awk 'NR==2{print $5}'
    ;;
esac
exit 0
chmod a+x /usr/local/jvmstat/bin/run.sh
vi +200 /etc/snmp/snmpd.conf
exec gcSurvivor0 /usr/local/jvmstat/bin/run.sh gcSurvivor0
exec gcSurvivor1 /usr/local/jvmstat/bin/run.sh gcSurvivor1
exec gcEden      /usr/local/jvmstat/bin/run.sh gcEden
exec gcOld       /usr/local/jvmstat/bin/run.sh gcOld
exec gcPermanent /usr/local/jvmstat/bin/run.sh gcPermanent
/etc/rc.d/init.d/snmpd reload

テスト

snmpwalk -v 1 192.168.0.2 -c public .1.3.6.1.4.1.2021.8.1.101.1
snmpwalk -v 1 192.168.0.2 -c public .1.3.6.1.4.1.2021.8.1.101.2
snmpwalk -v 1 192.168.0.2 -c public .1.3.6.1.4.1.2021.8.1.101.3
snmpwalk -v 1 192.168.0.2 -c public .1.3.6.1.4.1.2021.8.1.101.4
snmpwalk -v 1 192.168.0.2 -c public .1.3.6.1.4.1.2021.8.1.101.5

備考

正しく書くと下記になるが、環境によっては上記でも問題なく、かつ早い。

/usr/local/jvmstat/bin/jvmstat -gcutil `/usr/local/jvmstat/bin/jvmps | grep jboss | awk '{print $1}'` | awk 'NR==2{print $1}'

MRTGの設定

vi /etc/mrtg/mrtg.cfg
### Garbage Collection Analysis ###
Target[gcS]: .1.3.6.1.4.1.2021.8.1.101.1&.1.3.6.1.4.1.2021.8.1.101.2:public@192.168.0.2
MaxBytes[gcS]: 100
Unscaled[gcS]: dwmy
Options[gcS]: gauge, absolute, growright, nopercent, noinfo
YLegend[gcS]: Survivor Used(%)
ShortLegend[gcS]: (%)
LegendI[gcS]: S0
LegendO[gcS]: S1
Legend1[gcS]: Survivor0 使用率(%)
Legend2[gcS]: Survivor1 使用率(%)
Title[gcS]: Garbage Collection Analysis for Survivor
PageTop[gcS]: <H1>Garbage Collection Analysis for Survivor</H1>

Target[gcE]: .1.3.6.1.4.1.2021.8.1.101.3&.1.3.6.1.4.1.2021.8.1.101.3:public@192.168.0.2
MaxBytes[gcE]: 100
Unscaled[gcE]: dwmy
Options[gcE]: gauge, absolute, growright, nopercent, noinfo
YLegend[gcE]: Eden Used(%)
ShortLegend[gcE]: (%)
LegendI[gcE]: E
LegendO[gcE]: E
Legend1[gcE]: Eden 使用率(%)
Legend2[gcE]: Eden 使用率(%)
Title[gcE]: Garbage Collection Analysis for Eden
PageTop[gcE]: <H1>Garbage Collection Analysis for Eden</H1>

Target[gcO]: .1.3.6.1.4.1.2021.8.1.101.4&.1.3.6.1.4.1.2021.8.1.101.4:public@192.168.0.2
MaxBytes[gcO]: 100
Unscaled[gcO]: dwmy
Options[gcO]: gauge, absolute, growright, nopercent, noinfo
YLegend[gcO]: Old Used(%)
ShortLegend[gcO]: (%)
LegendI[gcO]: O
LegendO[gcO]: O
Legend1[gcO]: Old 使用率(%)
Legend2[gcO]: Old 使用率(%)
Title[gcO]: Garbage Collection Analysis for Old
PageTop[gcO]: <H1>Garbage Collection Analysis for Old</H1>

Target[gcP]: .1.3.6.1.4.1.2021.8.1.101.5&.1.3.6.1.4.1.2021.8.1.101.5:public@192.168.0.2
MaxBytes[gcP]: 100
Unscaled[gcP]: dwmy
Options[gcP]: gauge, absolute, growright, nopercent, noinfo
YLegend[gcP]: Permanent Used(%)
ShortLegend[gcP]: (%)
LegendI[gcP]: P
LegendO[gcP]: P
Legend1[gcP]: Permanent 使用率(%)
Legend2[gcP]: Permanent 使用率(%)
Title[gcP]: Garbage Collection Analysis for Permanent
PageTop[gcP]: <H1>Garbage Collection Analysis for Permanent</H1>

[FAQ]パフォーマンス情報が取得できない

所有権

/tmp/hsperfdata_<username>の所有者をチェックし、対象プロセスの実行ユーザーと異なるときは削除して下さい。ついで、対象プロセスを再起動して下さい。

javaへのパス

snmpd実行ユーザーでのパスを通すために以下のようにするか、jvmps, jvmstat等のシェルスクリプト内部を変更して下さい。

vi ~/.bashrc
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin

snmpd.confのexecディレクティブ

行末にタブが入っていたりしないか、確認してみて下さい。

参考

Amazon

差分 一覧