// Path: src/main/java/storm/benchmark/benchmarks/common/StormBenchmark.java
// public abstract class StormBenchmark implements IBenchmark {
// 
//   private static final Logger LOG = Logger.getLogger(StormBenchmark.class);
//   public static final String DEFAULT_TOPOLOGY_NAME = "benchmark";
// 
//   @Override
//   public IMetricsCollector getMetricsCollector(Config config, StormTopology topology) {
// 
//     Set<MetricsItem> items = Sets.newHashSet(
//             MetricsItem.SUPERVISOR_STATS,
//             MetricsItem.TOPOLOGY_STATS,
//             MetricsItem.THROUGHPUT,
//             MetricsItem.SPOUT_THROUGHPUT,
//             MetricsItem.SPOUT_LATENCY
//             );
//     return new BasicMetricsCollector(config, topology, items);
//   }
// 
// 
// }
// 
// Path: src/main/java/storm/benchmark/util/BenchmarkUtils.java
// public final class BenchmarkUtils {
//   private static final Logger LOG = Logger.getLogger(BenchmarkUtils.class);
// 
//   private BenchmarkUtils() {
//   }
// 
//   public static double max(Iterable<Double> iterable) {
//     Iterator<Double> iterator = iterable.iterator();
//     double max = Double.MIN_VALUE;
//     while (iterator.hasNext()) {
//       double d = iterator.next();
//       if (d > max) {
//         max = d;
//       }
//     }
//     return max;
//   }
// 
//   public static double avg(Iterable<Double> iterable) {
//     Iterator<Double> iterator = iterable.iterator();
//     double total = 0.0;
//     int num = 0;
//     while (iterator.hasNext()) {
//       total += iterator.next();
//       num++;
//     }
//     return total / num;
//   }
// 
//   public static void putIfAbsent(Map map, Object key, Object val) {
//     if (!map.containsKey(key)) {
//       map.put(key, val);
//     }
//   }
// 
//   public static int getInt(Map map, Object key, int def) {
//     return Utils.getInt(Utils.get(map, key, def));
//   }
// 
//   public static boolean ifAckEnabled(Config config) {
//     Object ackers = config.get(Config.TOPOLOGY_ACKER_EXECUTORS);
//     if (null == ackers) {
//       LOG.warn("acker executors are null");
//       return false;
//     }
//     return Utils.getInt(ackers) > 0;
//   }}


import backtype.storm.Config;
import backtype.storm.utils.Utils;
import org.apache.log4j.Logger;
import storm.benchmark.benchmarks.common.StormBenchmark;
import storm.benchmark.util.BenchmarkUtils;
import java.io.PrintWriter;
import java.util.Map;
import java.util.TreeMap;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package storm.benchmark.metrics;



public class MetricsCollectorConfig {
  private static final Logger LOG = Logger.getLogger(MetricsCollectorConfig.class);

  public static final String CONF_FILE_FORMAT = "%s/%s_metrics_%d.yaml";
  public static final String DATA_FILE_FORMAT = "%s/%s_metrics_%d.csv";

  public static final String METRICS_ENABLED = "metrics.enabled";
  public static final String METRICS_POLL_INTERVAL = "metrics.poll";
  public static final String METRICS_TOTAL_TIME = "metrics.time";
  public static final String METRICS_PATH = "metrics.path";

  public static final int DEFAULT_POLL_INTERVAL = 30 * 1000; // 30 secs
  public static final int DEFAULT_TOTAL_TIME = 5 * 60 * 1000; // 5 mins
  public static final String DEFAULT_PATH = "/root/";

  // storm configuration
  public final Config stormConfig;
  // storm benchmarks name
  public final String name;
  // How often should metrics be collected
  public final int pollInterval;
  // How long should the benchmark run for
  public final int totalTime;
  // metrics file path
  public final String path;

  public MetricsCollectorConfig(Config stormConfig) {
    this.stormConfig  = stormConfig;
    name = (String) Utils.get(
            stormConfig, Config.TOPOLOGY_NAME, StormBenchmark.DEFAULT_TOPOLOGY_NAME);
    pollInterval = BenchmarkUtils.getInt(
            stormConfig, METRICS_POLL_INTERVAL, DEFAULT_POLL_INTERVAL);
// Path: src/main/java/storm/benchmark/benchmarks/common/StormBenchmark.java
// public abstract class StormBenchmark implements IBenchmark {
// 
//   private static final Logger LOG = Logger.getLogger(StormBenchmark.class);
//   public static final String DEFAULT_TOPOLOGY_NAME = "benchmark";
// 
//   @Override
//   public IMetricsCollector getMetricsCollector(Config config, StormTopology topology) {
// 
//     Set<MetricsItem> items = Sets.newHashSet(
//             MetricsItem.SUPERVISOR_STATS,
//             MetricsItem.TOPOLOGY_STATS,
//             MetricsItem.THROUGHPUT,
//             MetricsItem.SPOUT_THROUGHPUT,
//             MetricsItem.SPOUT_LATENCY
//             );
//     return new BasicMetricsCollector(config, topology, items);
//   }
// 
// 
// }
// 
// Path: src/main/java/storm/benchmark/util/BenchmarkUtils.java
// public final class BenchmarkUtils {
//   private static final Logger LOG = Logger.getLogger(BenchmarkUtils.class);
// 
//   private BenchmarkUtils() {
//   }
// 
//   public static double max(Iterable<Double> iterable) {
//     Iterator<Double> iterator = iterable.iterator();
//     double max = Double.MIN_VALUE;
//     while (iterator.hasNext()) {
//       double d = iterator.next();
//       if (d > max) {
//         max = d;
//       }
//     }
//     return max;
//   }
// 
//   public static double avg(Iterable<Double> iterable) {
//     Iterator<Double> iterator = iterable.iterator();
//     double total = 0.0;
//     int num = 0;
//     while (iterator.hasNext()) {
//       total += iterator.next();
//       num++;
//     }
//     return total / num;
//   }
// 
//   public static void putIfAbsent(Map map, Object key, Object val) {
//     if (!map.containsKey(key)) {
//       map.put(key, val);
//     }
//   }
// 
//   public static int getInt(Map map, Object key, int def) {
//     return Utils.getInt(Utils.get(map, key, def));
//   }
// 
//   public static boolean ifAckEnabled(Config config) {
//     Object ackers = config.get(Config.TOPOLOGY_ACKER_EXECUTORS);
//     if (null == ackers) {
//       LOG.warn("acker executors are null");
//       return false;
//     }
//     return Utils.getInt(ackers) > 0;
//   }}


// Path: src/main/java/storm/benchmark/metrics/MetricsCollectorConfig.java
import backtype.storm.Config;
import backtype.storm.utils.Utils;
import org.apache.log4j.Logger;
import storm.benchmark.benchmarks.common.StormBenchmark;
import storm.benchmark.util.BenchmarkUtils;
import java.io.PrintWriter;
import java.util.Map;
import java.util.TreeMap;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package storm.benchmark.metrics;



public class MetricsCollectorConfig {
  private static final Logger LOG = Logger.getLogger(MetricsCollectorConfig.class);

  public static final String CONF_FILE_FORMAT = "%s/%s_metrics_%d.yaml";
  public static final String DATA_FILE_FORMAT = "%s/%s_metrics_%d.csv";

  public static final String METRICS_ENABLED = "metrics.enabled";
  public static final String METRICS_POLL_INTERVAL = "metrics.poll";
  public static final String METRICS_TOTAL_TIME = "metrics.time";
  public static final String METRICS_PATH = "metrics.path";

  public static final int DEFAULT_POLL_INTERVAL = 30 * 1000; // 30 secs
  public static final int DEFAULT_TOTAL_TIME = 5 * 60 * 1000; // 5 mins
  public static final String DEFAULT_PATH = "/root/";

  // storm configuration
  public final Config stormConfig;
  // storm benchmarks name
  public final String name;
  // How often should metrics be collected
  public final int pollInterval;
  // How long should the benchmark run for
  public final int totalTime;
  // metrics file path
  public final String path;

  public MetricsCollectorConfig(Config stormConfig) {
    this.stormConfig  = stormConfig;
    name = (String) Utils.get(
            stormConfig, Config.TOPOLOGY_NAME, StormBenchmark.DEFAULT_TOPOLOGY_NAME);
    pollInterval = BenchmarkUtils.getInt(
            stormConfig, METRICS_POLL_INTERVAL, DEFAULT_POLL_INTERVAL);
    totalTime = BenchmarkUtils.getInt(