Repository navigation
Expand file tree
/
Copy pathMetricAdmin.java
More file actions
88 lines (80 loc) · 3.17 KB
/
Copy pathMetricAdmin.java
File metadata and controls
88 lines (80 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package act.metric;
import act.Act;
import act.cli.Command;
import act.cli.Optional;
import act.util.PropertySpec;
import org.osgl.$;
import org.osgl.util.C;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;
/**
* Console app to access actframework metric data
*/
public class MetricAdmin {
@Command(name = "act.metric.counter.list", help = "list all counters")
@PropertySpec("name,count")
public Object getCounters(
@Optional("specify maximum items returned") Integer limit,
@Optional("display in tree view") boolean tree,
@Optional("specify depth of levels") Integer depth,
@Optional("specify search string") String q
) {
List<MetricInfo> list = Act.metricPlugin().metricStore().timers();
return process(list, limit, q, tree, depth, MetricInfo.Comparator.COUNTER, MetricInfoTree.COUNTER);
}
@Command(name = "act.metric.timer.list", help = "list all timers")
@PropertySpec("name,accumulated,count,avg")
public Object getTimers(
@Optional("specify maximum items returned") Integer limit,
@Optional("display in tree view") boolean tree,
@Optional("specify depth of levels") Integer depth,
@Optional("specify search string") String q
) {
List<MetricInfo> list = Act.metricPlugin().metricStore().timers();
return process(list, limit, q, tree, depth, MetricInfo.Comparator.TIMER, MetricInfoTree.TIMER);
}
@Command(name = "act.metric.clear", help = "clear existing metric data")
public void clearMetricData() {
Act.metricPlugin().metricStore().clear();
}
private Object process(List<MetricInfo> list, Integer max, final String q,
boolean asTree, final Integer level, Comparator<MetricInfo> comp,
MetricInfoTree.NodeDecorator decorator) {
$.Predicate<String> filter = $.F.yes();
if (null != level) {
filter = (new $.Predicate<String>() {
@Override
public boolean test(String path) {
String[] sa = path.split(Metric.PATH_SEPARATOR);
return sa.length <= level;
}
});
}
if (null != q) {
final Pattern p = Pattern.compile(q);
filter = filter.and(new $.Predicate<String>() {
@Override
public boolean test(String path) {
return path.contains(q) || p.matcher(path).matches();
}
});
}
final $.Predicate<String> theFilter = filter;
if (!asTree) {
list = C.list(list).filter(new $.Predicate<MetricInfo>() {
@Override
public boolean test(MetricInfo metricInfo) {
return theFilter.test(metricInfo.getName());
}
});
if (null == max) {
return C.list(list).sorted(comp);
}
return C.list(list).take(max).sorted(comp);
} else {
MetricInfoTree tree = new MetricInfoTree(list, theFilter);
return tree.root(decorator);
}
}
}