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-jcruz-0.5.3.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jmxquery_jcruz-0.5.3-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file jmxquery-jcruz-0.5.3.tar.gz.

File metadata

  • Download URL: jmxquery-jcruz-0.5.3.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4

File hashes

Hashes for jmxquery-jcruz-0.5.3.tar.gz
Algorithm Hash digest
SHA256 47b598da97dd223ad0ffaf497f917cd63a3ccef90f96e129dd7bf588afa17a83
MD5 390c5dd1a301c46701069f187aa5d940
BLAKE2b-256 c40b5039d3f5a745e1ea22f558252a13c4217c44411dff60847d2a95cfa0fb2c

See more details on using hashes here.

File details

Details for the file jmxquery_jcruz-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: jmxquery_jcruz-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4

File hashes

Hashes for jmxquery_jcruz-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 be2cda4f0312c520ee781fd251e7f6b65de87ef22fbb6364bbcb9f55b9c88d0e
MD5 98cfdf66fc563ce2dff27ce49079c651
BLAKE2b-256 afe4f9f64f11d3724cc133b52d6b6bf9bd0b24fb3c51e204fdb23f5997ee1cf5

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