Skip to main content

A JMX Interface for Python to Query runtime metrics in a JVM

Project description

# 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
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jmxquery-0.3.0.tar.gz (20.3 kB view details)

Uploaded Source

File details

Details for the file jmxquery-0.3.0.tar.gz.

File metadata

  • Download URL: jmxquery-0.3.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jmxquery-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e89296b0cba859eba55e8f74fd4353bd84ad152f106f6dcf4c2ed564e7c64b2b
MD5 e120b7fb49fdfe6e4726ba8d1a7e0cdc
BLAKE2b-256 64ead23a3f032e607f48e02abbd432a9bb25ae1e818dc41a33e28784a47314b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page