@Retention(value=CLASS)
@Target(value=METHOD)
public @interface Telemetry
Only public static parameterless methods can be used for creating custom telemetries, annotating instance methods or non-public static methods will not have any effect. The method must return a numeric value, either a primitive value like int or double or a primitive wrapper instance like java.lang.Integer or java.lang.Double.
It is not sufficient if the the class containing the annotated method is present in the classpath. You have to make sure that the class is loaded at runtime, so perfino can intercept the class loading event and set up the custom telemetry.
The method is called periodically on a dedicated thread. This may have implications for the requirements of thread safety in your code. If the numeric value is calculated on the fly, access to the data structures must by made thread-safe by making access to those data structures synchronized. Alternatively, you could calculate a cached value when convenient and save it to a volatile atomic value, like an int or a class from the java.util.concurrent.atomic package.
In the perfino UI, the telemetry is shown in the VM data views under "Custom telemetries". In addition, you can choose custom telemetries as data sources for sparklines in the dashboard or in the VMs view.
For example, the following code snippet defines a custom telemetry with the name "Connection count":
@Telemetry("Connection count") public static int getConnectionCount() { return connectionCount; }
Multiple lines in a single custom telemetry
If you want to compare several measurements in the same telemetry, you can annotate multiple methods with the
same value()
for the telemetry name, but with a different line()
parameter.
For example:
@Telemetry(value = "Queries", line = "Successful queries") public static int getSuccessCount() { return successCount; } @Telemetry(value = "Queries", line = "Failed queries") public static int getErrorCount() { return errorCount; }
This will create a single custom telemetry with the name "Queries" and two data lines named "Successful queries" and "Failed queries".
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
value
The name of the telemetry.
|
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
line
The optional line name of the telemetry.
|
public abstract java.lang.String value
@Telemetry("Connection count")
public abstract java.lang.String line
Telemetry
for an example.