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
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:
-
Enable Profiling in the Configuration Update the
reference.conffile 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 -
Verify Metrics in JConsole
- Start your RSKj node with the
system.profiling.enabled=trueconfiguration. - Open JConsole and connect to the node.
- Navigate to the
co.rsk.metrics.JmxMBean to view the custom metrics defined in theMetricKindenum.
-
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.yamlfile should include a rule to match theco.rsk.metrics.JmxMBean: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.