Java Code Examples for com.netflix.spectator.api.Registry#clock()

The following examples show how to use com.netflix.spectator.api.Registry#clock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoubleDistributionSummary.java    From spectator with Apache License 2.0 5 votes vote down vote up
/**
 * Get or create a double distribution summary with the specified id.
 *
 * @param registry
 *     Registry to use.
 * @param id
 *     Identifier for the metric being registered.
 * @return
 *     Distribution summary corresponding to the id.
 */
static DoubleDistributionSummary get(Registry registry, Id id) {
  DoubleDistributionSummary instance = INSTANCES.get(id);
  if (instance == null) {
    final Clock c = registry.clock();
    DoubleDistributionSummary tmp = new DoubleDistributionSummary(c, id, RESET_FREQ);
    instance = INSTANCES.putIfAbsent(id, tmp);
    if (instance == null) {
      instance = tmp;
      registry.register(tmp);
    }
  }
  return instance;
}
 
Example 2
Source File: IntervalCounter.java    From spectator with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new IntervalCounter using the given registry and base id.
 */
IntervalCounter(Registry registry, Id id) {
  this.clock = registry.clock();
  this.id = id;
  this.counter = registry.counter(id.withTag(Statistic.count));
  this.lastUpdated = PolledMeter.using(registry)
      .withId(id)
      .withTag(Statistic.duration)
      .monitorValue(new AtomicLong(0L), Functions.age(clock));
}
 
Example 3
Source File: IpcLogger.java    From spectator with Apache License 2.0 4 votes vote down vote up
/** Create a new instance. */
public IpcLogger(Registry registry, Logger logger) {
  this(registry, registry.clock(), logger);
}
 
Example 4
Source File: IpcLogger.java    From spectator with Apache License 2.0 4 votes vote down vote up
/** Create a new instance. */
public IpcLogger(Registry registry) {
  this(registry, registry.clock(), LoggerFactory.getLogger(IpcLogger.class));
}
 
Example 5
Source File: LongTaskTimer.java    From spectator with Apache License 2.0 4 votes vote down vote up
/** Create a new instance. */
private LongTaskTimer(Registry registry, Id id) {
  this.clock = registry.clock();
  this.id = id;
}
 
Example 6
Source File: Scheduler.java    From spectator with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param registry
 *     Registry to use for collecting metrics. The clock from the registry will also be
 *     used as the clock source for accessing the time.
 * @param id
 *     Id for this instance of the scheduler. Used to distinguish between instances of
 *     the scheduler for metrics and thread names. Threads will be named as
 *     {@code spectator-$id-$i}.
 * @param poolSize
 *     Number of threads to have in the pool. The threads will not be started until the
 *     first task is scheduled.
 */
public Scheduler(Registry registry, String id, int poolSize) {
  this.clock = registry.clock();

  PolledMeter.using(registry)
      .withId(newId(registry, id, "queueSize"))
      .monitorSize(queue);
  stats = new Stats(registry, id);

  this.factory = newThreadFactory(id);
  this.threads = new Thread[poolSize];
}