com.netflix.servo.DefaultMonitorRegistry Java Examples

The following examples show how to use com.netflix.servo.DefaultMonitorRegistry. 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: TestDefaultRegistryInitializer.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void init() {
  registryInitializer.init(globalRegistry, new EventBus(), new MetricsBootstrapConfig());

  Assert.assertEquals(-10, registryInitializer.getOrder());
  Assert.assertThat(globalRegistry.getDefaultRegistry(),
      Matchers.instanceOf(com.netflix.spectator.servo.ServoRegistry.class));
  Assert.assertEquals(1, registries.size());
  Assert.assertEquals(1, DefaultMonitorRegistry.getInstance().getRegisteredMonitors().size());

  registryInitializer.destroy();

  Assert.assertEquals(0, registries.size());
  Assert.assertEquals(0, DefaultMonitorRegistry.getInstance().getRegisteredMonitors().size());
}
 
Example #2
Source File: DynoOPMonitor.java    From dyno with Apache License 2.0 6 votes vote down vote up
private DynoOpCounter getOrCreateCounter(String opName, boolean compressionEnabled) {

        String counterName = opName + "_" + compressionEnabled;
        DynoOpCounter counter = counterMap.get(counterName);

        if (counter != null) {
            return counter;
        }

        counter = new DynoOpCounter(appName, counterName);

        DynoOpCounter prevCounter = counterMap.putIfAbsent(counterName, counter);
        if (prevCounter != null) {
            return prevCounter;
        }

        DefaultMonitorRegistry.getInstance().register(counter.success);
        DefaultMonitorRegistry.getInstance().register(counter.failure);
        DefaultMonitorRegistry.getInstance().register(counter.successCompressionEnabled);
        DefaultMonitorRegistry.getInstance().register(counter.failureCompressionEnabled);

        return counter;
    }
 
Example #3
Source File: DynoOPMonitor.java    From dyno with Apache License 2.0 6 votes vote down vote up
private DynoTimingCounters getOrCreateTimers(String opName) {

        DynoTimingCounters timer = timerMap.get(opName);
        if (timer != null) {
            return timer;
        }
        timer = new DynoTimingCounters(appName, opName);
        DynoTimingCounters prevTimer = timerMap.putIfAbsent(opName, timer);
        if (prevTimer != null) {
            return prevTimer;
        }
        DefaultMonitorRegistry.getInstance().register(timer.latMean);
        DefaultMonitorRegistry.getInstance().register(timer.lat99);
        DefaultMonitorRegistry.getInstance().register(timer.lat995);
        DefaultMonitorRegistry.getInstance().register(timer.lat999);
        return timer;
    }
 
Example #4
Source File: DynoJedisPipelineMonitor.java    From dyno with Apache License 2.0 6 votes vote down vote up
public void init() {
    // register the counters
    DefaultMonitorRegistry.getInstance().register(pipelineSync);
    DefaultMonitorRegistry.getInstance().register(pipelineDiscard);
    // register the pipeline timer
    DefaultMonitorRegistry.getInstance().register(timer.latMean);
    DefaultMonitorRegistry.getInstance().register(timer.lat99);
    DefaultMonitorRegistry.getInstance().register(timer.lat995);
    DefaultMonitorRegistry.getInstance().register(timer.lat999);

    // NOTE -- pipeline 'send' timers are created on demand and are registered
    // in PipelineSendTimer.getOrCreateHistogram()

    Logger.debug(String.format("Initializing DynoJedisPipelineMonitor with timing counter reset frequency %d",
            resetTimingsFrequencyInSeconds));
    if (resetTimingsFrequencyInSeconds > 0) {
        threadPool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                timer.reset();
                sendTimer.reset();
            }
        }, 1, resetTimingsFrequencyInSeconds, TimeUnit.SECONDS);
    }
}
 
Example #5
Source File: MetricObserverManualTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenMetrics_whenRegister_thenMonitored() throws InterruptedException {
    Gauge<Double> gauge = new BasicGauge<>(MonitorConfig
      .builder("test")
      .build(), () -> 2.32);
    assertEquals(2.32, gauge.getValue(), 0.01);

    DefaultMonitorRegistry
      .getInstance()
      .register(gauge);

    for (int i = 0; i < 2; i++) {
        SECONDS.sleep(1);
    }

    List<List<Metric>> metrics = observer.getObservations();
    assertThat(metrics, hasSize(greaterThanOrEqualTo(2)));

    Iterator<List<Metric>> metricIterator = metrics.iterator();
    //skip first empty observation
    metricIterator.next();
    while (metricIterator.hasNext()) {
        assertThat(metricIterator.next(), hasItem(allOf(hasProperty("config", hasProperty("tags", hasItem(GAUGE))), hasProperty("value", is(2.32)))));
    }

}
 
Example #6
Source File: AtlasObserverLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenAtlasAndCounter_whenRegister_thenPublishedToAtlas() throws Exception {
    Counter counter = new BasicCounter(MonitorConfig
      .builder("test")
      .withTag("servo", "counter")
      .build());
    DefaultMonitorRegistry
      .getInstance()
      .register(counter);
    assertThat(atlasValuesOfTag("servo"), not(containsString("counter")));

    for (int i = 0; i < 3; i++) {
        counter.increment(RandomUtils.nextInt(10));
        SECONDS.sleep(1);
        counter.increment(-1 * RandomUtils.nextInt(10));
        SECONDS.sleep(1);
    }

    assertThat(atlasValuesOfTag("servo"), containsString("counter"));
}
 
Example #7
Source File: DefaultRegistryInitializer.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public void destroy() {
  if (registry != null) {
    DefaultMonitorRegistry.getInstance().unregister(registry);
    globalRegistry.remove(registry);
  }
}
 
Example #8
Source File: DynoCPMonitor.java    From dyno with Apache License 2.0 5 votes vote down vote up
public DynoCPMonitor(String namePrefix) {

        try {
            DefaultMonitorRegistry.getInstance().register(Monitors.newObjectMonitor(namePrefix, this));
        } catch (Exception e) {
            Logger.warn("Failed to register metrics with monitor registry", e);
        }
    }
 
Example #9
Source File: DynoJedisPipelineMonitor.java    From dyno with Apache License 2.0 5 votes vote down vote up
private BasicCounter getOrCreateCounter(String opName) {

        BasicCounter counter = counterMap.get(opName);
        if (counter != null) {
            return counter;
        }
        counter = getNewPipelineCounter(opName);
        BasicCounter prevCounter = counterMap.putIfAbsent(opName, counter);
        if (prevCounter != null) {
            return prevCounter;
        }
        DefaultMonitorRegistry.getInstance().register(counter);
        return counter;
    }
 
Example #10
Source File: DynoJedisPipelineMonitor.java    From dyno with Apache License 2.0 5 votes vote down vote up
private EstimatedHistogramMean getOrCreateHistogram(String opName) {
    if (histograms.containsKey(opName)) {
        return histograms.get(opName);
    } else {
        EstimatedHistogram histogram = new EstimatedHistogram();
        EstimatedHistogramMean histogramMean =
                new EstimatedHistogramMean("Dyno__" + appName + "__PL__latMean", "PL_SEND", opName, histogram);
        histograms.put(opName, histogramMean);
        DefaultMonitorRegistry.getInstance().register(histogramMean);
        return histogramMean;
    }
}
 
Example #11
Source File: Servo.java    From suro with Apache License 2.0 5 votes vote down vote up
public static Counter getCounter(MonitorConfig config) {
    Counter v = counters.get(config);
    if (v != null) return v;
    else {
        Counter counter = new BasicCounter(config);
        Counter prevCounter = counters.putIfAbsent(config, counter);
        if (prevCounter != null) return prevCounter;
        else {
            DefaultMonitorRegistry.getInstance().register(counter);
            return counter;
        }
    }
}
 
Example #12
Source File: Servo.java    From suro with Apache License 2.0 5 votes vote down vote up
public static Timer getTimer(MonitorConfig config) {
    Timer v = timers.get(config);
    if (v != null) return v;
    else {
        Timer timer = new BasicTimer(config, TimeUnit.SECONDS);
        Timer prevTimer = timers.putIfAbsent(config, timer);
        if (prevTimer != null) return prevTimer;
        else {
            DefaultMonitorRegistry.getInstance().register(timer);
            return timer;
        }
    }
}
 
Example #13
Source File: Servo.java    From suro with Apache License 2.0 5 votes vote down vote up
public static LongGauge getLongGauge(MonitorConfig config) {
    LongGauge v = longGauges.get(config);
    if (v != null) return v;
    else {
        LongGauge gauge = new LongGauge(config);
        LongGauge prev = longGauges.putIfAbsent(config, gauge);
        if (prev != null) return prev;
        else {
            DefaultMonitorRegistry.getInstance().register(gauge);
            return gauge;
        }
    }
}
 
Example #14
Source File: Servo.java    From suro with Apache License 2.0 5 votes vote down vote up
public static DoubleGauge getDoubleGauge(MonitorConfig config) {
    DoubleGauge v = doubleGauges.get(config);
    if (v != null) return v;
    else {
        DoubleGauge gauge = new DoubleGauge(config);
        DoubleGauge prev = doubleGauges.putIfAbsent(config, gauge);
        if (prev != null) return prev;
        else {
            DefaultMonitorRegistry.getInstance().register(gauge);
            return gauge;
        }
    }
}
 
Example #15
Source File: ServoRegistry.java    From spectator with Apache License 2.0 4 votes vote down vote up
/** Create a new instance. */
ServoRegistry(Clock clock, MonitorConfig config) {
  super(clock);
  this.config = (config == null) ? defaultConfig() : config;
  DefaultMonitorRegistry.getInstance().register(this);
}
 
Example #16
Source File: Servo.java    From spectator with Apache License 2.0 4 votes vote down vote up
static MonitorRegistry getInstance() {
  return DefaultMonitorRegistry.getInstance();
}