Realization

Custom metrics are realized by storing the [name-value] pairs of metrics into JVM SystemProperties. The Monitor Agent shall periodically capture SystemProperty prefixed with mo@.

1. Realized by Users

As shown in Definition, the format of custom metric names shall be

mo@indicator name

Take the user access metric in UAV as an example:

final String METRIC_24HOURUSERLOGIN = "mo@M24hr_UsrLog";

The metric value is initialized as 0:

AtomicLong userCount=new AtomicLong(0);

The metric value shall increment by 1 when the condition is met (user login):

userCount.getAndAdd(1);

Write the metric into system properties:

System.getProperties().put(METRIC_24HOURUSERLOGIN , userCount);

Delete the custom metric from the system configuration if the metric is not used in future:

System.getProperties().remove(METRIC_24HOURUSERLOGIN );

2. Realized via UAV Tools

Simple Monitor is the simple encapsulation class of custom metrics provided by UAV and is easy to use:

  • First, get a SimpleMonitor instance:
SimpleMonitor monitor = SimpleMonitor.getMonitor(monitorID);

getMonitor shall generate a singleton labeled as monitorID (a string). Corresponding SimpleMonitor instance at any place of the program can be accessed via monitorID.

  • Define custom metric constants (optional):
private static final String CUSTOM_MONITOR_Metric="My_Metric";

The Simple Monitor shall automatically add the prefix "mo@” to custom metrics.

  • Below are three methods to count metric values:
monitor.sumValue(CUSTOM_MONITOR_Metric,10);//atomic_adding
monitor.setValue(CUSTOM_MONITOR_Metric,1); //direct_value_modification
monitor.increValue(CUSTOM_MONITOR_Metric); //atomic_adding_by_1
  • Refresh to SystemProperties: custom metrics can be captured only after being refreshed to SystemProperties
monitor.flushToSystemProperties(CUSTOM_MONITOR_Metric);
If flushToSystemProperties has specified a group of custom metrics, then only refresh this metric group to SystemProperties 
If flushToSystemProperties is null, then refresh all metrics to SystemProperties
  • Delete the custom metric if it shall not be used in future:
monitor.removeMetric(CUSTOM_MONITOR_Metric);
Other Options (optional)

setValueSumBySeconds(String key, Long timeUnit, int lastRecordNumber) denotes to set a record list with timeUnit as the time unit and lastRecordNumber as the unit count for the metric key. Record the final value of the metric key at the end of each time unit and set the metric value back to 0. Save final values of lastRecordNumber time units in the local memory. Such values shall not be captured.

results matching ""

    No results matching ""