You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
<!-- Creates a MetricRegistry bean -->
<metrics:metric-registry id="metricRegistry" />
<!-- Creates a HealthCheckRegistry bean (Optional) -->
<metrics:health-check-registry id="health" />
<!-- Registers BeanPostProcessors with Spring which proxy beans and capture metrics -->
<!-- Include this once per context (once in the parent context and in any subcontexts) -->
<metrics:annotation-driven metric-registry="metricRegistry" />
<!-- Example reporter definiton. Supported reporters include jmx, slf4j, graphite, and others. -->
<!-- Reporters should be defined only once, preferably in the parent context -->
<metrics:reporter type="console" metric-registry="metricRegistry" period="5s" />
<!-- Register metric beans (Optional) -->
<!-- The metrics in this example require metrics-jvm -->
<metrics:register metric-registry="metricRegistry">
<bean metrics:name="jvm.count" id="advices" class="cn.com.servyou.alpha.aop.TheSets" />
</metrics:register>
register a set class TheSets implements the MetricSet,the class is like this:
public class TheSets implements MetricSet {
public static Map<String, Metric> metricMap = new LinkedHashMap<String, Metric>();
public Map<String, Metric> getMetrics() {
System.out.println("the set class is :" + this);
System.out.println("set map size is "+ metricMap.size());
metricMap.put("cc", new Counter());
return metricMap;
}
public static void increase(String key) {
if (metricMap.get(key) != null) {
Counter counter1 = (Counter)metricMap.get(key);
counter1.inc();
}else {
Counter counter2 = new Counter();
counter2.inc();
metricMap.put(key, counter2);
}
System.out.println("invoked map size is "+ metricMap.size());
}
}
and I invoke the increase method in another class , just like TheSets.increase("cc");.
this works.
but ,when I want to invoke the method with another arg , which like TheSets.increase("dd");. the result is I can't get the counter named with "dd",it seems like the put method on metricMap only works in the getMetrics method.
now I need to put some dynamic keys in the map, how can I make it? @ryantenney
thank you .
The text was updated successfully, but these errors were encountered:
I'm afraid that can't be done. The getMetrics method on a MetricSet is only ever invoked once. What you need to do is get a reference to the MetricRegistry and then replace the body of the increase method with the code: MetricRegistry.counter(key).inc();.
I make the simple xml spring config like this:
register a set class TheSets implements the MetricSet,the class is like this:
and I invoke the increase method in another class , just like
TheSets.increase("cc");
.this works.
but ,when I want to invoke the method with another arg , which like
TheSets.increase("dd");
. the result is I can't get the counter named with "dd",it seems like theput
method onmetricMap
only works in thegetMetrics
method.now I need to put some dynamic keys in the map, how can I make it? @ryantenney
thank you .
The text was updated successfully, but these errors were encountered: