use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class DropwizardCounterServiceSpeedTests method counters.
@Theory
public void counters(String input) throws Exception {
watch.start("counters" + count++);
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
Runnable task = new Runnable() {
@Override
public void run() {
for (int i = 0; i < number; i++) {
String name = sample[i % sample.length];
DropwizardCounterServiceSpeedTests.this.counterService.increment(name);
}
}
};
Collection<Future<?>> futures = new HashSet<>();
for (int i = 0; i < threadCount; i++) {
futures.add(pool.submit(task));
}
for (Future<?> future : futures) {
future.get();
}
watch.stop();
double rate = number / watch.getLastTaskTimeMillis() * 1000;
System.err.println("Counters rate(" + count + ")=" + rate + ", " + watch);
watch.start("read" + count);
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
@Override
public void accept(Metric<?> metric) {
err.println(metric);
}
});
final LongAdder total = new LongAdder();
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
@Override
public void accept(Metric<?> value) {
total.add(value.getValue().intValue());
}
});
watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertThat(total.longValue()).isEqualTo(number * threadCount);
}
use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class RichGaugeReaderPublicMetricsTests method testMetrics.
@Test
public void testMetrics() throws Exception {
InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository();
repository.set(new Metric<>("a", 0.d, new Date()));
repository.set(new Metric<>("a", 0.5d, new Date()));
RichGaugeReaderPublicMetrics metrics = new RichGaugeReaderPublicMetrics(repository);
Map<String, Metric<?>> results = new HashMap<>();
for (Metric<?> metric : metrics.metrics()) {
results.put(metric.getName(), metric);
}
assertThat(results.containsKey("a.val")).isTrue();
assertThat(results.get("a.val").getValue().doubleValue()).isEqualTo(0.5d);
assertThat(results.containsKey("a.avg")).isTrue();
assertThat(results.get("a.avg").getValue().doubleValue()).isEqualTo(0.25d);
assertThat(results.containsKey("a.min")).isTrue();
assertThat(results.get("a.min").getValue().doubleValue()).isEqualTo(0.0d);
assertThat(results.containsKey("a.max")).isTrue();
assertThat(results.get("a.max").getValue().doubleValue()).isEqualTo(0.5d);
assertThat(results.containsKey("a.count")).isTrue();
assertThat(results.get("a.count").getValue().longValue()).isEqualTo(2L);
assertThat(results.containsKey("a.alpha")).isTrue();
assertThat(results.get("a.alpha").getValue().doubleValue()).isEqualTo(-1.d);
}
use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method richGaugePublicMetrics.
@Test
public void richGaugePublicMetrics() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class);
RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class);
assertThat(richGaugeReader).isNotNull();
given(richGaugeReader.findAll()).willReturn(Collections.singletonList(new RichGauge("bar", 3.7d)));
RichGaugeReaderPublicMetrics publicMetrics = context.getBean(RichGaugeReaderPublicMetrics.class);
assertThat(publicMetrics).isNotNull();
Collection<Metric<?>> metrics = publicMetrics.metrics();
assertThat(metrics).isNotNull();
assertThat(6).isEqualTo(metrics.size());
assertHasMetric(metrics, new Metric<>("bar.val", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.avg", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.min", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.max", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.alpha", -1.d));
assertHasMetric(metrics, new Metric<>("bar.count", 1L));
context.close();
}
use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method multipleDataSourcesWithPrimary.
@Test
public void multipleDataSourcesWithPrimary() {
load(MultipleDataSourcesWithPrimaryConfig.class);
PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
Collection<Metric<?>> metrics = bean.metrics();
assertMetrics(metrics, "datasource.primary.active", "datasource.primary.usage", "datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
}
use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method multipleDataSources.
@Test
public void multipleDataSources() {
load(MultipleDataSourcesConfig.class);
PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
Collection<Metric<?>> metrics = bean.metrics();
assertMetrics(metrics, "datasource.tomcat.active", "datasource.tomcat.usage", "datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
// Hikari won't work unless a first connection has been retrieved
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.context.getBean("hikariDS", DataSource.class));
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
return null;
}
});
Collection<Metric<?>> anotherMetrics = bean.metrics();
assertMetrics(anotherMetrics, "datasource.tomcat.active", "datasource.tomcat.usage", "datasource.hikariDS.active", "datasource.hikariDS.usage", "datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
}
Aggregations