com.logicbus.backend.bizlog.handler.ServiceBizLogger Maven / Gradle / Ivy
package com.logicbus.backend.bizlog.handler;
import com.anysoft.util.PropertiesConstants;
import org.w3c.dom.Element;
import com.anysoft.rrm.RRData;
import com.anysoft.rrm.RRDataHandlerFactory;
import com.anysoft.rrm.ServiceMetrics;
import com.anysoft.stream.AbstractHandler;
import com.anysoft.stream.Handler;
import com.anysoft.util.Properties;
import com.logicbus.backend.bizlog.BizLogItem;
import com.logicbus.backend.bizlog.BizLogger;
/**
* 针对BizLog统计服务指标
* @author duanwaiwai
* @since 1.6.12.34 [20190507]
*
* @version 1.6.16.13
* - 增加sumAll配置,用于标记是否累加/all指标
*/
public class ServiceBizLogger extends AbstractHandlerimplements BizLogger {
protected boolean sumAll = true;
protected Handler handler = RRDataHandlerFactory.getHandler();
protected String getMetricsId(String svcId){
return "svc.thpt:" + svcId;
}
protected void onHandle(BizLogItem data, long t) {
if (handler != null){
String id = data.id;
// 统计服务调用次数
String metricsId = getMetricsId(id);
ServiceMetrics sm = new ServiceMetrics(metricsId,id);
sm.count(data.duration, !data.result.equals("core.ok"));
handler.handle(sm, t);
if (sumAll) {
ServiceMetrics total = new ServiceMetrics("metrics.service", "/all");
total.count(data.duration, !data.result.equals("core.ok"));
handler.handle(total, t);
}
}
}
protected void onFlush(long t) {
// 没有什么可以flush的
}
protected void onConfigure(Element e, Properties p) {
sumAll = PropertiesConstants.getBoolean(p,"sumAll",sumAll);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy