[ZBXNEXT-1223] JMX items LLD discovery Created: 2012 May 15  Updated: 2024 Apr 10  Resolved: 2017 Aug 04

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Agent (G), Frontend (F), Java gateway (J), Server (S)
Affects Version/s: 2.0.0
Fix Version/s: 3.4.0alpha1, 3.4 (plan)

Type: New Feature Request Priority: Minor
Reporter: Igor Urazov Assignee: Unassigned
Resolution: Fixed Votes: 30
Labels: jmx, lld, patch
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Java Source File JMXItemChecker-3.0.4.java     Text File Zabbix-adoptation-3.0.4.txt     Text File filter.patch     Text File jmx.discovery.filter.patch     PNG File zbxnext-1223.png    
Issue Links:
Duplicate
is duplicated by ZBXNEXT-3509 Patch to provide Java Gateway support... Open
is duplicated by ZBXNEXT-1648 Improve Zabbix JMX Discovery to query... Closed
is duplicated by ZBX-6273 Document jmx.discovery item Closed
Team: Team C
Team: Team C
Sprint: Sprint 11, Sprint 12
Story Points: 1

 Description   

It would be very nice to be able to perform discovery of JVM garbage collectors and memory pools via JMX. Something like: jmx["java.lang:type=GarbageCollector,name={#GCNAME}","CollectionCount"] and jmx["java.lang:type=MemoryPool,name={#MPNAME}","Usage.used"]



 Comments   
Comment by Semyon Koshechkin [ 2012 Nov 22 ]

It would be nice to autodiscover new ActiveMQ topics and queues via JMX

Comment by Semyon Koshechkin [ 2012 Nov 23 ]

Actually, there is a jmx lld in zabbix java gateway source code.

file: JMXItemChecker.java
look for "jmx.discovery"

i'll try it later

Comment by Ryan Rupp [ 2013 Mar 07 ]

Sorry, I had missed this Jira and actually created a duplicate here - ZBXNEXT-1648 - I have the proposal/code changes in that Jira to do this, just need some feedback. Thanks.

Comment by Lee Lists [ 2013 May 24 ]

Hi,

Could someone post a template using this feature ?

Thanks,
Lee

Comment by Semyon Koshechkin [ 2013 Aug 22 ]

Code proposal for parameterized jmx.discovery:
https://gist.github.com/Cromeshnic/6303320

Example usage:
jmx.discovery["org.apache.activemq:BrokerName=*,Type=Queue,Destination=*"]

Comment by Semyon Koshechkin [ 2013 Aug 27 ]

Zabbix template using parameterized LLD:
https://gist.github.com/Cromeshnic/6316503

Comment by Linus Brimstedt [ 2013 Sep 30 ]

I have this patch in production and it works well!
I would highly appreciate if it was merged into zabbix (or if a similar solution was implemented)

Comment by Asbjorn Kjaer [ 2014 Jan 09 ]

I wrote a small patch that would enable filtered JMX discovery as well, but unlike the previous patch, this does not change the functionality of the existing jmx.discovery key, but instead adds a new key, jmx.discovery.filter. The output is also slightly different than what you get from jmx.discovery. This patch will let you search for specific beans instead of attributes. The example output below shows the output from a HornetQ request.

Request
{
    "request": "java gateway jmx",
    "conn": "10.x.x.x",
    "port": 9000,
    "keys": [
        "jmx.discovery.filter[\"org.hornetq:module=JMS,type=Queue,name=*\"]"
    ]
}
Result
{
    "{#PROPTYPE}":"Queue",
    "{#PROPNAME}":"\"DLQ\"",
    "{#PROPMODULE}":"JMS",
    "{#JMXDESC}":"Information on the management interface of the MBean",
    "{#JMXOBJ}":"org.hornetq:module=JMS,name=\"DLQ\",type=Queue"
}

The main reason I found for changing the output, was because the attribute information fields didnt make much sense when you are searching for beans instead.

EDIT:

I realized that the previous patch was too specific to HornetQ and the way some of the MBean Properties are exposed, so a more generic version can be found at https://github.com/bunjiboys/random/blob/master/filter.patch.

Instead of hardcoding certain property names, it will now return {#JMXOBJ}, {#JMXDESC} as before, and then iterate and expose as {#PROP<UPPERCASE-PROPERTY-NAME>}, for example {#PROPNAME}. This lets you use any arbitrary property exposed by the MBean.

Comment by Asbjorn Kjaer [ 2014 Feb 14 ]

We have just released a standalone version of the patch about, that can be used with the external scripts functionality, to discover JMX items as well. You can find the source code at https://github.com/RiotGamesMinions/zabbix_jmxdiscovery

To build the jar, you can either compile the code manually using javac but we have also provided an ant build file. To build using ant, you simple need to run ant in the root folder of the git repo, and it will create a JAR file in the dist/ folder.

Comment by Asbjorn Kjaer [ 2014 Mar 01 ]

Updated jmx.discovery.filter patch, that is less general than the previous version

Comment by Andrew [ 2015 Jan 09 ]

Sorry guys, but can you hepl me with Semen's template?..
i configured/made/installed zabbix java gateway using file JMXItemChecker.java taken from https://gist.github.com/Cromeshnic/6303320#file-jmxitemchecker-java
I used template xml https://gist.github.com/Cromeshnic/6316503
but i cannot discover activemq...

zabbix_java.log says:

2015-01-09 03:15:25.030 [pool-1-thread-5] DEBUG com.zabbix.gateway.SocketProcessor - starting to process incoming connection
2015-01-09 03:15:25.031 [pool-1-thread-5] DEBUG c.z.gateway.BinaryProtocolSpeaker - reading Zabbix protocol header
2015-01-09 03:15:25.031 [pool-1-thread-5] DEBUG c.z.gateway.BinaryProtocolSpeaker - reading 8 bytes of data length
2015-01-09 03:15:25.031 [pool-1-thread-5] DEBUG c.z.gateway.BinaryProtocolSpeaker - reading 264 bytes of request data
2015-01-09 03:15:25.031 [pool-1-thread-5] DEBUG c.z.gateway.BinaryProtocolSpeaker - received the following data in request: {"request":"java gateway jmx","conn":"10.2.41.21","port":9012,"username":"user","password":"pswd","keys":["jmx.discovery[\"org.apache.activemq:BrokerName=*,Type=*,Destination=*\",Name]","jmx.discovery[\"org.apache.activemq:BrokerName=*,Type=Broker\",BrokerName]"]}
2015-01-09 03:15:25.032 [pool-1-thread-5] DEBUG com.zabbix.gateway.SocketProcessor - dispatched request to class com.zabbix.gateway.JMXItemChecker
2015-01-09 03:15:25.032 [pool-1-thread-5] DEBUG com.zabbix.gateway.JMXItemChecker - connecting to JMX agent at service:jmx:rmi:///jndi/rmi://10.2.41.21:9012/jmxrmi
2015-01-09 03:15:25.049 [pool-1-thread-5] DEBUG com.zabbix.gateway.ItemChecker - getting value for item 'jmx.discovery["org.apache.activemq:BrokerName=*,Type=*,Destination=*",Name]'
2015-01-09 03:15:25.054 [pool-1-thread-5] DEBUG com.zabbix.gateway.ItemChecker - received value '{
  "data": []
}' for item 'jmx.discovery["org.apache.activemq:BrokerName=*,Type=*,Destination=*",Name]'
2015-01-09 03:15:25.054 [pool-1-thread-5] DEBUG com.zabbix.gateway.ItemChecker - getting value for item 'jmx.discovery["org.apache.activemq:BrokerName=*,Type=Broker",BrokerName]'
2015-01-09 03:15:25.055 [pool-1-thread-5] DEBUG com.zabbix.gateway.ItemChecker - received value '{
  "data": []
}' for item 'jmx.discovery["org.apache.activemq:BrokerName=*,Type=Broker",BrokerName]'
2015-01-09 03:15:25.056 [pool-1-thread-5] DEBUG c.z.gateway.BinaryProtocolSpeaker - sending the following data in response: {"response":"success","data":[{"value":"{\n  \"data\": []\n}"},{"value":"{\n  \"data\": []\n}"}]}
2015-01-09 03:15:25.056 [pool-1-thread-5] DEBUG com.zabbix.gateway.SocketProcessor - finished processing incoming connection.

so it looks like returned json array is empty...

thank you.

Comment by Shijirbaatar Khadbaatar [ 2015 Mar 04 ]

Hello Dears,
I have a same problem. Did you solve it?
Br,

Comment by richlv [ 2016 Oct 17 ]

also see the variation of path/context that would be useful to handle in JMX LLD

Comment by Astapkovich Viacheslav [ 2016 Dec 26 ]

There are many variations of JMX discovery patch:
v.2.2.15 - https://support.zabbix.com/browse/ZBXNEXT-3509
Ryan Rupp - https://support.zabbix.com/browse/ZBXNEXT-1648
Cromeshnic - https://gist.github.com/Cromeshnic/6303320
josevh - https://gist.github.com/josevh/73f7a78c64ffed0d239c
External Script: https://github.com/RiotGamesMinions/zabbix_jmxdiscovery
Also, there is trouble about hardcoded JMXServiceURL. If you use WildFly you can't perform DDL without fix this.

Are there plans for an official decision?
We had to adopt variant from ZBXNEXT-3509 for java gateway version 3.0.4.
JMX Discovery is very powerfull tool for ejb and webservices monitoring. Very sad that there is no official way to fix problems with it. Am i wrong?

Also, suggest our addoptation for other, who decided to use it for 3.0.4:
About changes: Zabbix-adoptation-3.0.4.txt
Example: JMXItemChecker-3.0.4.java

Comment by Augugliaro [ 2017 Jun 08 ]

Hi,

I'm trying to use Asbjorn's external script jmx_discovery (https://github.com/RiotGamesMinions/zabbix_jmxdiscovery) and I've some troubles with the JSON interpretation by Zabbix.
Fact is that my {#PROPID} value is returned with escaped double quote (because the object name contains double quote in its real name), like this :

"{#PROPID}":"\"jmx_agent_name\"",

Then Zabbix refuse to recognize the JSON format. By the way, im forced to keep the double quote to create my jmx item, calling the exact name of the object.
Is someone having the same issue ? I'm using Zabbix 2.2.6.

Thanks,
Julien

Comment by Vladislavs Sokurenko [ 2017 Jun 08 ]

Could it be something that has been implemented in ZBXNEXT-1274 ?
https://www.zabbix.com/documentation/3.4/manual/introduction/whatsnew340#configurable_jmx_endpoints
https://www.zabbix.com/documentation/3.4/manual/config/macros/lld_macros

glebs.ivanovskis No, it's a different story.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Jun 08 ]

Dear Gugli, quote after jmx_agent_name is not escaped.

Comment by Augugliaro [ 2017 Jun 08 ]

@Gelbs, I made a mistake on my example, I just edited it : char is well escaped on my JSON discovery return.
@Vladislavs, thanks, I'll read those KB tomorrow.

Unfortunately I'm working on a +25k objects in Zabbix infra, so I cant patch or update Zabbix like I wish. I hope I'll find some light workaround.
I'll keep you informed.

Comment by Augugliaro [ 2017 Jun 09 ]

As I thought, your documentation is for Zabbix 3.4 and I cant upgrade atm because of the
I'm looking for a quick change that allow Zabbix to get double-quote escaping in the JSON discovered.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Jun 09 ]

Dear Gugli, 2.2.6 is pretty old. Try minor upgrade to one of the latest 2.2.x.

Comment by Augugliaro [ 2017 Jun 27 ]

Hi,
Just to let you know (because I spent some hard times on this problem, and you too) : I fixed it !
Finaly, this wasnt a syntax problem that broke the LLD discovery but my calling of the script :/
In my .sh I was calling correctly java, but I used a relative path to locate the zabbix_jmxdiscovery external script. Even if it was in the same path, it couldnt work.

Thanks you all for your interest.
Julien

Comment by Rostislav Palivoda [ 2017 Jul 10 ]

Available in 3.4.0alpha1 r69863.

Generated at Sat Apr 20 02:41:17 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.