Search in sources :

Example 6 with PublicMetrics

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());
}
Also used : PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with PublicMetrics

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"));
}
Also used : PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) Test(org.junit.Test)

Example 8 with PublicMetrics

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");
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) MetricReaderPublicMetrics(org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics) CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) DataSourcePublicMetrics(org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics) TomcatPublicMetrics(org.springframework.boot.actuate.endpoint.TomcatPublicMetrics) PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) SystemPublicMetrics(org.springframework.boot.actuate.endpoint.SystemPublicMetrics) Test(org.junit.Test)

Example 9 with PublicMetrics

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");
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) MetricReaderPublicMetrics(org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics) CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) DataSourcePublicMetrics(org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics) TomcatPublicMetrics(org.springframework.boot.actuate.endpoint.TomcatPublicMetrics) PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) SystemPublicMetrics(org.springframework.boot.actuate.endpoint.SystemPublicMetrics) Test(org.junit.Test)

Example 10 with PublicMetrics

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");
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) MetricReaderPublicMetrics(org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics) CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) DataSourcePublicMetrics(org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics) TomcatPublicMetrics(org.springframework.boot.actuate.endpoint.TomcatPublicMetrics) PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) SystemPublicMetrics(org.springframework.boot.actuate.endpoint.SystemPublicMetrics) Test(org.junit.Test)

Aggregations

PublicMetrics (org.springframework.boot.actuate.endpoint.PublicMetrics)10 Test (org.junit.Test)9 CachePublicMetrics (org.springframework.boot.actuate.endpoint.CachePublicMetrics)5 DataSourcePublicMetrics (org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics)5 MetricReaderPublicMetrics (org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics)5 RichGaugeReaderPublicMetrics (org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics)5 SystemPublicMetrics (org.springframework.boot.actuate.endpoint.SystemPublicMetrics)5 TomcatPublicMetrics (org.springframework.boot.actuate.endpoint.TomcatPublicMetrics)5 Metric (org.springframework.boot.actuate.metrics.Metric)5 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)1 DataAccessException (org.springframework.dao.DataAccessException)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1