use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.
the class RefreshEvent method syncTopologyMeta.
/**
* sync topology metric meta from external storage like TDDL/OTS.
* nimbus server will skip syncing, only followers do this
*/
public void syncTopologyMeta() {
// sys meta, use remote only
syncSysMetaFromRemote();
// normal topology meta, local + remote
for (Entry<String, TopologyMetricContext> entry : context.getTopologyMetricContexts().entrySet()) {
String topologyId = entry.getKey();
TopologyMetricContext metricContext = entry.getValue();
if (!JStormMetrics.SYS_TOPOLOGY_SET.contains(topologyId)) {
try {
syncMetaFromCache(topologyId, metricContext);
syncMetaFromRemote(topologyId, metricContext);
} catch (Exception e1) {
LOG.warn("failed to sync meta for topology:{}", topologyId);
}
}
}
}
use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.
the class ClusterMetricsContext method registerMetrics.
public Map<String, Long> registerMetrics(String topologyId, Set<String> metricNames) {
TimeTicker ticker = new TimeTicker(TimeUnit.MILLISECONDS, true);
TopologyMetricContext topologyMetricContext = topologyMetricContexts.get(topologyId);
if (topologyMetricContext == null) {
LOG.warn("topology metrics context does not exist for topology:{}!!!", topologyId);
return new HashMap<>();
}
// if (!topologyMetricContext.finishSyncRemote()) {
// LOG.warn("waiting for topology {} to finish sync with remote.", topologyId);
// return new HashMap<>();
// }
ConcurrentMap<String, Long> memMeta = topologyMetricContexts.get(topologyId).getMemMeta();
Map<String, Long> ret = new HashMap<>();
for (String metricName : metricNames) {
Long id = memMeta.get(metricName);
if (id != null && MetricUtils.isValidId(id)) {
ret.put(metricName, id);
} else {
id = metricIDGenerator.genMetricId(metricName);
Long old = memMeta.putIfAbsent(metricName, id);
if (old == null) {
ret.put(metricName, id);
} else {
ret.put(metricName, old);
}
}
}
long cost = ticker.stop();
LOG.info("register metrics, topology:{}, size:{}, cost:{}", topologyId, metricNames.size(), cost);
return ret;
}
use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.
the class ClusterMetricsContext method deleteMetric.
public void deleteMetric(String topologyId, int metaType, List<String> idList) {
final TopologyMetricContext context = topologyMetricContexts.get(topologyId);
if (context != null) {
for (String id : idList) {
MetricMeta meta = metricQueryClient.getMetricMeta(clusterName, topologyId, MetaType.parse(metaType), id);
if (meta != null) {
LOG.warn("deleting metric meta:{}", meta);
metricQueryClient.deleteMeta(meta);
context.getMemMeta().remove(meta.getFQN());
metricCache.put(topologyId, context.getMemMeta());
} else {
LOG.warn("Failed to delete metric meta, topology:{}, metaType:{}, id:{}, meta not found", topologyId, metaType, id);
}
}
} else {
LOG.warn("Failed to delete metric meta, topology:{} doesn't exist!", topologyId);
}
}
use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.
the class RefreshEvent method syncTopologyMetaForFollower.
/**
* sync topology metric meta from external storage like TDDL/OTS.
* nimbus server will skip syncing, only followers do this
*/
public void syncTopologyMetaForFollower() {
// sys meta, use remote only
syncSysMetaFromRemote();
// normal topology meta, local + remote
for (Entry<String, TopologyMetricContext> entry : context.getTopologyMetricContexts().entrySet()) {
String topology = entry.getKey();
TopologyMetricContext metricContext = entry.getValue();
if (!JStormMetrics.SYS_TOPOLOGY_SET.contains(topology)) {
try {
syncMetaFromCache(topology, metricContext);
syncNonSysMetaFromRemote(topology, metricContext);
} catch (Exception e1) {
LOG.warn("failed to sync meta for topology:{}", topology);
}
}
}
}
use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.
the class StartTopologyEvent method run.
@Override
public void run() {
context.getMetricCache().putSampleRate(topologyId, sampleRate);
context.getMetricUploaderDelegate().sendEvent(context.getClusterName(), this);
if (!context.getTopologyMetricContexts().containsKey(topologyId)) {
TopologyMetricContext metricContext = new TopologyMetricContext();
// note that workerNum is not set here.
context.getTopologyMetricContexts().put(topologyId, metricContext);
}
}
Aggregations