当前位置: 首页>>代码示例>>Java>>正文


Java PublicMetrics类代码示例

本文整理汇总了Java中org.springframework.boot.actuate.endpoint.PublicMetrics的典型用法代码示例。如果您正苦于以下问题:Java PublicMetrics类的具体用法?Java PublicMetrics怎么用?Java PublicMetrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PublicMetrics类属于org.springframework.boot.actuate.endpoint包,在下文中一共展示了PublicMetrics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMetrics

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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();
        });
}
 
开发者ID:cbornet,项目名称:generator-jhipster-grpc,代码行数:22,代码来源:_MetricService.java

示例2: prometheusMetrics

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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());

}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:22,代码来源:PrometheusMetricsAutoConfiguration.java

示例3: multipleDataSources

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:PublicMetricsAutoConfigurationTests.java

示例4: correctHttpResponse

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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"));
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:10,代码来源:PrometheusMetricsAutoConfigurationTest.java

示例5: defaultsToGauge

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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"));
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:PrometheusMetricsAutoConfigurationTest.java

示例6: detectsCounters

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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"));
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:PrometheusMetricsAutoConfigurationTest.java

示例7: detectsGauges

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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"));
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:PrometheusMetricsAutoConfigurationTest.java

示例8: collect

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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());
}
 
开发者ID:maust,项目名称:spring-boot-prometheus,代码行数:16,代码来源:SpringBootMetricsCollector.java

示例9: EndpointAutoConfiguration

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
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();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:EndpointAutoConfiguration.java

示例10: metricsEndpoint

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:EndpointAutoConfiguration.java

示例11: autoDataSource

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:PublicMetricsAutoConfigurationTests.java

示例12: multipleDataSourcesWithPrimary

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:PublicMetricsAutoConfigurationTests.java

示例13: multipleDataSourcesWithCustomPrimary

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:PublicMetricsAutoConfigurationTests.java

示例14: customPrefix

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@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");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:PublicMetricsAutoConfigurationTests.java

示例15: customPublicMetrics

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入依赖的package包/类
@Bean
PublicMetrics customPublicMetrics() {
	return new PublicMetrics() {
		@Override
		public Collection<Metric<?>> metrics() {
			Metric<Integer> metric = new Metric<Integer>("foo", 1);
			return Collections.<Metric<?>>singleton(metric);
		}
	};
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:EndpointAutoConfigurationTests.java


注:本文中的org.springframework.boot.actuate.endpoint.PublicMetrics类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。