com.netflix.servo.monitor.MonitorConfig Java Examples

The following examples show how to use com.netflix.servo.monitor.MonitorConfig. 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: 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 #2
Source File: MetricTypeManualTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenBucketTimer_whenRecord_thenStatsCalculated() throws Exception {
    BucketTimer timer = new BucketTimer(MonitorConfig
      .builder("test")
      .build(), new BucketConfig.Builder()
      .withBuckets(new long[]{2L, 5L})
      .withTimeUnit(SECONDS)
      .build(), SECONDS);
    timer.record(3);
    timer.record(6);

    assertEquals("timer should count 9 seconds in total", 9, timer
      .getTotalTime()
      .intValue());

    final Map<String, Long> metricMap = timer
      .getMonitors()
      .stream()
      .filter(monitor -> monitor
        .getConfig()
        .getTags()
        .containsKey("servo.bucket"))
      .collect(toMap(monior -> getMonitorTagValue(monior, "servo.bucket"), monitor -> (Long) monitor.getValue()));

    assertThat(metricMap, allOf(hasEntry("bucket=2s", 0L), hasEntry("bucket=5s", 1L), hasEntry("bucket=overflow", 1L)));
}
 
Example #3
Source File: KafkaSink.java    From suro with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(final MessageContainer message) {
    queuedRecords.incrementAndGet();
    DynamicCounter.increment(
        MonitorConfig
            .builder("queuedRecord")
            .withTag(TagKey.ROUTING_KEY, message.getRoutingKey())
            .build());
    runRecordCounterListener();

    if (metadataFetchedTopicSet.contains(message.getRoutingKey())) {
        sendMessage(message);
    } else {
        if(!metadataWaitingQueue.offer(message)) {
            dropMessage(message.getRoutingKey(), "metadataWaitingQueueFull");
        }
    }
}
 
Example #4
Source File: MetricTypeManualTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenTimer_whenExecuteTask_thenTimerUpdated() throws Exception {
    BasicTimer timer = new BasicTimer(MonitorConfig
      .builder("test")
        .build(), MILLISECONDS);

    Stopwatch stopwatch = timer.start();
    SECONDS.sleep(1);
    timer.record(2, SECONDS);
    stopwatch.stop();

    assertEquals("timer should count 1 second", 1000, timer
      .getValue()
      .intValue(),1000);        
    assertEquals("timer should count 3 second in total", 3000, timer.getTotalTime()
        .intValue(),1000);
    assertEquals("timer should record 2 updates", 2, timer
      .getCount()
      .intValue());

    assertEquals("timer should have max 2", 2000, timer.getMax(), 0.01);
}
 
Example #5
Source File: CloudTrail.java    From suro with Apache License 2.0 6 votes vote down vote up
@Override
public List<MessageContainer> parse(String data) {
    List<MessageContainer> messages = new ArrayList<MessageContainer>();

    try {
        Map<String, Object> blob = jsonMapper.readValue(data, S3Consumer.typeReference);
        List<Map<String, Object>> records = (List<Map<String, Object>>) blob.get("Records");
        for (Map<String, Object> record : records) {
            messages.add(new DefaultMessageContainer(
                    new Message(routingKey, jsonMapper.writeValueAsBytes(record)),
                    jsonMapper));
        }
    } catch (Exception e) {
        log.error("Exception on parsing: " + e.getMessage(), e);
        DynamicCounter.increment(
                MonitorConfig.builder("recordParseError").withTag("parserType", TYPE).build());
    }

    return messages;
}
 
Example #6
Source File: MetricTypeManualTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenPeakRateCounter_whenManipulate_thenPeakRateReturn() throws Exception {
    Counter counter = new PeakRateCounter(MonitorConfig
      .builder("test")
      .build());
    assertEquals("counter should start with 0", 0, counter
      .getValue()
      .intValue());

    counter.increment();
    SECONDS.sleep(1);
    counter.increment();
    counter.increment();

    assertEquals("peak rate should have be 2", 2, counter
      .getValue()
      .intValue());
}
 
Example #7
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 #8
Source File: SyncSuroClient.java    From suro with Apache License 2.0 6 votes vote down vote up
public static int incrementMessageCount(String counterName, String app, Iterable<Message> messages, List<AsyncSuroClient.Listener> listeners) {
    int count = 0;
    for (Message message : messages) {
        DynamicCounter.increment(
                MonitorConfig.builder(counterName)
                        .withTag(TagKey.APP, app)
                        .withTag(TagKey.DATA_SOURCE, message.getRoutingKey())
                        .build());
        ++count;
    }

    for (AsyncSuroClient.Listener listener : listeners) {
        listener.sentCallback(count);
    }

    return count;
}
 
Example #9
Source File: LocalFileSink.java    From suro with Apache License 2.0 6 votes vote down vote up
/**
 * Write all messages in msgList to file writer, sync the file,
 * commit the queue and clear messages
 *
 * @param msgList
 * @throws java.io.IOException
 */
@Override
protected void write(List<Message> msgList) throws IOException {
    for (Message msg : msgList) {
        writer.writeTo(msg);

        String routingKey = normalizeRoutingKey(msg);

        DynamicCounter.increment(
                MonitorConfig.builder("writtenMessages")
                        .withTag(TagKey.DATA_SOURCE, routingKey)
                        .build());
        ++writtenMessages;
        DynamicCounter.increment(
                MonitorConfig.builder("writtenBytes")
                        .withTag(TagKey.DATA_SOURCE, routingKey)
                        .build(), msg.getPayload().length);
        writtenBytes += msg.getPayload().length;

        messageWrittenInRotation = true;
    }

    writer.sync();

    throughput.increment(msgList.size());
}
 
Example #10
Source File: MetricTypeManualTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenBasicCounter_whenManipulate_thenCountValid() {
    Counter counter = new BasicCounter(MonitorConfig
      .builder("test")
      .build());
    assertEquals("counter should start with 0", 0, counter
      .getValue()
      .intValue());
    counter.increment();
    assertEquals("counter should have increased by 1", 1, counter
      .getValue()
      .intValue());
    counter.increment(-1);
    assertEquals("counter should have decreased by 1", 0, counter
      .getValue()
      .intValue());
}
 
Example #11
Source File: MetricTypeManualTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenInformationalMonitor_whenRecord_thenInformationCollected() throws Exception {
    BasicInformational informational = new BasicInformational(MonitorConfig
      .builder("test")
      .build());
    informational.setValue("information collected");
    assertEquals("information collected", informational.getValue());
}
 
Example #12
Source File: DynoOPMonitor.java    From dyno with Apache License 2.0 5 votes vote down vote up
private BasicCounter getNewCounter(String metricName, String opName, String compressionEnabled) {
    MonitorConfig config = MonitorConfig.builder(metricName)
            .withTag(new BasicTag("dyno_op", opName))
            .withTag(new BasicTag("compression_enabled", compressionEnabled))
            .build();
    return new BasicCounter(config);
}
 
Example #13
Source File: AsyncSuroClient.java    From suro with Apache License 2.0 5 votes vote down vote up
@Override
public void send(Message message) {
    if (!messageQueue.offer(message)) {
        lostMessages.incrementAndGet();
        DynamicCounter.increment(
                MonitorConfig.builder(TagKey.LOST_COUNT)
                        .withTag(TagKey.APP, config.getApp())
                        .withTag(TagKey.DATA_SOURCE, message.getRoutingKey())
                        .build());
        for (Listener listener : listeners) {
            listener.lostCallback(1);
        }
    }
}
 
Example #14
Source File: AsyncSuroClient.java    From suro with Apache License 2.0 5 votes vote down vote up
public void restore(Message message) {
    restoredMessages.incrementAndGet();
    DynamicCounter.increment(
            MonitorConfig.builder(TagKey.RESTORED_COUNT)
                    .withTag(TagKey.APP, config.getApp())
                    .withTag(TagKey.DATA_SOURCE, message.getRoutingKey())
                    .build());
    for (Listener listener : listeners) {
        listener.restoredCallback();
    }
    send(message);
}
 
Example #15
Source File: ServoReporter.java    From suro with Apache License 2.0 5 votes vote down vote up
private void addMetric(KafkaMetric metric) {
    MetricName metricName = metric.metricName();
    MonitorConfig.Builder builder = MonitorConfig.builder(metricName.name())
        .withTag("group", metricName.group());
    for(Map.Entry<String, String> tag : metricName.tags().entrySet()) {
        builder.withTag(tag.getKey(), tag.getValue());
    }
    MonitorConfig monitorConfig = builder.build();
    gauges.put(Servo.getDoubleGauge(monitorConfig), metric);
}
 
Example #16
Source File: KafkaSink.java    From suro with Apache License 2.0 5 votes vote down vote up
private void dropMessage(final String routingKey, final String reason) {
    DynamicCounter.increment(
        MonitorConfig
            .builder("droppedRecord")
            .withTag(TagKey.ROUTING_KEY, routingKey)
            .withTag(TagKey.DROPPED_REASON, reason)
            .build());
    droppedRecords.incrementAndGet();
    runRecordCounterListener();
}
 
Example #17
Source File: QueuedSink.java    From suro with Apache License 2.0 5 votes vote down vote up
protected void initialize(
        String sinkId,
        MessageQueue4Sink queue4Sink,
        int batchSize, int batchTimeout,
        boolean pauseOnLongQueue) {
    this.sinkId = sinkId;
    this.queue4Sink = queue4Sink;
    this.batchSize = batchSize == 0 ? 1000 : batchSize;
    this.batchTimeout = batchTimeout == 0 ? 1000 : batchTimeout;
    this.pauseOnLongQueue = pauseOnLongQueue;

    throughput = new Meter(MonitorConfig.builder(sinkId + "_throughput_meter").build());
}
 
Example #18
Source File: QueuedSink.java    From suro with Apache License 2.0 5 votes vote down vote up
protected void enqueue(Message message) {
    if (!queue4Sink.offer(message)) {
        droppedMessagesCount.incrementAndGet();
        DynamicCounter.increment(
                MonitorConfig.builder(TagKey.DROPPED_COUNT)
                        .withTag("reason", "queueFull")
                        .withTag("sink", sinkId)
                        .build());
    }
}
 
Example #19
Source File: MetricTypeManualTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenGauge_whenCall_thenValueReturned() {
    Gauge<Double> gauge = new BasicGauge<>(MonitorConfig
      .builder("test")
      .build(), () -> 2.32);
    assertEquals(2.32, gauge.getValue(), 0.01);
}
 
Example #20
Source File: EstimatedHistogramBasedCounter.java    From dyno with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of the counter.
 */
public EstimatedHistogramBasedCounter(final String name, final String opName, final EstimatedHistogram histogram) {
    super(MonitorConfig.builder(name).build()
            .withAdditionalTag(DataSourceType.GAUGE)
            .withAdditionalTag(new BasicTag("dyno_op", opName)));
    this.estHistogram = histogram;
}
 
Example #21
Source File: DynoJedisPipelineMonitor.java    From dyno with Apache License 2.0 5 votes vote down vote up
private BasicCounter getNewPipelineCounter(String opName) {

        String metricName = "Dyno__" + appName + "__PL__" + opName;
        MonitorConfig config = MonitorConfig.builder(metricName)
                .withTag(new BasicTag("dyno_pl_op", opName))
                .build();
        return new BasicCounter(config);
    }
 
Example #22
Source File: ServoGauge.java    From spectator with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new monitor that returns {@code value}.
 */
ServoGauge(Id id, Clock clock, MonitorConfig config) {
  super(config.withAdditionalTag(DataSourceType.GAUGE));
  this.id = id;
  this.clock = clock;
  this.value = new AtomicDouble(Double.NaN);
  this.lastUpdated = new AtomicLong(clock.wallTime());
}
 
Example #23
Source File: ServoMaxGauge.java    From spectator with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new monitor that returns {@code value}.
 */
ServoMaxGauge(Id id, Clock clock, MonitorConfig config) {
  super(config.withAdditionalTag(DataSourceType.GAUGE));
  this.id = id;
  this.clock = clock;
  this.impl = new MaxGauge(config);
  this.lastUpdated = new AtomicLong(clock.wallTime());
}
 
Example #24
Source File: DoubleCounter.java    From spectator with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of the counter.
 */
DoubleCounter(MonitorConfig config, Clock clock) {
  // This class will reset the value so it is not a monotonically increasing value as
  // expected for type=COUNTER. This class looks like a counter to the user and a gauge to
  // the publishing pipeline receiving the value.
  super(config.withAdditionalTag(DataSourceType.NORMALIZED));
  count = new StepLong(0L, clock);
}
 
Example #25
Source File: DoubleCounterTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetValueTwice() {
  ManualClock manualClock = new ManualClock(0L);

  DoubleCounter c = new DoubleCounter(MonitorConfig.builder("test").build(), manualClock);
  c.increment(1);
  for (int i = 1; i < 10; ++i) {
    manualClock.set(i * 60000L);
    c.increment(1);
    c.getValue(0);
    Assertions.assertEquals(1 / 60.0, c.getValue(0).doubleValue(), DELTA);
  }
}
 
Example #26
Source File: MetricTypeManualTest.java    From tutorials with MIT License 5 votes vote down vote up
@Ignore
@Test
public void givenStepCounter_whenManipulate_thenRateValid() throws Exception {
    System.setProperty("servo.pollers", "1000");
    Counter counter = new StepCounter(MonitorConfig
      .builder("test")
      .build());
    assertEquals("counter should start with rate 0.0", 0.0, counter.getValue());

    counter.increment();
    SECONDS.sleep(1);

    assertEquals("counter rate should have increased to 1.0", 1.0, counter.getValue());
}
 
Example #27
Source File: MetricTypeManualTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Exception {
    System.setProperty("netflix.servo", "1000");
    StatsTimer timer = new StatsTimer(MonitorConfig
      .builder("test")
      .build(), new StatsConfig.Builder()
      .withComputeFrequencyMillis(2000)
      .withPercentiles(new double[]{99.0, 95.0, 90.0})
      .withPublishMax(true)
      .withPublishMin(true)
      .withPublishCount(true)
      .withPublishMean(true)
      .withPublishStdDev(true)
      .withPublishVariance(true)
        .build(), MILLISECONDS);

    Stopwatch stopwatch = timer.start();
    SECONDS.sleep(1);
    timer.record(3, SECONDS);
    stopwatch.stop();

    stopwatch = timer.start();
    timer.record(6, SECONDS);
    SECONDS.sleep(2);
    stopwatch.stop();

    assertEquals("timer should count 12 seconds in total", 12000, timer.getTotalTime(),500);
    assertEquals("timer should count 12 seconds in total", 12000, timer.getTotalMeasurement(),500);
    assertEquals("timer should record 4 updates", 4, timer.getCount());
    assertEquals("stats timer value time-cost/update should be 2", 3000, timer
      .getValue()
      .intValue(),500);

    final Map<String, Number> metricMap = timer
      .getMonitors()
      .stream()
      .collect(toMap(monitor -> getMonitorTagValue(monitor, "statistic"), monitor -> (Number) monitor.getValue()));

    assertThat(metricMap.keySet(), containsInAnyOrder("count", "totalTime", "max", "min", "variance", "stdDev", "avg", "percentile_99", "percentile_95", "percentile_90"));
}
 
Example #28
Source File: MetricTypeManualTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMaxGauge_whenUpdateMultipleTimes_thenMaxReturned() {
    MaxGauge gauge = new MaxGauge(MonitorConfig
      .builder("test")
      .build());
    assertEquals(0, gauge
      .getValue()
      .intValue());

    gauge.update(4);
    assertEquals(4, gauge.getCurrentValue(0));

    gauge.update(1);
    assertEquals(4, gauge.getCurrentValue(0));
}
 
Example #29
Source File: DoubleCounterTest.java    From spectator with Apache License 2.0 4 votes vote down vote up
private DoubleCounter newInstance(String name) {
  return new DoubleCounter(MonitorConfig.builder(name).build(), clock);
}
 
Example #30
Source File: DoubleCounter.java    From spectator with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of the counter.
 */
DoubleCounter(MonitorConfig config) {
  this(config, ClockWithOffset.INSTANCE);
}