use of com.alibaba.jstorm.metric.MetricQueryClient in project jstorm by alibaba.
the class CheckMetricEvent method run.
@Override
public void run() {
try {
MetricQueryClient metricQueryClient = context.getMetricQueryClient();
int batch = 30;
long start = System.currentTimeMillis() - batch * AsmWindow.M1_WINDOW * TimeUtils.MS_PER_SEC;
long end = System.currentTimeMillis();
List<MetricMeta> toDelete = new ArrayList<>();
for (Pair<MetricMeta, Long> pair : pairs) {
MetricMeta meta = pair.getFirst();
MetricType metricType = MetricType.parse(meta.getMetricType());
Long id1 = meta.getId();
Long id2 = pair.getSecond();
List<Object> data1 = metricQueryClient.getMetricData(id1, metricType, AsmWindow.M1_WINDOW, start, end, batch);
List<Object> data2 = metricQueryClient.getMetricData(id2, metricType, AsmWindow.M1_WINDOW, start, end, batch);
int size1 = data1 != null ? data1.size() : 0;
int size2 = data2 != null ? data2.size() : 0;
LOG.info("check duplicate metric meta for {}, id1:{}, size:{}, id2:{}, size:{}", meta.getMetricName(), id1, size1, id2, size2);
if (size1 > size2) {
// delete id2
meta.setId(id2);
toDelete.add(meta);
tmContext.getMemMeta().put(meta.getFQN(), id1);
} else {
// delete id1
toDelete.add(meta);
tmContext.getMemMeta().put(meta.getFQN(), id2);
}
}
if (toDelete.size() > 0) {
LOG.warn("will delete the following duplicate metric meta\n----------------------------\n");
for (MetricMeta meta : toDelete) {
LOG.warn("metric:{}, id:{}", meta.getFQN(), meta.getId());
}
LOG.info("\n");
metricQueryClient.deleteMeta(toDelete);
}
//context.getMetricCache().putMeta(topologyId, tmContext.getMemMeta());
//context.getStormClusterState().set_topology_metric(topologyId, zkSize - dupMetaList.size());
} catch (Exception ex) {
LOG.error("Error", ex);
}
}
Aggregations