use of com.usthe.collector.collect.AbstractCollect in project hertzbeat by dromara.
the class MetricsCollect method run.
@Override
public void run() {
this.startTime = System.currentTimeMillis();
setNewThreadName(monitorId, app, startTime, metrics);
CollectRep.MetricsData.Builder response = CollectRep.MetricsData.newBuilder();
response.setApp(app);
response.setId(monitorId);
response.setMetrics(metrics.getName());
// According to the indicator group collection protocol, application type, etc., dispatch to the real application indicator group collection implementation class
// 根据指标组采集协议,应用类型等来调度到真正的应用指标组采集实现类
AbstractCollect abstractCollect = null;
switch(metrics.getProtocol()) {
case DispatchConstants.PROTOCOL_HTTP:
abstractCollect = HttpCollectImpl.getInstance();
break;
case DispatchConstants.PROTOCOL_ICMP:
abstractCollect = IcmpCollectImpl.getInstance();
break;
case DispatchConstants.PROTOCOL_TELNET:
abstractCollect = TelnetCollectImpl.getInstance();
break;
case DispatchConstants.PROTOCOL_JDBC:
abstractCollect = JdbcCommonCollect.getInstance();
break;
case DispatchConstants.PROTOCOL_SSH:
abstractCollect = SshCollectImpl.getInstance();
break;
case DispatchConstants.PROTOCOL_REDIS:
abstractCollect = RedisSingleCollectImpl.getInstance();
// todo
default:
break;
}
if (abstractCollect == null) {
log.error("[Dispatcher] - not support this: app: {}, metrics: {}, protocol: {}.", app, metrics.getName(), metrics.getProtocol());
response.setCode(CollectRep.Code.FAIL);
response.setMsg("not support " + app + ", " + metrics.getName() + ", " + metrics.getProtocol());
return;
} else {
try {
abstractCollect.collect(response, monitorId, app, metrics);
} catch (Exception e) {
String msg = e.getMessage();
if (msg == null && e.getCause() != null) {
msg = e.getCause().getMessage();
}
log.error("[Metrics Collect]: {}.", msg, e);
response.setCode(CollectRep.Code.FAIL);
if (msg != null) {
response.setMsg(msg);
}
}
}
// 别名属性表达式替换计算
if (fastFailed()) {
return;
}
calculateFields(metrics, response);
CollectRep.MetricsData metricsData = validateResponse(response);
collectDataDispatch.dispatchCollectData(timeout, metrics, metricsData);
}
Aggregations