public interface Metric
Metric
is used to measure the application and framework performance.
Two kinds of metrics are been implemented in ActFramework:
ActFramework supports hierarchical metric. For example, suppose you want to measure the time spent on direct web request handling and background jobs:
measure direct request handling
@PostAction("/xyz")
public void handleXyzRequest(String param) {
Timer timer = metric.startTimer("direct_req_handling:xyz");
try {
// your logic to handle xyz request
} finally {
timer.stop();
}
}
measure a background job
@Every("1hr")
public void scanDatabase() {
Timer timer = metric.startTimer("background_job:scan_db");
try {
// your logic to scan database
} finally {
timer.stop();
}
}
In the sample code shown above, the name used to start timers are direct_req_handling:xyz
and background_job:scan_db
respectively. Both name contains a metric hierarchy, say direct_req_handling
followed by xyz
and background_job
followed by scan_db
. The benefit of metric hierarchy is the value measured on child name will get aggregated automatically on parent name: Suppose you have two counters: “a:b”: 100, and “a:c”: 105, then your “a” counter will be 205.
Modifier and Type | Field and Description |
---|---|
static Metric |
NULL_METRIC
The do-nothing metric instance
|
static String |
PATH_SEPARATOR
PATH_SEPARATOR is provided to support hierarchical metric |
Modifier and Type | Method and Description |
---|---|
void |
countOnce(String name)
Call this method to increase one time for the counter specified
|
Timer |
startTimer(String name)
Call this method to start a
Timer before starting a process. |
static final String PATH_SEPARATOR
PATH_SEPARATOR
is provided to support hierarchical metric
static final Metric NULL_METRIC
The do-nothing metric instance
void countOnce(String name)
Call this method to increase one time for the counter specified
name
- A string specifies the counterTimer startTimer(String name)
Call this method to start a Timer
before starting a process.
Note calling this method should automatically call countOnce(String)
method with the name
specified
name
- A string specifies the timerCopyright © 2014–2018 ActFramework. All rights reserved.