类com.codahale.metrics.SlidingTimeWindowReservoir源码实例Demo

下面列出了怎么用com.codahale.metrics.SlidingTimeWindowReservoir的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lucene-solr   文件: MetricsConfigTest.java
@Test
public void testCustomReservoir() throws Exception {
  System.setProperty("timer.reservoir", UniformReservoir.class.getName());
  System.setProperty("histogram.size", "2048");
  System.setProperty("histogram.window", "600");
  System.setProperty("histogram.reservoir", SlidingTimeWindowReservoir.class.getName());
  NodeConfig cfg = loadNodeConfig();
  SolrMetricManager mgr = new SolrMetricManager(cfg.getSolrResourceLoader(), cfg.getMetricsConfig());
  assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
  assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
  assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
  assertTrue(mgr.getHistogramSupplier() instanceof MetricSuppliers.DefaultHistogramSupplier);
  Reservoir rsv = ((MetricSuppliers.DefaultTimerSupplier)mgr.getTimerSupplier()).getReservoir();
  assertTrue(rsv instanceof UniformReservoir);
  rsv = ((MetricSuppliers.DefaultHistogramSupplier)mgr.getHistogramSupplier()).getReservoir();
  assertTrue(rsv instanceof SlidingTimeWindowReservoir);
}
 
源代码2 项目: raml-module-builder   文件: StatsTracker.java
/** add a metric (time) to a specific resource - for example
 * type = PostgresClient.get
 * time = single operation time in nanoseconds
 */
public static void addStatElement(String type, long time){
  // unsynchronized but fast check
  if (!registeredStatRequesters.contains(type)) {
    // prevent race condition - registering the same type twice will throw an exception
    synchronized(registeredStatRequesters) {
      // synchronized check
      if (!registeredStatRequesters.contains(type)) {
        METRICS.register(type, new Histogram(new SlidingTimeWindowReservoir(60,
          TimeUnit.SECONDS)));
        registeredStatRequesters.add(type);
      }
    }
  }
  METRICS.histogram(type).update(time/1000000);
}
 
@Setup(Level.Iteration)
public void setup() {
    registry = new MetricRegistry();
    histogram = registry.histogram("histogram");
    histogramSlidingTimeWindow =
            registry.register("slidingTimeWindowHistogram",
                    new Histogram(new SlidingTimeWindowReservoir(10, TimeUnit.SECONDS)));
    histogramUniform =
            registry.register("uniformHistogram",
                    new Histogram(new UniformReservoir()));
}
 
源代码4 项目: datacollector   文件: MetricsConfigurator.java
public static Timer createTimer(MetricRegistry metrics, String name, final String pipelineName, final String pipelineRev) {
  return create(
    metrics,
    new Timer(new SlidingTimeWindowReservoir(60, TimeUnit.SECONDS)),
    metricName(name, TIMER_SUFFIX),
    pipelineName,
    pipelineRev
  );
}
 
源代码5 项目: incubator-gobblin   文件: TaskExecutor.java
/**
 * Constructor used internally.
 */
private TaskExecutor(int taskExecutorThreadPoolSize, int coreRetryThreadPoolSize, long retryIntervalInSeconds,
                     int queuedTaskTimeMaxSize, long queuedTaskTimeMaxAge, int timerWindowSize) {
  Preconditions.checkArgument(taskExecutorThreadPoolSize > 0, "Task executor thread pool size should be positive");
  Preconditions.checkArgument(retryIntervalInSeconds > 0, "Task retry interval should be positive");
  Preconditions.checkArgument(queuedTaskTimeMaxSize > 0, "Queued task time max size should be positive");
  Preconditions.checkArgument(queuedTaskTimeMaxAge > 0, "Queued task time max age should be positive");

  // Currently a fixed-size thread pool is used to execute tasks. We probably need to revisit this later.
  this.taskExecutor = ExecutorsUtils.loggingDecorator(Executors.newScheduledThreadPool(
      taskExecutorThreadPoolSize,
      ExecutorsUtils.newThreadFactory(Optional.of(LOG), Optional.of("TaskExecutor-%d"))));

  this.retryIntervalInSeconds = retryIntervalInSeconds;
  this.queuedTaskTimeMaxSize = queuedTaskTimeMaxSize;
  this.queuedTaskTimeMaxAge = queuedTaskTimeMaxAge;
  this.taskCreateAndRunTimer = new Timer(new SlidingTimeWindowReservoir(timerWindowSize, TimeUnit.MINUTES));

  this.forkExecutor = ExecutorsUtils.loggingDecorator(
      new ThreadPoolExecutor(
          // The core thread pool size is equal to that of the task
          // executor as there's at least one fork per task
          taskExecutorThreadPoolSize,
          // The fork executor thread pool size is essentially unbounded. This is to make sure all forks of
          // a task get a thread to run so all forks of the task are making progress. This is necessary since
          // otherwise the parent task will be blocked if the record queue (bounded) of some fork is full and
          // that fork has not yet started to run because of no available thread. The task cannot proceed in
          // this case because it has to make sure every records go to every forks.
          Integer.MAX_VALUE,
          0L,
          TimeUnit.MILLISECONDS,
          // The work queue is a SynchronousQueue. This essentially forces a new thread to be created for each fork.
          new SynchronousQueue<Runnable>(),
          ExecutorsUtils.newThreadFactory(Optional.of(LOG), Optional.of("ForkExecutor-%d"))));
}
 
源代码6 项目: incubator-gobblin   文件: InnerHistogram.java
InnerHistogram(MetricContext context, String name, ContextAwareHistogram contextAwareHistogram, long windowSize, TimeUnit unit) {
  super(new SlidingTimeWindowReservoir(windowSize, unit));

  this.name = name;

  Optional<MetricContext> parentContext = context.getParent();
  if (parentContext.isPresent()) {
    this.parentHistogram = Optional.fromNullable(parentContext.get().contextAwareHistogram(name, windowSize, unit));
  } else {
    this.parentHistogram = Optional.absent();
  }

  this.contextAwareHistogram = new WeakReference<>(contextAwareHistogram);
}
 
源代码7 项目: incubator-gobblin   文件: InnerTimer.java
InnerTimer(MetricContext context, String name, ContextAwareTimer contextAwareTimer, long windowSize, TimeUnit unit) {
  super(new SlidingTimeWindowReservoir(windowSize, unit));
  this.name = name;

  Optional<MetricContext> parentContext = context.getParent();
  if (parentContext.isPresent()) {
    this.parentTimer = Optional.fromNullable(parentContext.get().contextAwareTimer(name, windowSize, unit));
  } else {
    this.parentTimer = Optional.absent();
  }
  this.timer = new WeakReference<>(contextAwareTimer);
}
 
源代码8 项目: kite   文件: MetricBuilders.java
public Histogram getSlidingTimeWindowHistogram(MetricRegistry registry, String name, final long window,
    final TimeUnit windowUnit) {
  return getOrAdd(registry, name, new MetricBuilder<Histogram>() {
    @Override
    public Histogram newMetric() {
      return new Histogram(new SlidingTimeWindowReservoir(window, windowUnit));
    }
    @Override
    public boolean isInstance(Metric metric) {
      return Histogram.class.isInstance(metric);
    }          
  });
}
 
源代码9 项目: kite   文件: MetricBuilders.java
public Timer getSlidingTimeWindowTimer(MetricRegistry registry, String name, final long window,
    final TimeUnit windowUnit) {
  return getOrAdd(registry, name, new MetricBuilder<Timer>() {
    @Override
    public Timer newMetric() {
      return new Timer(new SlidingTimeWindowReservoir(window, windowUnit));
    }
    @Override
    public boolean isInstance(Metric metric) {
      return Timer.class.isInstance(metric);
    }          
  });
}
 
源代码10 项目: lucene-solr   文件: MetricSuppliers.java
@SuppressWarnings({"unchecked"})
private static final Reservoir getReservoir(SolrResourceLoader loader, PluginInfo info) {
  if (info == null) {
    return new ExponentiallyDecayingReservoir();
  }
  Clock clk = getClock(info, CLOCK);
  String clazz = ExponentiallyDecayingReservoir.class.getName();
  int size = -1;
  double alpha = -1;
  long window = -1;
  if (info.initArgs != null) {
    if (info.initArgs.get(RESERVOIR) != null) {
      String val = String.valueOf(info.initArgs.get(RESERVOIR)).trim();
      if (!val.isEmpty()) {
        clazz = val;
      }
    }
    Number n = (Number)info.initArgs.get(RESERVOIR_SIZE);
    if (n != null) {
      size = n.intValue();
    }
    n = (Number)info.initArgs.get(RESERVOIR_EDR_ALPHA);
    if (n != null) {
      alpha = n.doubleValue();
    }
    n = (Number)info.initArgs.get(RESERVOIR_WINDOW);
    if (n != null) {
      window = n.longValue();
    }
  }
  if (size <= 0) {
    size = DEFAULT_SIZE;
  }
  if (alpha <= 0) {
    alpha = DEFAULT_ALPHA;
  }
  // special case for core implementations
  if (clazz.equals(EDR_CLAZZ)) {
    return new ExponentiallyDecayingReservoir(size, alpha, clk);
  } else if (clazz.equals(UNI_CLAZZ)) {
    return new UniformReservoir(size);
  } else if (clazz.equals(STW_CLAZZ)) {
    if (window <= 0) {
      window = DEFAULT_WINDOW; // 5 minutes, comparable to EDR
    }
    return new SlidingTimeWindowReservoir(window, TimeUnit.SECONDS);
  } else if (clazz.equals(SW_CLAZZ)) {
    return new SlidingWindowReservoir(size);
  } else { // custom reservoir
    Reservoir reservoir;
    try {
      reservoir = loader.newInstance(clazz, Reservoir.class);
      if (reservoir instanceof PluginInfoInitialized) {
        ((PluginInfoInitialized)reservoir).init(info);
      } else {
        SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
      }
      return reservoir;
    } catch (Exception e) {
      log.warn("Error initializing custom Reservoir implementation (will use default): {}", info, e);
      return new ExponentiallyDecayingReservoir(size, alpha, clk);
    }
  }
}
 
源代码11 项目: ffwd   文件: SemanticCoreStatistics.java
@Override
public Histogram newMetric() {
    return new Histogram(new SlidingTimeWindowReservoir(
        TimeUnit.MINUTES.toMinutes(HISTOGRAM_TTL_MINUTES), TimeUnit.MINUTES));
}
 
源代码12 项目: incubator-gobblin   文件: ContextAwareHistogram.java
ContextAwareHistogram(MetricContext context, String name, long windowSize, TimeUnit unit) {
  super(new SlidingTimeWindowReservoir(windowSize, unit));
  this.innerHistogram = new InnerHistogram(context, name, this, windowSize, unit);
  this.context = context;
}
 
源代码13 项目: incubator-gobblin   文件: ContextAwareTimer.java
ContextAwareTimer(MetricContext context, String name, long windowSize, TimeUnit unit) {
  super(new SlidingTimeWindowReservoir(windowSize, unit));
  this.innerTimer = new InnerTimer(context, name, this, windowSize, unit);
  this.context = context;
}
 
 类所在包
 类方法
 同包方法