Skip to main content

JMXQuery Python Module

Provides a Python module to easily run queries and collect metrics from a Java Virtual Machine via JMX.

In order to use this module, provide a list of queries, and the module will return all of the values it finds matching the query. Please note that the interfact to the JMX uses a small jar file contained in this module, so you will need to have java installed on the machine you're running this module on.

Usage

This example query for a Kafka server will get all cluster partition metrics:

jmxConnection = JMXConnection("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi")
jmxQuery = [JMXQuery("kafka.cluster:type=*,name=*,topic=*,partition=*",
                         metric_name="kafka_cluster_{type}_{name}",
                         metric_labels={"topic" : "{topic}", "partition" : "{partition}"})]
metrics = jmxConnection.query(jmxQuery)
for metric in metrics:
    print(f"{metric.metric_name}<{metric.metric_labels}> == {metric.value}")

This will return the following:

kafka_cluster_Partition_UnderReplicated<{'partition': '0', 'topic': 'test'}> == 0
kafka_cluster_Partition_UnderMinIsr<{'partition': '0', 'topic': 'test'}> == 0
kafka_cluster_Partition_InSyncReplicasCount<{'partition': '0', 'topic': 'test'}> == 1
kafka_cluster_Partition_ReplicasCount<{'partition': '0', 'topic': 'test'}> == 1
kafka_cluster_Partition_LastStableOffsetLag<{'partition': '0', 'topic': 'test'}> == 0

As you will notice you can optionally send a metric_name and metric_labels with {} tokens in them. These tokens are replaced at runtime by the jar so you can easily build metric names with associated labels using the MBean properties of the values your query pulls back.

You can also use the module to pull back a list of all the MBean values available in the JVM too:

jmxConnection = JMXConnection("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi")
jmxQuery = [JMXQuery("*:*")]
metrics = jmxConnection.query(jmxQuery)
for metric in metrics:
    print(f"{metric.to_query_string()} ({metric.value_type}) = {metric.value}")

Installation

Just use pip to install the module in your Python environment:

pip install jmxquery

Metadata

Release files for jmxquery 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jmxquery 0.6.0
File Size Uploaded
jmxquery-0.6.0.tar.gz 20.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jmxquery 0.6.0
File Interpreter ABI Platform
jmxquery-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.9 kB

Release files / jmxquery-0.6.0.tar.gz

Download URL jmxquery-0.6.0.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f0bdb002591eec6eea0e16546baa35448f8b66acaf6dd72ed049c3a666afc06b
BLAKE2b-256 checksum
How to use checksums
77e06b1648bb44eb2bdd778149a6f6100620db92161d3d55659ac1f51e95c69f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.6

Release files / jmxquery-0.6.0-py3-none-any.whl

Download URL jmxquery-0.6.0-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fb4644026bb2de7c1dbedc52f6cb8e3d56820859b7b03cb971c9c633c870a77
BLAKE2b-256 checksum
How to use checksums
58a91f9fa3a6082d597b056b23098870856da6f2ba0dee943cfe2f9b572922f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page