Search in sources :

Example 1 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class MetricUtils method mergeMetricSnapshotMap.

public static void mergeMetricSnapshotMap(Map<Integer, MetricSnapshot> returnSnapshotMaps, Map<Integer, MetricSnapshot> snapshotMap, AsmMetric asmMetric, MetricType metricType) {
    Map<Integer, MetricSnapshot> generateSnapshotMap = MetricUtils.toThriftSnapshots(asmMetric.getSnapshots(), metricType);
    for (Map.Entry<Integer, MetricSnapshot> entry : snapshotMap.entrySet()) {
        Integer key = entry.getKey();
        MetricSnapshot snapshot = entry.getValue();
        MetricSnapshot old = returnSnapshotMaps.get(key);
        if (old == null) {
            snapshot.set_ts(generateSnapshotMap.get(key).get_ts());
            snapshot.set_metricId(asmMetric.getMetricId());
            old = snapshot;
            returnSnapshotMaps.put(key, old);
        } else {
            if (metricType == MetricType.COUNTER) {
                old.set_longValue(old.get_longValue() + snapshot.get_longValue());
            } else if (metricType == MetricType.GAUGE) {
                old.set_doubleValue(old.get_doubleValue() + snapshot.get_doubleValue());
            } else if (metricType == MetricType.METER) {
                old.set_mean(old.get_mean() + snapshot.get_mean());
                old.set_m1(old.get_m1() + snapshot.get_m1());
                old.set_m5(old.get_m5() + snapshot.get_m5());
                old.set_m15(old.get_m15() + snapshot.get_m15());
            } else if (metricType == MetricType.HISTOGRAM) {
                old.set_min((old.get_min() + snapshot.get_min()) / 2);
                old.set_max((old.get_max() + snapshot.get_max()) / 2);
                old.set_p50((old.get_p50() + snapshot.get_p50()) / 2);
                old.set_p75((old.get_p75() + snapshot.get_p75()) / 2);
                old.set_p95((old.get_p95() + snapshot.get_p95()) / 2);
                old.set_p98((old.get_p98() + snapshot.get_p98()) / 2);
                old.set_p99((old.get_p99() + snapshot.get_p99()) / 2);
                old.set_p999((old.get_p999() + snapshot.get_p999()) / 2);
                old.set_mean((old.get_mean() + snapshot.get_mean()) / 2);
                old.set_stddev((old.get_stddev() + snapshot.get_stddev()) / 2);
            }
        }
    }
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 2 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class ServiceHandler method getPagingNettyMetrics.

@Override
public MetricInfo getPagingNettyMetrics(String topologyId, String host, int page) throws TException {
    MetricInfo ret = new MetricInfo();
    int start = (page - 1) * MetricUtils.NETTY_METRIC_PAGE_SIZE;
    int end = page * MetricUtils.NETTY_METRIC_PAGE_SIZE;
    int cur = -1;
    List<MetricInfo> metricInfoList = data.getMetricCache().getMetricData(topologyId, MetaType.NETTY);
    if (metricInfoList != null && metricInfoList.size() > 0) {
        MetricInfo metricInfo = metricInfoList.get(0);
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metricInfo.get_metrics().entrySet()) {
            String metricName = metricEntry.getKey();
            Map<Integer, MetricSnapshot> data = metricEntry.getValue();
            if (metricName.contains(host)) {
                ++cur;
                if (cur >= start && cur < end) {
                    ret.put_to_metrics(metricName, data);
                }
                if (cur >= end) {
                    break;
                }
            }
        }
    }
    LOG.info("getNettyMetricsByHost, topology:{}, host:{}, total size:{}", topologyId, host, ret.get_metrics_size());
    return ret;
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 3 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class ServiceHandler method getNettyMetricsByHost.

@Override
public MetricInfo getNettyMetricsByHost(String topologyId, String host) throws TException {
    MetricInfo ret = new MetricInfo();
    List<MetricInfo> metricInfoList = data.getMetricCache().getMetricData(topologyId, MetaType.NETTY);
    if (metricInfoList != null && metricInfoList.size() > 0) {
        MetricInfo metricInfo = metricInfoList.get(0);
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metricInfo.get_metrics().entrySet()) {
            String metricName = metricEntry.getKey();
            Map<Integer, MetricSnapshot> data = metricEntry.getValue();
            if (metricName.contains(host)) {
                ret.put_to_metrics(metricName, data);
            }
        }
    }
    LOG.info("getNettyMetricsByHost, topology:{}, host:{}, total size:{}", topologyId, host, ret.get_metrics_size());
    return ret;
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 4 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class UpdateEvent method updateClusterMetrics.

// update cluster metrics local cache
private void updateClusterMetrics(String topologyId, TopologyMetric tpMetric) {
    if (tpMetric.get_topologyMetric().get_metrics_size() == 0) {
        return;
    }
    MetricInfo topologyMetrics = tpMetric.get_topologyMetric();
    // make a new MetricInfo to save the topologyId's metric
    MetricInfo clusterMetrics = MetricUtils.mkMetricInfo();
    Set<String> metricNames = new HashSet<>();
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> entry : topologyMetrics.get_metrics().entrySet()) {
        String metricName = MetricUtils.topo2clusterName(entry.getKey());
        MetricType metricType = MetricUtils.metricType(metricName);
        Map<Integer, MetricSnapshot> winData = new HashMap<>();
        for (Map.Entry<Integer, MetricSnapshot> entryData : entry.getValue().entrySet()) {
            MetricSnapshot snapshot = entryData.getValue().deepCopy();
            winData.put(entryData.getKey(), snapshot);
            if (metricType == MetricType.HISTOGRAM) {
                // reset topology metric points
                entryData.getValue().set_points(new byte[0]);
                entryData.getValue().set_pointSize(0);
            }
        }
        clusterMetrics.put_to_metrics(metricName, winData);
        metricNames.add(metricName);
    }
    // save to local cache, waiting for merging
    TopologyMetricContext clusterTpMetricContext = context.getClusterTopologyMetricContext();
    clusterTpMetricContext.addToMemCache(topologyId, clusterMetrics);
    context.registerMetrics(JStormMetrics.CLUSTER_METRIC_KEY, metricNames);
}
Also used : HashMap(java.util.HashMap) MetricType(com.alibaba.jstorm.metric.MetricType) TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext) MetricInfo(backtype.storm.generated.MetricInfo) HashMap(java.util.HashMap) Map(java.util.Map) MetricSnapshot(backtype.storm.generated.MetricSnapshot) HashSet(java.util.HashSet)

Example 5 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class MetricUtils method convert.

public static MetricSnapshot convert(AsmHistogramSnapshot snapshot) {
    // some histograms are never updated, skip such metrics
    // if (snapshot.getSnapshot().getValues().length == 0) {
    // return null;
    // }
    MetricSnapshot ret = new MetricSnapshot();
    ret.set_metricId(snapshot.getMetricId());
    ret.set_ts(TimeUtils.alignTimeToMin(snapshot.getTs()));
    ret.set_metricType(MetricType.HISTOGRAM.getT());
    Snapshot ws = snapshot.getSnapshot();
    ret.set_min(ws.getMin());
    ret.set_max(ws.getMax());
    ret.set_p50(ws.getMedian());
    ret.set_p75(ws.get75thPercentile());
    ret.set_p95(ws.get95thPercentile());
    ret.set_p98(ws.get98thPercentile());
    ret.set_p99(ws.get99thPercentile());
    ret.set_p999(ws.get999thPercentile());
    ret.set_mean(ws.getMean());
    ret.set_stddev(ws.getStdDev());
    ret.set_points(new byte[0]);
    ret.set_pointSize(0);
    return ret;
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Aggregations

MetricSnapshot (backtype.storm.generated.MetricSnapshot)35 MetricInfo (backtype.storm.generated.MetricInfo)12 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 ConcurrentMap (java.util.concurrent.ConcurrentMap)11 Map (java.util.Map)7 HashMap (java.util.HashMap)6 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)4 MetricType (com.alibaba.jstorm.metric.MetricType)3 TreeMap (java.util.TreeMap)3 ComponentSummary (backtype.storm.generated.ComponentSummary)2 TopologyMetric (backtype.storm.generated.TopologyMetric)2 TopologyMetricContext (com.alibaba.jstorm.metric.TopologyMetricContext)2 TimeCacheMap (com.alibaba.jstorm.utils.TimeCacheMap)2 Histogram (com.codahale.metrics.Histogram)2 Snapshot (com.codahale.metrics.Snapshot)2 ArrayList (java.util.ArrayList)2 Iface (backtype.storm.generated.Nimbus.Iface)1 WorkerSummary (backtype.storm.generated.WorkerSummary)1 NimbusClientWrapper (backtype.storm.utils.NimbusClientWrapper)1 KVSerializable (com.alibaba.jstorm.metric.KVSerializable)1