Munin JMX 配置

3

我正在尝试在Munin上启用JMX监控。

我遵循了以下指南:

https://github.com/munin-monitoring/contrib/tree/master/plugins/java/jmx

它告诉我:
1) Files from "plugin" folder must be copied to /usr/share/munin/plugins (or another - where your munin plugins located)
2) Make sure that jmx_ executable : chmod a+x /usr/share/munin/plugins/jmx_
3) Copy configuration files that you want to use, from "examples" folder, into /usr/share/munin/plugins folder
4) create links from the /etc/munin/plugins folder to the /usr/share/munin/plugins/jmx_
The name of the link must follow wildcard pattern:
jmx_<configname>,
where configname is the name of the configuration (config filename without extension), for example:
ln -s /usr/share/munin/plugins/jmx_ /etc/munin/plugins/jmx_process_memory

我已经按照要求做了这个,但是当我运行./jmx_process_memory时,我只得到以下输出:

Error: Could not find or load main class org.munin.plugin.jmx.memory

实际的配置文件名为java_process_memory.conf,因此我也尝试将符号链接命名为jmx_java_process_memory,但是遇到了相同的错误。
我已经通过按照这里描述的方式将符号链接命名为jmx_Threads而取得了成功。
http://blog.johannes-beck.name/?p=160

我看到org.munin.plugin.jmx.Threads是munin-jmx-plugins.jar中的一个类名,其他类似的类也能工作。但这不是Munin指南告诉我的方法,所以文档有误吗?配置文件的目的是什么,它们一定有重要性。Tomcat有示例配置文件,这是我真正感兴趣的地方,所以我需要理解这个问题。但如果不能按照指南进行操作,我会有点困惑!请问有人能够帮助我纠正这个问题吗? 谢谢 NFV
1个回答

2

我遇到了一个与之前类似的问题。

为了让事情变得更好一些,但仍不完美,我做了以下操作:

我正在使用 RHEL 操作系统:

[root@bus|in plugins]# cat /etc/munin/plugin-conf.d/munin-node 
[diskstats]
user munin

[iostat_ios]
user munin

[jmx_*]
env.ip 192.168.1.101
env.port 5054         <- being the port configured for your jmx 

那么

[root@bus|in plugins]# ls -l /etc/munin/plugins/jmx_MultigraphAll 
lrwxrwxrwx 1 root root 29 14 mars  15:36 /etc/munin/plugins/jmx_MultigraphAll -> /usr/share/munin/plugins/jmx_

我修改了 /usr/share/munin/plugins/jmx_ 文件,具体如下:

#!/bin/sh
# -*- sh -*-
: << =cut

=head1 NAME

jmx_ - Wildcard plugin to monitor Java application servers via JMX

=head1 APPLICABLE SYSTEMS

Tested with Tomcat 4.1/5.0/5.5/6.0 on Sun JVM 5/6 and OpenJDK.

Any JVM that supports JMX should in theory do.

Needs nc in path for autoconf.

=head1 CONFIGURATION

  [jmx_*]
    env.ip 127.0.0.1
    env.port 5400
    env.category jvm
    env.username monitorRole
    env.password SomethingSecret

    env.JRE_HOME /usr/lib/jvm/java-6-sun/jre
    env.JAVA_OPTS -Xmx128m

Needed configuration on the Tomcat side: add

  -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=5400 \
  -Dcom.sun.management.jmxremote.ssl=false \
  -Dcom.sun.management.jmxremote.authenticate=false

to CATALINA_OPTS in your startup scripts.

Replace authenticate=false with 
  -Dcom.sun.management.jmxremote.password.file=/etc/tomcat/jmxremote.password \
  -Dcom.sun.management.jmxremote.access.file=/etc/tomcat/jmxremote.access
 ...if you want authentication.

jmxremote.password:
 monitorRole SomethingSecret

jmxremote.access:
 monitorRole readonly

You may need higher access levels for some counters, notably ThreadsDeadlocked.

=head1 BUGS

No encryption supported in the JMX connection.

The plugins available reflect the most interesting aspects of a
JVM runtime.  This should be extended to cover things specific to
Tomcat, JBoss, Glassfish and so on.  Patches welcome.

=head1 AUTHORS

=encoding UTF-8

Mo Amini, Diyar Amin and Younes Hajji, Høgskolen i Oslo/Oslo
University College.

Shell script wrapper and integration by Erik Inge Bolsø, Redpill
Linpro AS.

Previous work on JMX plugin by Aleksey Studnev. Support for
authentication added by Ingvar Hagelund, Redpill Linpro AS.

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf suggest

=cut

MUNIN_JAR="/usr/share/java/munin-jmx-plugins.jar"

if [ "x$JRE_HOME" != "x" ] ; then
  JRE=$JRE_HOME/bin/java
  export JRE_HOME=$JRE_HOME
fi
JAVA_BIN=${JRE:-/opt/jdk/jre/bin/java}

ip=${ip:-192.168.1.101}
port=${port:-5054}

if [ "x$1" = "xsuggest" ] ; then
  echo MultigraphAll
  exit 0
fi

if [ "x$1" = "xautoconf" ] ; then
    NC=`which nc 2>/dev/null`
    if [ "x$NC" = "x" ] ; then
      echo "no (nc not found)"
      exit 0
    fi
    $NC -n -z $ip $port >/dev/null 2>&1
    CONNECT=$?

    $JAVA_BIN -? >/dev/null 2>&1
    JAVA=$?
    if [ $JAVA -ne 0 ] ; then
      echo "no (java runtime not found at $JAVA_BIN)"
      exit 0
    fi

    if [ ! -e $MUNIN_JAR ] ; then
      echo "no (munin jmx classes not found at $MUNIN_JAR)"
      exit 0
    fi

    if [ $CONNECT -eq 0 ] ; then
      echo "yes"
      exit 0
    else
      echo "no (connection to $ip:$port failed)"
      exit 0
    fi
fi

if [ "x$1" = "xconfig" ] ; then
  param=config
else
  param=Tomcat
fi

scriptname=${0##*/}
jmxfunc=${scriptname##*_}
prefix=${scriptname%_*}

if [ "x$jmxfunc" = "x" ] ; then
  echo "error, plugin must be symlinked in order to run"
  exit 1
fi

ip=$ip port=$port $JAVA_BIN -cp $MUNIN_JAR $JAVA_OPTS org.munin.plugin.jmx.$jmxfunc $param $prefix

您需要在定义JRE时添加正确的权限和所有者:组,例如:

[root@bus|in plugins]# ls -ld /opt/jdk
drwxrwxr-x 8 nobody nobody 4096  8 oct.  15:03 /opt/jdk

现在我可以运行它(我可以看到它正在使用 nobody: nobody 作为用户:组,也许可以在配置中尝试一些东西):

[root@bus|in plugins]# munin-run jmx_MultigraphAll -d
# Processing plugin configuration from /etc/munin/plugin-conf.d/df
# Processing plugin configuration from /etc/munin/plugin-conf.d/fw_
# Processing plugin configuration from /etc/munin/plugin-conf.d/hddtemp_smartctl
# Processing plugin configuration from /etc/munin/plugin-conf.d/munin-node
# Processing plugin configuration from /etc/munin/plugin-conf.d/postfix
# Processing plugin configuration from /etc/munin/plugin-conf.d/sendmail
# Setting /rgid/ruid/ to /99/99/
# Setting /egid/euid/ to /99 99/99/
# Setting up environment
# Environment ip = 192.168.1.101
# Environment port = 5054
# About to run '/etc/munin/plugins/jmx_MultigraphAll'
multigraph jmx_memory
Max.value 2162032640
Committed.value 1584332800
Init.value 1613168640
Used.value 473134248

multigraph jmx_MemoryAllocatedHeap
Max.value 1037959168
Committed.value 1037959168
Init.value 1073741824
Used.value 275414584

multigraph jmx_MemoryAllocatedNonHeap
Max.value 1124073472
Committed.value 546373632
Init.value 539426816
Used.value 197986088

[...]

multigraph jmx_ProcessorsAvailable
ProcessorsAvailable.value 1

现在我正在尝试使其适用于同一主机上不同的JVM,因为这是针对单个JVM的。

编辑: 实际上,我已经进行了修改,以便与具有自己的JMX端口的多个Java进程一起使用。

您需要在其中添加它们:

[root@bus|in plugins]# cat /etc/munin/plugin-conf.d/munin-node 
[diskstats]
user munin

[iostat_ios]
user munin

[admin_jmx_*]
env.ip 192.168.1.101
env.port 5054

[managed_jmx_*]
env.ip 192.168.1.101
env.port 5055

[jboss_jmx_*]
env.ip 192.168.1.101
env.port 1616

然后创建链接:
[root@bus|in plugins]# ls -l /etc/munin/plugins/*_jmx_*
lrwxrwxrwx 1 root root 29 14 mars  15:36 /etc/munin/plugins/admin_jmx_MultigraphAll -> /usr/share/munin/plugins/jmx_
lrwxrwxrwx 1 root root 29 14 mars  16:51 /etc/munin/plugins/jboss_jmx_MultigraphAll -> /usr/share/munin/plugins/jmx_
lrwxrwxrwx 1 root root 29 14 mars  16:03 /etc/munin/plugins/managed_jmx_MultigraphAll -> /usr/share/munin/plugins/jmx_

我将 /usr/share/munin/plugins/jmx_ 文件中的IP和端口注释掉了,但我不确定它是否起作用。


谢谢,我终于搞定了,看起来和你的方法类似,但我没有像你那样使用多个虚拟机! - nfvindaloo
好的,其实我认为这会更困难一些。 但实际上它是在同一台服务器上的不同Java进程,而不是不同的虚拟机。 - Pierre-Alain TORET

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接