Skip to main content
Time to read: 1 min

Exposing RSKj node metrics

1. Enable JMX for JConsole​

Java Management Extensions (JMX) can be used to expose metrics for tools like JConsole.

  1. 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 9010 with the desired port number.
  • For production environments, enable authentication and SSL for security.
  1. Start your node with the above options and connect to it using JConsole:
  • Open JConsole (jconsole command).
  • 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.

  1. Download the JMX Exporter Download the jmx_prometheus_javaagent JAR file from the releases page.

  2. Create a Configuration File Create a config.yaml file 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.
  1. 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.jar with the path to the downloaded jmx agent JAR file.
  • Replace 8080 with the port where the metrics will be exposed.
  • Replace /path/to/config.yaml with the path to the configuration file you created in the step 2.
  1. 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

3. Verify Metrics​

  • For JConsole: Open JConsole and verify the metrics under the MBeans tab.
  • For Prometheus: Access the metrics endpoint (e.g., http://localhost:8080/metrics) in your browser or use Prometheus to scrape the metrics.

4. Enable Emission of Custom JMX Metrics​

RSKj provides the ability to emit custom JMX metrics defined in the MetricKind enum. To enable this feature, follow these steps:

  1. Enable Profiling in the Configuration Update the reference.conf file or your custom configuration file to enable profiling:

    system {
    profiling {
    enabled = true
    }
    }

    alternatively, you can set the following system property when starting the node:

      -Dsystem.profiling.enabled=true
  2. Verify Metrics in JConsole

  • Start your RSKj node with the system.profiling.enabled=true configuration.
  • Open JConsole and connect to the node.
  • Navigate to the co.rsk.metrics.Jmx MBean to view the custom metrics defined in the MetricKind enum.
  1. Access Metrics via Prometheus JMX Exporter If you are using the Prometheus JMX Exporter, ensure that the exporter is configured to scrape the custom JMX metrics. The config.yaml file should include a rule to match the co.rsk.metrics.Jmx MBean:

    rules:
    - pattern: "co\\.rsk\\.metrics\\.Jmx<.*>"

    or enable all metrics with .* pattern:

    rules:
    - pattern: ".*"

    Restart the node with the JMX Exporter agent to expose the metrics for Prometheus.

Last updated on by github-actions[bot]

Feedback