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.6.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

jmxquery-0.6.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jmxquery-0.6.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for jmxquery-0.6.0.tar.gz
Algorithm Hash digest
SHA256 f0bdb002591eec6eea0e16546baa35448f8b66acaf6dd72ed049c3a666afc06b
MD5 dce3bff6e2c9539c000aa70eb59aa564
BLAKE2b-256 77e06b1648bb44eb2bdd778149a6f6100620db92161d3d55659ac1f51e95c69f

See more details on using hashes here.

File details

Details for the file jmxquery-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: jmxquery-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for jmxquery-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fb4644026bb2de7c1dbedc52f6cb8e3d56820859b7b03cb971c9c633c870a77
MD5 888139c0ae6bde00839bbc8492b42956
BLAKE2b-256 58a91f9fa3a6082d597b056b23098870856da6f2ba0dee943cfe2f9b572922f8

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