use of com.alibaba.metrics.MetricName in project dubbo by alibaba.
the class MetricsFilterTest method testConsumerSuccess.
public void testConsumerSuccess() throws Exception {
IMetricManager metricManager = MetricManager.getIMetricManager();
metricManager.clear();
MetricsFilter metricsFilter = new MetricsFilter();
Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), "", new Class<?>[] { Integer.class }, new Object[0]);
RpcContext.getContext().setRemoteAddress(host, url.getPort()).setLocalAddress(host, NetUtils.getAvailablePort());
RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE));
AppResponse response = AppResponseBuilder.create().build();
onInvokeReturns(response);
for (int i = 0; i < 100; i++) {
metricsFilter.invoke(serviceInvoker, invocation);
}
FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR));
FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER_METHOD, new HashMap<String, String>(4) {
{
put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
put(METHOD, "void sayName(Integer)");
}
}, MetricLevel.NORMAL));
long timestamp = System.currentTimeMillis() / 5000 * 5000;
Assertions.assertEquals(100, dubboClient.getMethodCountPerCategory(0).get("success").get(timestamp));
timestamp = timestamp / 15000 * 15000;
Assertions.assertEquals(100, dubboMethod.getMethodCountPerCategory(0).get("success").get(timestamp));
}
use of com.alibaba.metrics.MetricName in project dubbo by alibaba.
the class MetricsFilter method reportMetrics.
private void reportMetrics(Invoker<?> invoker, Invocation invocation, long duration, String result, boolean isProvider) {
String serviceName = invoker.getInterface().getName();
String methodName = buildMethodName(invocation);
MetricName global;
MetricName method;
if (isProvider) {
global = new MetricName(DUBBO_PROVIDER, MetricLevel.MAJOR);
method = new MetricName(DUBBO_PROVIDER_METHOD, new HashMap<String, String>(4) {
{
put(SERVICE, serviceName);
put(METHOD, methodName);
}
}, MetricLevel.NORMAL);
} else {
global = new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR);
method = new MetricName(DUBBO_CONSUMER_METHOD, new HashMap<String, String>(4) {
{
put(SERVICE, serviceName);
put(METHOD, methodName);
}
}, MetricLevel.NORMAL);
}
setCompassQuantity(DUBBO_GROUP, result, duration, global, method);
}
use of com.alibaba.metrics.MetricName in project dubbo by alibaba.
the class MetricsFilterTest method testConsumerTimeout.
public void testConsumerTimeout() {
IMetricManager metricManager = MetricManager.getIMetricManager();
metricManager.clear();
MetricsFilter metricsFilter = new MetricsFilter();
Invocation invocation = new RpcInvocation("timeoutException", DemoService.class.getName(), "", null, null);
RpcContext.getContext().setRemoteAddress(host, url.getPort()).setLocalAddress(host, NetUtils.getAvailablePort());
RpcContext.getContext().setUrl(timeoutInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE).addParameter(TIMEOUT_KEY, 300));
AppResponse response = AppResponseBuilder.create().build();
onInvokeReturns(response);
for (int i = 0; i < 10; i++) {
try {
metricsFilter.invoke(timeoutInvoker, invocation);
} catch (RpcException e) {
// ignore
}
}
FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR));
FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER_METHOD, new HashMap<String, String>(4) {
{
put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
put(METHOD, "void timeoutException()");
}
}, MetricLevel.NORMAL));
long timestamp = System.currentTimeMillis() / 5000 * 5000;
Assertions.assertEquals(10, dubboClient.getMethodCountPerCategory(0).get("timeoutError").get(timestamp));
timestamp = timestamp / 15000 * 15000;
Assertions.assertEquals(10, dubboMethod.getMethodCountPerCategory(0).get("timeoutError").get(timestamp));
}
use of com.alibaba.metrics.MetricName in project dubbo by alibaba.
the class MetricsFilterTest method testProviderSuccess.
public void testProviderSuccess() throws Exception {
IMetricManager metricManager = MetricManager.getIMetricManager();
metricManager.clear();
MetricsFilter metricsFilter = new MetricsFilter();
Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
RpcContext.getContext().setRemoteAddress(host, url.getPort()).setLocalAddress(host, NetUtils.getAvailablePort());
RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER));
AppResponse response = AppResponseBuilder.create().build();
onInvokeReturns(response);
for (int i = 0; i < 100; i++) {
metricsFilter.invoke(serviceInvoker, invocation);
}
FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER, MetricLevel.MAJOR));
FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER_METHOD, new HashMap<String, String>(4) {
{
put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
put(METHOD, "void sayName()");
}
}, MetricLevel.NORMAL));
long timestamp = System.currentTimeMillis() / 5000 * 5000;
Assertions.assertEquals(100, dubboClient.getMethodCountPerCategory(0).get("success").get(timestamp));
timestamp = timestamp / 15000 * 15000;
Assertions.assertEquals(100, dubboMethod.getMethodCountPerCategory(0).get("success").get(timestamp));
}
use of com.alibaba.metrics.MetricName in project dubbo by alibaba.
the class MetricsFilter method setCompassQuantity.
private void setCompassQuantity(String groupName, String result, long duration, MetricName... metricNames) {
for (MetricName metricName : metricNames) {
FastCompass compass = MetricManager.getFastCompass(groupName, metricName);
compass.record(duration, result);
}
}
Aggregations