Search in sources :

Example 1 with AsmMetric

use of com.alibaba.jstorm.common.metric.AsmMetric in project jstorm by alibaba.

the class TaskBaseMetric method findMetric.

private AsmMetric findMetric(String streamId, String name, MetricType metricType, boolean mergeTopology) {
    //String key = new StringBuilder(30).append(taskId).append(streamId).append(name).toString();
    String key = streamId + name;
    AsmMetric existingMetric = metricCache.get(key);
    if (existingMetric == null) {
        String fullName = MetricUtils.streamMetricName(topologyId, componentId, taskId, streamId, name, metricType);
        existingMetric = JStormMetrics.getStreamMetric(fullName);
        if (existingMetric == null) {
            existingMetric = AsmMetric.Builder.build(metricType);
            JStormMetrics.registerStreamMetric(fullName, existingMetric, mergeTopology);
        }
        AsmMetric oldMetric = metricCache.putIfAbsent(key, existingMetric);
        if (oldMetric != null) {
            existingMetric = oldMetric;
        }
    }
    return existingMetric;
}
Also used : AsmMetric(com.alibaba.jstorm.common.metric.AsmMetric)

Example 2 with AsmMetric

use of com.alibaba.jstorm.common.metric.AsmMetric in project jstorm by alibaba.

the class TaskBaseMetric method updateTime.

/**
     * almost the same implementation of above update, but improves performance for histograms
     */
public void updateTime(String streamId, String name, long start, long end, int count, boolean mergeTopology) {
    if (start > 0) {
        AsmMetric existingMetric = findMetric(streamId, name, MetricType.HISTOGRAM, mergeTopology);
        if (existingMetric instanceof AsmHistogram) {
            AsmHistogram histogram = (AsmHistogram) existingMetric;
            if (histogram.okToUpdate(end)) {
                long elapsed = ((end - start) * TimeUtils.US_PER_MS) / count;
                if (elapsed >= 0) {
                    histogram.update(elapsed);
                    histogram.setLastUpdateTime(end);
                }
            }
        }
    }
}
Also used : AsmMetric(com.alibaba.jstorm.common.metric.AsmMetric) AsmHistogram(com.alibaba.jstorm.common.metric.AsmHistogram)

Example 3 with AsmMetric

use of com.alibaba.jstorm.common.metric.AsmMetric in project jstorm by alibaba.

the class TaskBaseMetric method update.

public void update(final String streamId, final String name, final Number value, final MetricType metricType, boolean mergeTopology) {
    AsmMetric existingMetric = findMetric(streamId, name, metricType, mergeTopology);
    existingMetric.update(value);
}
Also used : AsmMetric(com.alibaba.jstorm.common.metric.AsmMetric)

Example 4 with AsmMetric

use of com.alibaba.jstorm.common.metric.AsmMetric in project jstorm by alibaba.

the class JStormMetricsReporter method updateMetricMeta.

/**
     * Register metric meta callback. Called in SpoutExecutors/BoltExecutors within topology workers.
     *
     * JStormMetricsReporter first sends a TOPOLOGY_MASTER_REGISTER_METRICS_STREAM_ID stream to TM to register metrics,
     * on success TM will return a TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID stream which contains
     * registered metric meta and then call this method to update local meta.
     */
public void updateMetricMeta(Map<String, Long> nameIdMap) {
    if (nameIdMap != null) {
        for (String name : nameIdMap.keySet()) {
            AsmMetric metric = JStormMetrics.find(name);
            if (metric != null) {
                long id = nameIdMap.get(name);
                metric.setMetricId(id);
                LOG.debug("set metric id, {}:{}", name, id);
            }
        }
    }
}
Also used : AsmMetric(com.alibaba.jstorm.common.metric.AsmMetric)

Example 5 with AsmMetric

use of com.alibaba.jstorm.common.metric.AsmMetric in project jstorm by alibaba.

the class JStormMetricsReporter method updateMetricConfig.

public void updateMetricConfig(Map newConf) {
    JStormMetrics.setDebug(ConfigExtension.isEnableMetricDebug(conf));
    JStormMetrics.addDebugMetrics(ConfigExtension.getDebugMetricNames(conf));
    //update metric accurate calculate
    boolean accurateMetric = ConfigExtension.getTopologyAccurateMetric(newConf);
    if (MetricUtils.metricAccurateCal != accurateMetric) {
        MetricUtils.metricAccurateCal = accurateMetric;
        LOG.info("switch topology metric accurate enable to {}", MetricUtils.metricAccurateCal);
    }
    // update enabled/disabled metrics
    String enabledMetrics = ConfigExtension.getEnabledMetricNames(newConf);
    String disabledMetrics = ConfigExtension.getDisabledMetricNames(newConf);
    if (enabledMetrics != null || disabledMetrics != null) {
        Set<String> enabledMetricSet = toSet(enabledMetrics, ",");
        Set<String> disabledMetricsSet = toSet(disabledMetrics, ",");
        AsmMetricRegistry[] registries = new AsmMetricRegistry[] { JStormMetrics.getTopologyMetrics(), JStormMetrics.getComponentMetrics(), JStormMetrics.getTaskMetrics(), JStormMetrics.getStreamMetrics(), JStormMetrics.getNettyMetrics(), JStormMetrics.getWorkerMetrics() };
        for (AsmMetricRegistry registry : registries) {
            Collection<AsmMetric> metrics = registry.getMetrics().values();
            for (AsmMetric metric : metrics) {
                String shortMetricName = metric.getShortName();
                if (enabledMetricSet.contains(shortMetricName)) {
                    metric.setEnabled(true);
                } else if (disabledMetricsSet.contains(shortMetricName)) {
                    metric.setEnabled(false);
                }
            }
        }
    }
    long updateInterval = ConfigExtension.getTimerUpdateInterval(newConf);
    if (updateInterval != AsmHistogram.getUpdateInterval()) {
        AsmHistogram.setUpdateInterval(updateInterval);
    }
    boolean enableStreamMetrics = ConfigExtension.isEnableStreamMetrics(newConf);
    if (enableStreamMetrics != JStormMetrics.enableStreamMetrics) {
        JStormMetrics.enableStreamMetrics = enableStreamMetrics;
        LOG.info("switch topology stream metric enable to {}", enableStreamMetrics);
    }
    boolean enableMetrics = ConfigExtension.isEnableMetrics(newConf);
    if (enableMetrics != JStormMetrics.enabled) {
        JStormMetrics.enabled = enableMetrics;
        LOG.info("switch topology metric enable to {}", enableMetrics);
    }
}
Also used : AsmMetric(com.alibaba.jstorm.common.metric.AsmMetric)

Aggregations

AsmMetric (com.alibaba.jstorm.common.metric.AsmMetric)5 AsmHistogram (com.alibaba.jstorm.common.metric.AsmHistogram)1