Search in sources :

Example 1 with TopologyStats

use of org.apache.storm.generated.TopologyStats in project storm by apache.

the class StatsUtil method postAggregateTopoStats.

private static TopologyPageInfo postAggregateTopoStats(Map task2comp, Map exec2nodePort, Map<String, Object> accData, String topologyId, IStormClusterState clusterState) {
    TopologyPageInfo ret = new TopologyPageInfo(topologyId);
    ret.set_num_tasks(task2comp.size());
    ret.set_num_workers(((Set) accData.get(WORKERS_SET)).size());
    ret.set_num_executors(exec2nodePort != null ? exec2nodePort.size() : 0);
    Map bolt2stats = ClientStatsUtil.getMapByKey(accData, BOLT_TO_STATS);
    Map<String, ComponentAggregateStats> aggBolt2stats = new HashMap<>();
    for (Object o : bolt2stats.entrySet()) {
        Map.Entry e = (Map.Entry) o;
        Map m = (Map) e.getValue();
        long executed = getByKeyOr0(m, EXECUTED).longValue();
        if (executed > 0) {
            double execLatencyTotal = getByKeyOr0(m, EXEC_LAT_TOTAL).doubleValue();
            m.put(EXEC_LATENCY, execLatencyTotal / executed);
            double procLatencyTotal = getByKeyOr0(m, PROC_LAT_TOTAL).doubleValue();
            m.put(PROC_LATENCY, procLatencyTotal / executed);
        }
        m.remove(EXEC_LAT_TOTAL);
        m.remove(PROC_LAT_TOTAL);
        String id = (String) e.getKey();
        m.put(LAST_ERROR, getLastError(clusterState, topologyId, id));
        aggBolt2stats.put(id, thriftifyBoltAggStats(m));
    }
    Map spout2stats = ClientStatsUtil.getMapByKey(accData, SPOUT_TO_STATS);
    Map<String, ComponentAggregateStats> aggSpout2stats = new HashMap<>();
    for (Object o : spout2stats.entrySet()) {
        Map.Entry e = (Map.Entry) o;
        String id = (String) e.getKey();
        Map m = (Map) e.getValue();
        long acked = getByKeyOr0(m, ACKED).longValue();
        if (acked > 0) {
            double compLatencyTotal = getByKeyOr0(m, COMP_LAT_TOTAL).doubleValue();
            m.put(COMP_LATENCY, compLatencyTotal / acked);
        }
        m.remove(COMP_LAT_TOTAL);
        m.put(LAST_ERROR, getLastError(clusterState, topologyId, id));
        aggSpout2stats.put(id, thriftifySpoutAggStats(m));
    }
    TopologyStats topologyStats = new TopologyStats();
    topologyStats.set_window_to_acked(mapKeyStr(ClientStatsUtil.getMapByKey(accData, WIN_TO_ACKED)));
    topologyStats.set_window_to_emitted(mapKeyStr(ClientStatsUtil.getMapByKey(accData, WIN_TO_EMITTED)));
    topologyStats.set_window_to_failed(mapKeyStr(ClientStatsUtil.getMapByKey(accData, WIN_TO_FAILED)));
    topologyStats.set_window_to_transferred(mapKeyStr(ClientStatsUtil.getMapByKey(accData, WIN_TO_TRANSFERRED)));
    topologyStats.set_window_to_complete_latencies_ms(computeWeightedAveragesPerWindow(accData, WIN_TO_COMP_LAT_WGT_AVG, WIN_TO_ACKED));
    ret.set_topology_stats(topologyStats);
    ret.set_id_to_spout_agg_stats(aggSpout2stats);
    ret.set_id_to_bolt_agg_stats(aggBolt2stats);
    return ret;
}
Also used : Entry(java.util.Map.Entry) TopologyStats(org.apache.storm.generated.TopologyStats) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) TopologyPageInfo(org.apache.storm.generated.TopologyPageInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TopologyStats

use of org.apache.storm.generated.TopologyStats in project storm by apache.

the class UIHelpersTest method setup.

/**
 * Setups up bare minimum TopologyPageInfo instance such that we can pass to
 * UIHelpers.getTopologySummary() without it throwing a NPE.
 *
 * This should provide a base for which other tests can be written, but will
 * require populating additional values as needed for each test case.
 */
@BeforeEach
void setup() {
    // Create topology config and serialize to JSON.
    final Map<String, Object> topologyConfig = new HashMap<>();
    topologyConfig.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, TOPOLOGY_MESSAGE_TIMEOUT_SECS);
    final String topoConfigJson = JSONValue.toJSONString(topologyConfig);
    // Create empty TopologyStats instance
    final TopologyStats topologyStats = new TopologyStats();
    topologyStats.set_window_to_emitted(new HashMap<>());
    topologyStats.set_window_to_transferred(new HashMap<>());
    topologyStats.set_window_to_acked(new HashMap<>());
    topologyStats.set_window_to_complete_latencies_ms(new HashMap<>());
    topologyStats.set_window_to_failed(new HashMap<>());
    // Create empty AggregateStats instances.
    final Map<String, ComponentAggregateStats> idToSpoutAggStats = new HashMap<>();
    final Map<String, ComponentAggregateStats> idToBoltAggStats = new HashMap<>();
    // Build up TopologyPageInfo instance
    topoPageInfo = new TopologyPageInfo();
    topoPageInfo.set_topology_conf(topoConfigJson);
    topoPageInfo.set_id(TOPOLOGY_ID);
    topoPageInfo.set_topology_stats(topologyStats);
    topoPageInfo.set_id_to_spout_agg_stats(idToSpoutAggStats);
    topoPageInfo.set_id_to_bolt_agg_stats(idToBoltAggStats);
    // Simulate time
    mockTime = new Time.SimulatedTime(null);
}
Also used : TopologyStats(org.apache.storm.generated.TopologyStats) HashMap(java.util.HashMap) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) Time(org.apache.storm.utils.Time) TopologyPageInfo(org.apache.storm.generated.TopologyPageInfo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HashMap (java.util.HashMap)2 ComponentAggregateStats (org.apache.storm.generated.ComponentAggregateStats)2 TopologyPageInfo (org.apache.storm.generated.TopologyPageInfo)2 TopologyStats (org.apache.storm.generated.TopologyStats)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Time (org.apache.storm.utils.Time)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1