Java 类org.springframework.boot.actuate.metrics.writer.Delta 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryMetricRepository.java   
@Override
public void increment(Delta<?> delta) {
    final String metricName = delta.getName();
    final int amount = delta.getValue().intValue();
    final Date timestamp = delta.getTimestamp();
    this.metrics.update(metricName, new Callback<Metric<?>>() {
        @Override
        public Metric<?> modify(Metric<?> current) {
            if (current != null) {
                Metric<? extends Number> metric = current;
                return new Metric<Long>(metricName,
                        metric.increment(amount).getValue(), timestamp);
            }
            else {
                return new Metric<Long>(metricName, Long.valueOf(amount), timestamp);
            }
        }
    });
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisMultiMetricRepositoryTests.java   
@Test
public void increment() {
    this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
    this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
    this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
    Metric<?> bar = null;
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
        if (metric.getName().equals("foo.bar")) {
            bar = metric;
        }
    }
    assertThat(names).hasSize(2).contains("foo.bar");
    assertThat(bar.getValue()).isEqualTo(3d);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricCopyExporterTests.java   
@Test
public void counterWithGaugeWriter() throws Exception {
    SimpleGaugeWriter writer = new SimpleGaugeWriter();
    MetricCopyExporter exporter = new MetricCopyExporter(this.reader, writer);
    try {
        this.reader.increment(new Delta<Number>("counter.foo", 2));
        exporter.export();
        this.reader.increment(new Delta<Number>("counter.foo", 3));
        exporter.export();
        exporter.flush();
        assertThat(writer.getValue().getValue()).isEqualTo(5L);
    }
    finally {
        exporter.close();
    }
}
项目:spring-boot-concourse    文件:InMemoryMetricRepository.java   
@Override
public void increment(Delta<?> delta) {
    final String metricName = delta.getName();
    final int amount = delta.getValue().intValue();
    final Date timestamp = delta.getTimestamp();
    this.metrics.update(metricName, new Callback<Metric<?>>() {
        @Override
        public Metric<?> modify(Metric<?> current) {
            if (current != null) {
                Metric<? extends Number> metric = current;
                return new Metric<Long>(metricName,
                        metric.increment(amount).getValue(), timestamp);
            }
            else {
                return new Metric<Long>(metricName, Long.valueOf(amount), timestamp);
            }
        }
    });
}
项目:spring-boot-concourse    文件:RedisMultiMetricRepositoryTests.java   
@Test
public void increment() {
    this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
    this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
    this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
    Metric<?> bar = null;
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
        if (metric.getName().equals("foo.bar")) {
            bar = metric;
        }
    }
    assertThat(names).hasSize(2).contains("foo.bar");
    assertThat(bar.getValue()).isEqualTo(3d);
}
项目:spring-boot-concourse    文件:MetricCopyExporterTests.java   
@Test
public void counterWithGaugeWriter() throws Exception {
    SimpleGaugeWriter writer = new SimpleGaugeWriter();
    MetricCopyExporter exporter = new MetricCopyExporter(this.reader, writer);
    try {
        this.reader.increment(new Delta<Number>("counter.foo", 2));
        exporter.export();
        this.reader.increment(new Delta<Number>("counter.foo", 3));
        exporter.export();
        exporter.flush();
        assertThat(writer.getValue().getValue()).isEqualTo(5L);
    }
    finally {
        exporter.close();
    }
}
项目:contestparser    文件:InMemoryMetricRepository.java   
@Override
public void increment(Delta<?> delta) {
    final String metricName = delta.getName();
    final int amount = delta.getValue().intValue();
    final Date timestamp = delta.getTimestamp();
    this.metrics.update(metricName, new Callback<Metric<?>>() {
        @Override
        public Metric<?> modify(Metric<?> current) {
            if (current != null) {
                Metric<? extends Number> metric = current;
                return new Metric<Long>(metricName,
                        metric.increment(amount).getValue(), timestamp);
            }
            else {
                return new Metric<Long>(metricName, new Long(amount), timestamp);
            }
        }
    });
}
项目:contestparser    文件:RedisMultiMetricRepositoryTests.java   
@Test
public void increment() {
    this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
    this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
    this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
    Metric<?> bar = null;
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
        if (metric.getName().equals("foo.bar")) {
            bar = metric;
        }
    }
    assertEquals(2, names.size());
    assertTrue("Wrong names: " + names, names.contains("foo.bar"));
    assertEquals(3d, bar.getValue());
}
项目:statful-client-springboot    文件:StatfulClientProxy.java   
/**
 * Ingest a raw {@link Delta}.
 *
 * @param delta Raw {@link Delta} exported by springboot
 */
public void ingestMetric(Delta<?> delta) {
    ExportedMetric exportedMetric = new ExportedMetric.Builder()
            .withName(delta.getName())
            .withValue(delta.getValue().doubleValue())
            .withTimestamp(delta.getTimestamp().getTime() / 1000L)
            .build();

    ingest(exportedMetric);
}
项目:statful-client-springboot    文件:StatfulMetricWriterTest.java   
@Test
public void shouldIngestMetricOnIncrement() {
    // When
    Delta delta = new Delta<>("foo", 1L);
    subject.increment(delta);

    // Then
    verify(statfulClientProxy).ingestMetric(delta);
}
项目:statful-client-springboot    文件:StatfulClientProxyTest.java   
@Test
public void shouldIngestFromDelta() {
    // Given
    when(statfulMetricProcessor.validate(any())).thenReturn(true);
    List<ProcessedMetric> processedMetrics = Lists.newArrayList(getProcessedMetric());
    when(statfulMetricProcessor.process(any())).thenReturn(processedMetrics);
    Delta delta = new Delta<>(METRIC_NAME, 1L);

    // When
    subject.ingestMetric(delta);

    // Then
    verify(statfulClient).put(eq(INGESTED_METRIC_NAME), eq(Double.toString(1L)), any(Tags.class), eq(null),
            eq(null), anyInt(), eq(NAMESPACE), anyInt());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryMetricRepository.java   
@Override
public void increment(String group, Delta<?> delta) {
    String prefix = group;
    if (!prefix.endsWith(".")) {
        prefix = prefix + ".";
    }
    if (!delta.getName().startsWith(prefix)) {
        delta = new Delta<Number>(prefix + delta.getName(), delta.getValue(),
                delta.getTimestamp());
    }
    increment(delta);
    this.groups.add(group);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisMetricRepository.java   
@Override
public void increment(Delta<?> delta) {
    String name = delta.getName();
    String key = keyFor(name);
    trackMembership(key);
    double value = this.zSetOperations.incrementScore(key,
            delta.getValue().doubleValue());
    String raw = serialize(new Metric<Double>(name, value, delta.getTimestamp()));
    this.redisOperations.opsForValue().set(key, raw);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisMultiMetricRepository.java   
@Override
public void increment(String group, Delta<?> delta) {
    String groupKey = keyFor(group);
    trackMembership(groupKey);
    BoundZSetOperations<String, String> zSetOperations = this.redisOperations
            .boundZSetOps(groupKey);
    String key = keyFor(delta.getName());
    double value = zSetOperations.incrementScore(key, delta.getValue().doubleValue());
    String raw = serialize(
            new Metric<Double>(delta.getName(), value, delta.getTimestamp()));
    this.redisOperations.opsForValue().set(key, raw);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricCopyExporter.java   
private Delta<?> calculateDelta(Metric<?> value) {
    long delta = value.getValue().longValue();
    Long old = this.counts.replace(value.getName(), delta);
    if (old != null) {
        delta = delta - old;
    }
    else {
        this.counts.putIfAbsent(value.getName(), delta);
    }
    return new Delta<Long>(value.getName(), delta, value.getTimestamp());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PrefixMetricGroupExporter.java   
private Delta<?> calculateDelta(Metric<?> value) {
    long delta = value.getValue().longValue();
    Long old = this.counts.replace(value.getName(), delta);
    if (old != null) {
        delta = delta - old;
    }
    else {
        this.counts.putIfAbsent(value.getName(), delta);
    }
    return new Delta<Long>(value.getName(), delta, value.getTimestamp());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AggregateMetricReaderTests.java   
@Test
public void incrementCounter() {
    this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L));
    this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L));
    assertThat(this.reader.findOne("aggregate.counter.spam").getValue())
            .isEqualTo(5L);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AggregateMetricReaderTests.java   
@Test
public void countGaugesAndCounters() {
    this.source.set(new Metric<Double>("foo.bar.spam", 2.3));
    this.source.set(new Metric<Double>("oof.rab.spam", 2.4));
    this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L));
    this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L));
    assertThat(this.reader.count()).isEqualTo(2);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisMetricRepositoryTests.java   
@Test
public void setIncrementAndGet() {
    this.repository.set(new Metric<Number>("foo", 12.3));
    this.repository.increment(new Delta<Long>("foo", 3L));
    Metric<?> metric = this.repository.findOne("foo");
    assertThat(metric.getName()).isEqualTo("foo");
    assertThat(metric.getValue().doubleValue()).isEqualTo(15.3, offset(0.01));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void registeredPrefixCounted() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    this.repository.increment(new Delta<Number>("foo.spam", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(2);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void prefixWithWildcard() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo.*")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(1);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void prefixWithPeriod() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo.")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(1);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void onlyRegisteredPrefixCounted() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    this.repository.increment(new Delta<Number>("foobar.spam", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(1);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void incrementGroup() {
    this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
    this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
    this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(2);
    assertThat(names.contains("foo.bar")).isTrue();
    assertThat(this.repository.findOne("foo.bar").getValue()).isEqualTo(3L);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricCopyExporterTests.java   
@Test
public void counter() {
    this.reader.increment(new Delta<Number>("counter.foo", 2));
    this.exporter.export();
    assertThat(this.writer.count()).isEqualTo(1);
    this.reader.increment(new Delta<Number>("counter.foo", 3));
    this.exporter.export();
    this.exporter.flush();
    assertThat(this.writer.findOne("counter.foo").getValue()).isEqualTo(5L);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PrefixMetricGroupExporterTests.java   
@Test
public void countersIncremented() {
    this.writer.increment("counter.foo", new Delta<Long>("bar", 1L));
    this.reader.set(new Metric<Number>("counter.foo.bar", 1));
    this.exporter.setGroups(Collections.singleton("counter.foo"));
    this.exporter.export();
    assertThat(this.writer.findAll("counter.foo").iterator().next().getValue())
            .isEqualTo(2L);
}
项目:jhipster    文件:SpectatorLogMetricWriterTest.java   
@Test
public void testIncrement() {
    Delta<Double> delta = new Delta<>("foo.bar", 42D);

    writer.increment(delta);

    List<Event> events = recorder.play();
    assertThat(events).hasSize(1);
    Event event = events.get(0);
    assertThat(event.getMessage()).isEqualTo(SpectatorLogMetricWriter.INCREMENT_MESSAGE);
    Object[] args = event.getArguments();
    assertThat(args).hasSize(2);
    assertThat(args[0]).isEqualTo("foo.bar");
    assertThat(args[1]).isEqualTo(42D);
}
项目:spring-boot-concourse    文件:InMemoryMetricRepository.java   
@Override
public void increment(String group, Delta<?> delta) {
    String prefix = group;
    if (!prefix.endsWith(".")) {
        prefix = prefix + ".";
    }
    if (!delta.getName().startsWith(prefix)) {
        delta = new Delta<Number>(prefix + delta.getName(), delta.getValue(),
                delta.getTimestamp());
    }
    increment(delta);
    this.groups.add(group);
}
项目:spring-boot-concourse    文件:RedisMetricRepository.java   
@Override
public void increment(Delta<?> delta) {
    String name = delta.getName();
    String key = keyFor(name);
    trackMembership(key);
    double value = this.zSetOperations.incrementScore(key,
            delta.getValue().doubleValue());
    String raw = serialize(new Metric<Double>(name, value, delta.getTimestamp()));
    this.redisOperations.opsForValue().set(key, raw);
}
项目:spring-boot-concourse    文件:RedisMultiMetricRepository.java   
@Override
public void increment(String group, Delta<?> delta) {
    String groupKey = keyFor(group);
    trackMembership(groupKey);
    BoundZSetOperations<String, String> zSetOperations = this.redisOperations
            .boundZSetOps(groupKey);
    String key = keyFor(delta.getName());
    double value = zSetOperations.incrementScore(key, delta.getValue().doubleValue());
    String raw = serialize(
            new Metric<Double>(delta.getName(), value, delta.getTimestamp()));
    this.redisOperations.opsForValue().set(key, raw);
}
项目:spring-boot-concourse    文件:MetricCopyExporter.java   
private Delta<?> calculateDelta(Metric<?> value) {
    long delta = value.getValue().longValue();
    Long old = this.counts.replace(value.getName(), delta);
    if (old != null) {
        delta = delta - old;
    }
    else {
        this.counts.putIfAbsent(value.getName(), delta);
    }
    return new Delta<Long>(value.getName(), delta, value.getTimestamp());
}
项目:spring-boot-concourse    文件:PrefixMetricGroupExporter.java   
private Delta<?> calculateDelta(Metric<?> value) {
    long delta = value.getValue().longValue();
    Long old = this.counts.replace(value.getName(), delta);
    if (old != null) {
        delta = delta - old;
    }
    else {
        this.counts.putIfAbsent(value.getName(), delta);
    }
    return new Delta<Long>(value.getName(), delta, value.getTimestamp());
}
项目:spring-boot-concourse    文件:AggregateMetricReaderTests.java   
@Test
public void incrementCounter() {
    this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L));
    this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L));
    assertThat(this.reader.findOne("aggregate.counter.spam").getValue())
            .isEqualTo(5L);
}
项目:spring-boot-concourse    文件:AggregateMetricReaderTests.java   
@Test
public void countGaugesAndCounters() {
    this.source.set(new Metric<Double>("foo.bar.spam", 2.3));
    this.source.set(new Metric<Double>("oof.rab.spam", 2.4));
    this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L));
    this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L));
    assertThat(this.reader.count()).isEqualTo(2);
}
项目:spring-boot-concourse    文件:RedisMetricRepositoryTests.java   
@Test
public void setIncrementAndGet() {
    this.repository.set(new Metric<Number>("foo", 12.3));
    this.repository.increment(new Delta<Long>("foo", 3L));
    Metric<?> metric = this.repository.findOne("foo");
    assertThat(metric.getName()).isEqualTo("foo");
    assertThat(metric.getValue().doubleValue()).isEqualTo(15.3, offset(0.01));
}
项目:spring-boot-concourse    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void registeredPrefixCounted() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    this.repository.increment(new Delta<Number>("foo.spam", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(2);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:spring-boot-concourse    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void prefixWithWildcard() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo.*")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(1);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:spring-boot-concourse    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void prefixWithPeriod() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo.")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(1);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:spring-boot-concourse    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void onlyRegisteredPrefixCounted() {
    this.repository.increment(new Delta<Number>("foo.bar", 1));
    this.repository.increment(new Delta<Number>("foobar.spam", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(1);
    assertThat(names.contains("foo.bar")).isTrue();
}
项目:spring-boot-concourse    文件:InMemoryPrefixMetricRepositoryTests.java   
@Test
public void incrementGroup() {
    this.repository.increment("foo", new Delta<Number>("foo.bar", 1));
    this.repository.increment("foo", new Delta<Number>("foo.bar", 2));
    this.repository.increment("foo", new Delta<Number>("foo.spam", 1));
    Set<String> names = new HashSet<String>();
    for (Metric<?> metric : this.repository.findAll("foo")) {
        names.add(metric.getName());
    }
    assertThat(names).hasSize(2);
    assertThat(names.contains("foo.bar")).isTrue();
    assertThat(this.repository.findOne("foo.bar").getValue()).isEqualTo(3L);
}