[clusterinfo] Add metrics example
example, an implementation could expose JMX metrics together with a
type-safe DTO:</para>
- <programlisting>
- public class JMXMetricsDTO extends DTO {
-
+ <programlisting>public class JMXMetricsDTO extends DTO {
/**
* The number of processors available
*/
* The amount of non-heap memory used by the JVM
*/
public long nonHeapMemoryUsed;
+}</programlisting>
+ <para>Such DTO can be used to obtain metrics from a <code>NodeStatus</code> service as follows:
+ <programlisting>NodeStatus ns = ...; // From service registry
+Map&lt;String, ?&gt; metrics = ns.getMetrics(); // Obtain all metrics for this node
- }
+// Convert the metrics map to a DTO for type-safe access
+JMXMetricsDTO dto = Converters.standardConverter().convert(metrics)
+ .to(JMXMetricsDTO.class);
+
+// Use metrics
+System.out.println("System Load Average: " + dto.systemLoadAverage);
</programlisting>
+ </para>
</section>
<section>
