Java 类org.springframework.boot.actuate.endpoint.PublicMetrics 实例源码

项目:generator-jhipster-grpc    文件:_MetricService.java   
@Override
public Flux<Metric> getMetrics(Mono<Empty> request) {
    return request
        .flatMapIterable(empty -> publicMetrics)
        .flatMapIterable(PublicMetrics::metrics)
        .map(metric -> {
            Metric.Builder builder = Metric.newBuilder()
                .setName(metric.getName());
            if (metric.getTimestamp() != null) {
                builder.setTimestamp(ProtobufMappers.dateToTimestamp(metric.getTimestamp()));
            }
            if (metric.getValue() instanceof Long || metric.getValue() instanceof Integer) {
                builder.setLongValue(metric.getValue().longValue());
            } else if (metric.getValue() instanceof Float || metric.getValue() instanceof Double) {
                builder.setDoubleValue((metric.getValue()).doubleValue());
            } else {
                builder.setStringValue(metric.getValue().toString());
            }
            return builder.build();
        });
}
项目:zipkin    文件:PrometheusMetricsAutoConfiguration.java   
@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());

}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:spring-boot-concourse    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:contestparser    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:zipkin    文件:PrometheusMetricsAutoConfigurationTest.java   
@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"));
}
项目:zipkin    文件:PrometheusMetricsAutoConfigurationTest.java   
@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"));
}
项目:zipkin    文件:PrometheusMetricsAutoConfigurationTest.java   
@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"));
}
项目:zipkin    文件:PrometheusMetricsAutoConfigurationTest.java   
@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"));
}
项目:spring-boot-prometheus    文件:SpringBootMetricsCollector.java   
@Override
public List<MetricFamilySamples> collect() {
  Map<String, MetricFamilySamples> samples = new HashMap<String, MetricFamilySamples>();
  for (PublicMetrics publicMetrics : this.publicMetrics) {
    for (Metric<?> metric : publicMetrics.metrics()) {
      String name = Collector.sanitizeMetricName(metric.getName());
      double value = metric.getValue().doubleValue();
      MetricFamilySamples metricFamilySamples = new MetricFamilySamples(
              name, Type.GAUGE, name, Collections.singletonList(new MetricFamilySamples.Sample(
                  name, Collections.<String>emptyList(), Collections.<String>emptyList(), value)));
      samples.put(name, metricFamilySamples);
    }
  }
  return new ArrayList<MetricFamilySamples>(samples.values());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointAutoConfiguration.java   
public EndpointAutoConfiguration(
        ObjectProvider<HealthAggregator> healthAggregatorProvider,
        ObjectProvider<Map<String, HealthIndicator>> healthIndicatorsProvider,
        ObjectProvider<List<InfoContributor>> infoContributorsProvider,
        ObjectProvider<Collection<PublicMetrics>> publicMetricsProvider,
        ObjectProvider<TraceRepository> traceRepositoryProvider) {
    this.healthAggregator = healthAggregatorProvider.getIfAvailable();
    this.healthIndicators = healthIndicatorsProvider.getIfAvailable();
    this.infoContributors = infoContributorsProvider.getIfAvailable();
    this.publicMetrics = publicMetricsProvider.getIfAvailable();
    this.traceRepository = traceRepositoryProvider.getIfAvailable();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public MetricsEndpoint metricsEndpoint() {
    List<PublicMetrics> publicMetrics = new ArrayList<PublicMetrics>();
    if (this.publicMetrics != null) {
        publicMetrics.addAll(this.publicMetrics);
    }
    Collections.sort(publicMetrics, AnnotationAwareOrderComparator.INSTANCE);
    return new MetricsEndpoint(publicMetrics);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointAutoConfigurationTests.java   
@Bean
PublicMetrics customPublicMetrics() {
    return new PublicMetrics() {
        @Override
        public Collection<Metric<?>> metrics() {
            Metric<Integer> metric = new Metric<Integer>("foo", 1);
            return Collections.<Metric<?>>singleton(metric);
        }
    };
}
项目:spring-boot-starter-prometheus    文件:PrometheusEndpoint.java   
public PrometheusEndpoint(Collection<PublicMetrics> publicMetrics,
        PrometeusMetricNameConverter prometeusMetricNameConverter, Map<String, HealthIndicator> healthIndicators,
        HealthAggregator healthAggregator) {
    super("prometheus", false, true);
    this.publicMetrics = publicMetrics;
    this.prometeusMetricNameConverter = prometeusMetricNameConverter;
    this.healthIndicators = healthIndicators;
    this.healthAggregator = healthAggregator;

}
项目:spring-boot-starter-prometheus    文件:PrometheusEndpointConfiguration.java   
@Bean
@ConditionalOnMissingBean
@Autowired
public PrometheusEndpoint prometheusEndpoint(Collection<PublicMetrics> publicMetrics,
        PrometeusMetricNameConverter prometeusMetricNameConverter, Map<String, HealthIndicator> healthIndicators,
        HealthAggregator healthAggregator) {

    return new PrometheusEndpoint(publicMetrics, prometeusMetricNameConverter, healthIndicators, healthAggregator);
}
项目:spring-boot-concourse    文件:EndpointAutoConfiguration.java   
public EndpointAutoConfiguration(
        ObjectProvider<HealthAggregator> healthAggregatorProvider,
        ObjectProvider<Map<String, HealthIndicator>> healthIndicatorsProvider,
        ObjectProvider<List<InfoContributor>> infoContributorsProvider,
        ObjectProvider<Collection<PublicMetrics>> publicMetricsProvider,
        ObjectProvider<TraceRepository> traceRepositoryProvider) {
    this.healthAggregator = healthAggregatorProvider.getIfAvailable();
    this.healthIndicators = healthIndicatorsProvider.getIfAvailable();
    this.infoContributors = infoContributorsProvider.getIfAvailable();
    this.publicMetrics = publicMetricsProvider.getIfAvailable();
    this.traceRepository = traceRepositoryProvider.getIfAvailable();
}
项目:spring-boot-concourse    文件:EndpointAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public MetricsEndpoint metricsEndpoint() {
    List<PublicMetrics> publicMetrics = new ArrayList<PublicMetrics>();
    if (this.publicMetrics != null) {
        publicMetrics.addAll(this.publicMetrics);
    }
    Collections.sort(publicMetrics, AnnotationAwareOrderComparator.INSTANCE);
    return new MetricsEndpoint(publicMetrics);
}
项目:spring-boot-concourse    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:spring-boot-concourse    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:spring-boot-concourse    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:spring-boot-concourse    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:spring-boot-concourse    文件:EndpointAutoConfigurationTests.java   
@Bean
PublicMetrics customPublicMetrics() {
    return new PublicMetrics() {
        @Override
        public Collection<Metric<?>> metrics() {
            Metric<Integer> metric = new Metric<Integer>("foo", 1);
            return Collections.<Metric<?>>singleton(metric);
        }
    };
}
项目:citizenship-appointment-server    文件:MetricsConfig.java   
private MetricsServlet createMetricsServlet(PublicMetrics publicMetrics) {
        CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry;
        MetricRegistry metricRegistry = new MetricRegistry();
        for (Metric<?> metric : publicMetrics.metrics()) {
            Counter counter = metricRegistry.counter(metric.getName());
            counter.dec(counter.getCount());
            counter.inc(Double.valueOf(metric.getValue().toString()).longValue());
        }
        DropwizardExports dropwizardExports = new DropwizardExports(metricRegistry);
//        List<Collector.MetricFamilySamples> metricFamilySamples = dropwizardExports.collect();

        collectorRegistry.register(dropwizardExports);
        return new MetricsServlet(collectorRegistry);
    }
项目:contestparser    文件:EndpointAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public MetricsEndpoint metricsEndpoint() {
    List<PublicMetrics> publicMetrics = new ArrayList<PublicMetrics>();
    if (this.publicMetrics != null) {
        publicMetrics.addAll(this.publicMetrics);
    }
    Collections.sort(publicMetrics, AnnotationAwareOrderComparator.INSTANCE);
    return new MetricsEndpoint(publicMetrics);
}
项目:contestparser    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:contestparser    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:contestparser    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:contestparser    文件:PublicMetricsAutoConfigurationTests.java   
@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");
}
项目:contestparser    文件:EndpointAutoConfigurationTests.java   
@Bean
PublicMetrics customPublicMetrics() {
    return new PublicMetrics() {
        @Override
        public Collection<Metric<?>> metrics() {
            Metric<Integer> metric = new Metric<Integer>("foo", 1);
            return Collections.<Metric<?>>singleton(metric);
        }
    };
}
项目:bulbs-core    文件:MonitoringConfig.java   
@Bean
public PublicMetrics threadPoolMetrics() {
    return new PublicMetricsAggregator(
        new ThreadPoolMetrics(ctx),
        new MetricReaderPublicMetrics(metricRepository())
    );
}
项目:client_java    文件:SpringBootMetricsCollector.java   
@Override
public List<MetricFamilySamples> collect() {
  ArrayList<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>();
  for (PublicMetrics publicMetrics : this.publicMetrics) {
    for (Metric<?> metric : publicMetrics.metrics()) {
      String name = Collector.sanitizeMetricName(metric.getName());
      double value = metric.getValue().doubleValue();
      MetricFamilySamples metricFamilySamples = new MetricFamilySamples(
              name, Type.GAUGE, name, Collections.singletonList(
              new MetricFamilySamples.Sample(name, Collections.<String>emptyList(), Collections.<String>emptyList(), value)));
      samples.add(metricFamilySamples);
    }
  }
  return samples;
}
项目:generator-jhipster-grpc    文件:_MetricService.java   
/**
 * Create a new {@link MetricService} instance.
 * @param publicMetrics the metrics to expose. The collection will be sorted using the
 * {@link AnnotationAwareOrderComparator}.
 */
public MetricService(Collection<PublicMetrics> publicMetrics) {
    Assert.notNull(publicMetrics, "PublicMetrics must not be null");
    this.publicMetrics = new ArrayList<>(publicMetrics);
    AnnotationAwareOrderComparator.sort(this.publicMetrics);
}
项目:zipkin    文件:PrometheusMetricsAutoConfiguration.java   
@Autowired
public PrometheusMetricsAutoConfiguration(Collection<PublicMetrics> publicMetrics) {
    this.publicMetrics = publicMetrics;
}
项目:zipkin    文件:PrometheusMetricsAutoConfigurationTest.java   
private ResponseEntity<String> responseForMetrics(PublicMetrics publicMetrics) {
    PrometheusMetricsAutoConfiguration pmc = new PrometheusMetricsAutoConfiguration(Collections.singleton(publicMetrics));

    return pmc.prometheusMetrics();
}
项目:cat-boot    文件:ClusterMetricsConfig.java   
@Bean
public PublicMetrics metricsAggregate() {
    return new MetricReaderPublicMetrics(aggregatesMetricReader());
}
项目:spring-boot-prometheus    文件:SpringBootMetricsCollector.java   
SpringBootMetricsCollector(Collection<PublicMetrics> publicMetrics) {
  this.publicMetrics = publicMetrics;
}