Search in sources :

Example 1 with TopologyMetricDataInfo

use of com.alibaba.jstorm.daemon.nimbus.metric.uploader.TopologyMetricDataInfo in project jstorm by alibaba.

the class UpdateEvent method run.

/**
     * put metric data to metric cache.
     */
@Override
public void run() {
    if (!context.getTopologyMetricContexts().containsKey(topologyId)) {
        LOG.warn("topology {} has been killed or has not started, skip update.", topologyId);
        return;
    }
    // double check and reset stream metrics if disabled
    if (!JStormMetrics.enableStreamMetrics) {
        topologyMetrics.set_streamMetric(new MetricInfo());
    }
    if (!JStormMetrics.CLUSTER_METRIC_KEY.equals(topologyId)) {
        updateClusterMetrics(topologyId, topologyMetrics);
    }
    // overwrite nimbus-local metrics data
    context.getMetricCache().putMetricData(topologyId, topologyMetrics);
    // below process is kind of a transaction, first we lock an empty slot, mark it as PRE_SET
    // by this time the slot is not yet ready for uploading as the upload thread looks for SET slots only
    // after all metrics data has been saved, we mark it as SET, then it's ready for uploading.
    int idx = context.getAndPresetFirstEmptyIndex();
    if (idx < 0) {
        LOG.error("Exceeding maxPendingUploadMetrics(too much metrics in local rocksdb), " + "skip caching metrics data for topology:{}", topologyId);
        return;
    }
    TopologyMetricDataInfo summary = new TopologyMetricDataInfo();
    int total = 0;
    summary.topologyId = topologyId;
    summary.timestamp = timestamp;
    if (topologyId.equals(JStormMetrics.NIMBUS_METRIC_KEY) || topologyId.equals(JStormMetrics.CLUSTER_METRIC_KEY)) {
        summary.type = MetricUploader.METRIC_TYPE_TOPLOGY;
    } else {
        total += topologyMetrics.get_topologyMetric().get_metrics_size() + topologyMetrics.get_componentMetric().get_metrics_size();
        if (total > 0) {
            int sub = topologyMetrics.get_taskMetric().get_metrics_size() + topologyMetrics.get_workerMetric().get_metrics_size() + topologyMetrics.get_nettyMetric().get_metrics_size() + topologyMetrics.get_streamMetric().get_metrics_size();
            if (sub > 0) {
                total += sub;
                summary.type = MetricUploader.METRIC_TYPE_ALL;
            } else {
                summary.type = MetricUploader.METRIC_TYPE_TOPLOGY;
            }
        } else {
            summary.type = MetricUploader.METRIC_TYPE_TASK;
            total += topologyMetrics.get_taskMetric().get_metrics_size();
        }
    }
    context.getMetricCache().put(ClusterMetricsContext.PENDING_UPLOAD_METRIC_DATA_INFO + idx, summary);
    context.getMetricCache().put(ClusterMetricsContext.PENDING_UPLOAD_METRIC_DATA + idx, topologyMetrics);
    context.markSet(idx);
    LOG.debug("Put metric data to local cache, topology:{}, idx:{}, total:{}", topologyId, idx, total);
}
Also used : TopologyMetricDataInfo(com.alibaba.jstorm.daemon.nimbus.metric.uploader.TopologyMetricDataInfo) MetricInfo(backtype.storm.generated.MetricInfo)

Aggregations

MetricInfo (backtype.storm.generated.MetricInfo)1 TopologyMetricDataInfo (com.alibaba.jstorm.daemon.nimbus.metric.uploader.TopologyMetricDataInfo)1