2016-03-02 52 views
0

當我們測試JMX插件時Collectd面臨NoSuchMethod exception異常(缺少API的gethostname())測試JMX插件Collectd

java.lang.NoSuchMethodError:方法org.collectd.api.Collectd.getHostname()Ljava/lang/String;未找到。

既沒有從official api wiki也沒有從源代碼collectd-api.jar我們能找到這個方法的定義。

此外,我們不知道爲什麼調用此API。這裏是我的相關內容collectd.conf

LoadPlugin "java" 

    <Plugin "java"> 
     JVMARG "-Djava.class.path=/usr/share/collectd/java/collectd-api.jar:/usr/share/collectd/java/generic-jmx.jar" 
     LoadPlugin "org.collectd.java.GenericJMX" 

     <Plugin "GenericJMX"> 
      ################ 
      # MBean blocks # 
      ################ 
      # Number of classes being loaded. 
      <MBean "classes"> 
       ObjectName "java.lang:type=ClassLoading" 
       #InstancePrefix "" 
       #InstanceFrom "" 

       <Value> 
        Type "gauge" 
        InstancePrefix "loaded_classes" 
        #InstanceFrom "" 
        Table false 
        Attribute "LoadedClassCount" 
       </Value> 
      </MBean> 

      # Time spent by the JVM compiling or optimizing. 
      <MBean "compilation"> 
       ObjectName "java.lang:type=Compilation" 
       #InstancePrefix "" 
       #InstanceFrom "" 

       <Value> 
        Type "total_time_in_ms" 
        InstancePrefix "compilation_time" 
        #InstanceFrom "" 
        Table false 
        Attribute "TotalCompilationTime" 
       </Value> 
      </MBean> 

      # Garbage collector information 
      <MBean "garbage_collector"> 
       ObjectName "java.lang:type=GarbageCollector,*" 
       InstancePrefix "gc-" 
       InstanceFrom "name" 

       <Value> 
        Type "invocations" 
        #InstancePrefix "" 
        #InstanceFrom "" 
        Table false 
        Attribute "CollectionCount" 
       </Value> 

       <Value> 
        Type "total_time_in_ms" 
        InstancePrefix "collection_time" 
        #InstanceFrom "" 
        Table false 
        Attribute "CollectionTime" 
       </Value> 

      </MBean> 

      ###################################### 
      # Define the "jmx_memory" type as: # 
      # jmx_memory value:GAUGE:0:U  # 
      # See types.db(5) for details.  # 
      ###################################### 

      # Generic heap/nonheap memory usage. 
      <MBean "memory"> 
       ObjectName "java.lang:type=Memory" 
       #InstanceFrom "" 
       InstancePrefix "memory" 

       # Creates four values: committed, init, max, used 
       <Value> 
        Type "jmx_memory" 
        #InstancePrefix "" 
        #InstanceFrom "" 
        Table true 
        Attribute "HeapMemoryUsage" 
        InstancePrefix "heap-" 
       </Value> 

       # Creates four values: committed, init, max, used 
       <Value> 
        Type "jmx_memory" 
        #InstancePrefix "" 
        #InstanceFrom "" 
        Table true 
        Attribute "NonHeapMemoryUsage" 
        InstancePrefix "nonheap-" 
       </Value> 
      </MBean> 

       # Memory usage by memory pool. 
       <MBean "memory_pool"> 
       ObjectName "java.lang:type=MemoryPool,*" 
       InstancePrefix "memory_pool-" 
       InstanceFrom "name" 

       <Value> 
        Type "jmx_memory" 
        #InstancePrefix "" 
        #InstanceFrom "" 
        Table true 
        Attribute "Usage" 
       </Value> 
      </MBean> 

      ### MBeans by Catalina/Tomcat ### 
      # The global request processor (summary for each request processor) 
      <MBean "catalina/global_request_processor"> 
       ObjectName "Catalina:type=GlobalRequestProcessor,*" 
       InstancePrefix "request_processor-" 
       InstanceFrom "name" 

       <Value> 
        Type "io_octets" 
        InstancePrefix "global" 
        #InstanceFrom "" 
        Table false 
        Attribute "bytesReceived" 
        Attribute "bytesSent" 
       </Value> 

       <Value> 
        Type "total_requests" 
        InstancePrefix "global" 
        #InstanceFrom "" 
        Table false 
        Attribute "requestCount" 
       </Value> 

       <Value> 
        Type "total_time_in_ms" 
        InstancePrefix "global-processing" 
        #InstanceFrom "" 
        Table false 
        Attribute "processingTime" 
       </Value> 
      </MBean> 

      # Details for each request processor 
      <MBean "catalina/detailed_request_processor"> 
       ObjectName "Catalina:type=RequestProcessor,*" 
       InstancePrefix "request_processor-" 
       InstanceFrom "worker" 

       <Value> 
        Type "io_octets" 
        #InstancePrefix "" 
        InstanceFrom "name" 
        Table false 
        Attribute "bytesReceived" 
        Attribute "bytesSent" 
       </Value> 

       <Value> 
        Type "total_requests" 
        #InstancePrefix "" 
        InstanceFrom "name" 
        Table false 
        Attribute "requestCount" 
       </Value> 

       <Value> 
        Type "total_time_in_ms" 
        InstancePrefix "processing-" 
        InstanceFrom "name" 
        Table false 
        Attribute "processingTime" 
       </Value> 
      </MBean> 

      # Thread pool 
      <MBean "catalina/thread_pool"> 
       ObjectName "Catalina:type=ThreadPool,name=*" 
       InstancePrefix "request_processor-" 
       InstanceFrom "name" 

       <Value> 
        Type "threads" 
        InstancePrefix "total" 
        #InstanceFrom "" 
        Table false 
        Attribute "currentThreadCount" 
       </Value> 

       <Value> 
        Type "threads" 
        InstancePrefix "running" 
        #InstanceFrom "" 
        Table false 
        Attribute "currentThreadsBusy" 
       </Value> 
      </MBean> 
      ##################### 
      # Connection blocks # 
      ##################### 
      <Connection> 
       ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:8899/jmxrmi" 
       Host "localhost" 
       Collect "classes" 
       Collect "compilation" 
       Collect "garbage_collector" 
       Collect "memory" 
       Collect "memory_pool" 
       Collect "catalina/thread_pool" 
       Collect "catalina/detailed_request_processor" 
       Collect "catalina/global_request_processor" 
      </Connection> 
     </Plugin> 
    </Plugin> 

我將不勝感激任何答案。

+0

歡迎來到Stack Overflow!我編輯了你的問題,以正確地格式化內聯代碼和塊引用。我還將代碼示例縮進了4個空格,以便它能夠正確渲染 - 請參閱編輯幫助以獲取有關格式化的更多信息。祝你好運! – Wtower

回答

1

我修復了這個問題。 從Collectd GITHUB https://github.com/collectd/collectd/blob/master/bindings/java/org/collectd/api/OConfigItem.java,我們可以看到java api文件是最新版本,並且定義了缺少的API getHostname()。

對於安裝了最新collectd 5.5版本的collect-api.jar,java文件沒有包含新的API。

因此,它在我編譯&打包代碼從github下載並替換舊的jar後運行良好。

希望它能幫助你。

只是不能相信這樣的問題會發生在官方發佈。