Search in sources :

Example 1 with TimeTicker

use of com.alibaba.jstorm.metric.TimeTicker 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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext) TimeTicker(com.alibaba.jstorm.metric.TimeTicker)

Example 2 with TimeTicker

use of com.alibaba.jstorm.metric.TimeTicker in project jstorm by alibaba.

the class RefreshEvent method refreshTopologies.

/**
     * refresh metric settings of topologies & metric meta
     */
public void refreshTopologies() {
    TimeTicker ticker = new TimeTicker(TimeUnit.MILLISECONDS, true);
    try {
        doRefreshTopologies();
        LOG.debug("Refresh topologies, cost:{}", ticker.stopAndRestart());
        if (!context.getNimbusData().isLeader()) {
            syncTopologyMeta();
            LOG.debug("Sync topology meta, cost:{}", ticker.stop());
        } else if (context.getNimbusData().uptime() < SYNC_REMOTE_META_TIME_SEC) {
            syncSysMetaFromRemote();
        }
    } catch (Exception ex) {
        LOG.error("handleRefreshEvent error:", ex);
    }
}
Also used : TimeTicker(com.alibaba.jstorm.metric.TimeTicker)

Aggregations

TimeTicker (com.alibaba.jstorm.metric.TimeTicker)2 TopologyMetricContext (com.alibaba.jstorm.metric.TopologyMetricContext)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1