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.1.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.1.0
File Size Uploaded Provenance Actions
jmxquery-0.1.0.tar.gz 19.9 kB Without provenance Details for jmxquery-0.1.0.tar.gz

Release files / jmxquery-0.1.0.tar.gz

Download URL jmxquery-0.1.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d6b457df3dd156f2b88eb01412faceaef7c3071626541d420b9ccaccd27c9294
BLAKE2b-256 checksum
How to use checksums
5fd201905ba1b120eccaeae6d0b55c5c6fff540d33830d44d58aed36a60a0b69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for jmxquery 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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