Search in sources :

Example 1 with PublicMetrics

use of org.springframework.boot.actuate.endpoint.PublicMetrics in project zipkin by openzipkin.

the class PrometheusMetricsAutoConfigurationTest method correctHttpResponse.

@Test
public void correctHttpResponse() throws Exception {
    PublicMetrics publicMetrics = () -> Collections.singleton(new Metric<Number>("mem.free", 1024));
    ResponseEntity<String> response = responseForMetrics(publicMetrics);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
    assertThat(response.getHeaders().getContentType().toString(), equalTo("text/plain;version=0.0.4;charset=utf-8"));
}
Also used : PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) Test(org.junit.Test)

Example 2 with PublicMetrics

use of org.springframework.boot.actuate.endpoint.PublicMetrics in project zipkin by openzipkin.

the class PrometheusMetricsAutoConfigurationTest method detectsCounters.

@Test
public void detectsCounters() throws Exception {
    PublicMetrics publicMetrics = () -> Collections.singleton(new Metric<Number>("counter_mem.free", 1024));
    ResponseEntity<String> response = responseForMetrics(publicMetrics);
    String body = response.getBody();
    assertThat(body, equalTo("#TYPE mem_free counter\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 3 with PublicMetrics

use of org.springframework.boot.actuate.endpoint.PublicMetrics in project zipkin by openzipkin.

the class PrometheusMetricsAutoConfigurationTest method detectsGauges.

@Test
public void detectsGauges() throws Exception {
    PublicMetrics publicMetrics = () -> Collections.singleton(new Metric<Number>("gauge_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 4 with PublicMetrics

use of org.springframework.boot.actuate.endpoint.PublicMetrics 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");
}
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 5 with PublicMetrics

use of org.springframework.boot.actuate.endpoint.PublicMetrics 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");
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) 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) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataAccessException(org.springframework.dao.DataAccessException) DataSource(javax.sql.DataSource) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) 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