use of org.springframework.boot.actuate.endpoint.PublicMetrics in project zipkin by openzipkin.
the class PrometheusMetricsAutoConfiguration method prometheusMetrics.
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<String> prometheusMetrics() {
StringBuilder sb = new StringBuilder();
for (PublicMetrics publicMetrics : this.publicMetrics) {
for (Metric<?> metric : publicMetrics.metrics()) {
final String sanitizedName = sanitizeMetricName(metric.getName());
final String type = typeForName(sanitizedName);
final String metricName = metricName(sanitizedName, type);
double value = metric.getValue().doubleValue();
sb.append(String.format("#TYPE %s %s\n", metricName, type));
sb.append(String.format("#HELP %s %s\n", metricName, metricName));
sb.append(String.format("%s %s\n", metricName, prometheusDouble(value)));
}
}
return ResponseEntity.ok().contentType(MediaType.parseMediaType("text/plain; version=0.0.4; charset=utf-8")).body(sb.toString());
}
use of org.springframework.boot.actuate.endpoint.PublicMetrics in project zipkin by openzipkin.
the class PrometheusMetricsAutoConfigurationTest method defaultsToGauge.
@Test
public void defaultsToGauge() throws Exception {
PublicMetrics publicMetrics = () -> Collections.singleton(new Metric<Number>("mem.free", 1024));
ResponseEntity<String> response = responseForMetrics(publicMetrics);
String body = response.getBody();
assertThat(body, equalTo("#TYPE mem_free gauge\n" + "#HELP mem_free mem_free\n" + "mem_free 1024.0\n"));
}
use of org.springframework.boot.actuate.endpoint.PublicMetrics in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method multipleDataSourcesWithCustomPrimary.
@Test
public void multipleDataSourcesWithCustomPrimary() {
load(MultipleDataSourcesWithCustomPrimaryConfig.class);
PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
Collection<Metric<?>> metrics = bean.metrics();
assertMetrics(metrics, "datasource.primary.active", "datasource.primary.usage", "datasource.dataSource.active", "datasource.dataSource.usage");
}
use of org.springframework.boot.actuate.endpoint.PublicMetrics in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method autoDataSource.
@Test
public void autoDataSource() {
load(DataSourceAutoConfiguration.class);
PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
Collection<Metric<?>> metrics = bean.metrics();
assertMetrics(metrics, "datasource.primary.active", "datasource.primary.usage");
}
use of org.springframework.boot.actuate.endpoint.PublicMetrics in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method customPrefix.
@Test
public void customPrefix() {
load(MultipleDataSourcesWithPrimaryConfig.class, CustomDataSourcePublicMetrics.class);
PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
Collection<Metric<?>> metrics = bean.metrics();
assertMetrics(metrics, "ds.first.active", "ds.first.usage", "ds.second.active", "ds.second.usage");
}
Aggregations