Exposing RSKj node metrics
1. Enable JMX for JConsole
Java Management Extensions (JMX) can be used to expose metrics for tools like JConsole.
-
Add the following JVM options when starting your RSKj node to enable JMX:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
- Replace
9010with the desired port number. - For production environments, enable authentication and SSL for security.
- Start your node with the above options and connect to it using JConsole:
- Open JConsole (
jconsolecommand). - Enter the hostname and port (e.g.,
localhost:9010).
Note: For more details on using JConsole, refer to the official documentation: JConsole Documentation.
2. Expose Metrics for Prometheus Using Prometheus JMX Exporter
To expose metrics for Prometheus, you can use the Prometheus JMX Exporter, which acts as a Java agent to scrape JMX metrics and expose them via an HTTP endpoint.
-
Download the JMX Exporter Download the
jmx_prometheus_javaagentJAR file from the releases page. -
Create a Configuration File Create a
config.yamlfile to define the metrics you want to expose. Below is an example configuration:rules:
- pattern: ".*"
- This configuration exposes all available JMX metrics. You can customize it to include only specific metrics.
-
Add the JMX Exporter as a Java Agent Add the following JVM option when starting your RSKj node:
-javaagent:/path/to/jmx_prometheus_javaagent.jar=8080:/path/to/config.yaml
- Replace
/path/to/jmx_prometheus_javaagent.jarwith the path to the downloaded jmx agent JAR file. - Replace
8080with the port where the metrics will be exposed. - Replace
/path/to/config.yamlwith the path to the configuration file you created in the step 2.
-
Run Prometheus Configure Prometheus to scrape metrics from your node by adding the following to your
prometheus.yml:scrape_configs:
- job_name: 'rskj'
static_configs:
- targets: ['localhost:8080'] # Replace it with the host and port of your node where metrics are exposed