|
| 1 | +# JMX Exporter |
| 2 | + |
| 3 | +## What is JMX Exporter |
| 4 | + |
| 5 | +JMX Exporter (also known as the JMX Prometheus Java Agent) is a Java agent that exposes JMX metrics of a Java application in a format Prometheus can scrape and monitor. It is a tool created by the Prometheus community that allows: |
| 6 | + |
| 7 | +* Access JVM internal metrics (like memory usage, thread count, GC stats, etc.) |
| 8 | +* Expose custom application metrics exposed via MBeans |
| 9 | +* Export these metrics via an HTTP endpoint (e.g., http://localhost:9404/metrics) |
| 10 | +* Integrate Java applications (like Kafka, Cassandra, or your own apps) into a Prometheus monitoring setupx |
| 11 | + |
| 12 | +This tool unlocks Prometheus + Graphana based monitoring for a SynchDB Connector |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Obtain JMX Exporter |
| 17 | + |
| 18 | +Pre-compiled JMX Exporter (.jar) are available on official [JMX Exporter release page](https://github.com/prometheus/jmx_exporter/releases). We are interested in the "jmx_prometheus_javaagent" tool such as: |
| 19 | + |
| 20 | +``` |
| 21 | +jmx_prometheus_javaagent-1.3.0.jar |
| 22 | +
|
| 23 | +``` |
| 24 | + |
| 25 | +Please download it to the same machine where SynchDB connector is running. |
| 26 | + |
| 27 | +## Write a JMX Exporter Conf File |
| 28 | + |
| 29 | +JMX exporter requires a config file to define the behavior of exposing metrics. Below is a basic configuration template to get started. |
| 30 | + |
| 31 | +``` |
| 32 | +startDelaySeconds: 0 |
| 33 | +ssl: false |
| 34 | +lowercaseOutputName: true |
| 35 | +lowercaseOutputLabelNames: true |
| 36 | +
|
| 37 | +rules: |
| 38 | + - pattern: ".*" |
| 39 | +
|
| 40 | +``` |
| 41 | + |
| 42 | +Refer to the [official prometheus documentation](https://prometheus.github.io/jmx_exporter/1.3.0/http-mode/rules/) for more advanced configuration parameters and their usage. |
| 43 | + |
| 44 | +## Configure JMX Exporter to a SynchDB Connector |
| 45 | + |
| 46 | +The synchdb_add_jmx_exporter_conninfo() and synchdb_del_jmx_exporter_conninfo() functions adds or deletes JMX exporter configuration to or from an existing connector. This enables runtime monitoring and diagnostics via tools like Prometheus and Graphana. |
| 47 | + |
| 48 | +**Function Signature** |
| 49 | + |
| 50 | +``` |
| 51 | +synchdb_add_jmx_exporter_conninfo( |
| 52 | + connector_name TEXT, |
| 53 | + exporter_jar_path TEXT, |
| 54 | + exporter_port INTEGER, |
| 55 | + config_file_path TEXT |
| 56 | +); |
| 57 | +
|
| 58 | +synchdb_del_jmx_exporter_conninfo( |
| 59 | + name text |
| 60 | +) |
| 61 | +
|
| 62 | +``` |
| 63 | + |
| 64 | +| Parameter | Type | Description | |
| 65 | +| ------------------- | ------ | --------------------------------------------------------------------------- | |
| 66 | +| `connector_name` | `TEXT` | Name of the existing connector you want to attach the JMX Exporter to. | |
| 67 | +| `exporter_jar_path` | `TEXT` | Absolute path to the `jmx_prometheus_javaagent.jar` file. | |
| 68 | +| `exporter_port` | `INT` | Port on which the JMX Exporter HTTP server will expose metrics (e.g. 9404). | |
| 69 | +| `config_file_path` | `TEXT` | Path to the JMX Exporter's YAML configuration file we defined above. | |
| 70 | + |
| 71 | + |
| 72 | +```sql |
| 73 | +SELECT synchdb_add_jmx_exporter_conninfo( |
| 74 | + 'mysqlconn', -- existing connector name |
| 75 | + '/path/to/jmx_exporter/jar' -- path to JMX exporter java agent jar |
| 76 | + 9404, -- JMX exporter running port |
| 77 | + '/path/to/jmx/conf'); -- path to JMX exporter conf file |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +## Obtain Metrics via HTTP |
| 82 | + |
| 83 | +when the connector starts with JMX exporter settings, it will expose metrics at: |
| 84 | + |
| 85 | +``` |
| 86 | +http://<host>:9404/metrics |
| 87 | +``` |
| 88 | + |
| 89 | +we can test it by: |
| 90 | + |
| 91 | +``` |
| 92 | +curl http://<host>:9404/metrics |
| 93 | +
|
| 94 | +# HELP debezium_mysql_connector_metrics_binlogposition debezium.mysql:name=null,type=connector-metrics,attribute=BinlogPosition |
| 95 | +# TYPE debezium_mysql_connector_metrics_binlogposition untyped |
| 96 | +debezium_mysql_connector_metrics_binlogposition{context="streaming",server="synchdb-connector"} 1500.0 |
| 97 | +# HELP debezium_mysql_connector_metrics_changesapplied debezium.mysql:name=null,type=connector-metrics,attribute=ChangesApplied |
| 98 | +# TYPE debezium_mysql_connector_metrics_changesapplied untyped |
| 99 | +debezium_mysql_connector_metrics_changesapplied{context="schema-history",server="synchdb-connector"} 39.0 |
| 100 | +# HELP debezium_mysql_connector_metrics_changesrecovered debezium.mysql:name=null,type=connector-metrics,attribute=ChangesRecovered |
| 101 | +# TYPE debezium_mysql_connector_metrics_changesrecovered untyped |
| 102 | +debezium_mysql_connector_metrics_changesrecovered{context="schema-history",server="synchdb-connector"} 26.0 |
| 103 | +# HELP debezium_mysql_connector_metrics_connected debezium.mysql:name=null,type=connector-metrics,attribute=Connected |
| 104 | +# TYPE debezium_mysql_connector_metrics_connected untyped |
| 105 | +debezium_mysql_connector_metrics_connected{context="streaming",server="synchdb-connector"} 1.0 |
| 106 | +
|
| 107 | +... |
| 108 | +... |
| 109 | +... |
| 110 | +``` |
| 111 | + |
| 112 | +## Prometheus and Graphana |
| 113 | + |
| 114 | +Once we have confirmed the metrics can be obtained via HTTP, then we can configure this endpoint to prometheus system and have it to `scrape` them all. Then we can create a prometheus data source in graphana and create a dashboard out of it. Please refer to prometheus and graphana [tutorial](https://grafana.com/docs/grafana/latest/getting-started/get-started-grafana-prometheus/) on how to do so. |
0 commit comments