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


Java PublicMetrics.metrics方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: createMetricsServlet

import org.springframework.boot.actuate.endpoint.PublicMetrics; //导入方法依赖的package包/类
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);
    }
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:15,代码来源:MetricsConfig.java

示例9: collect

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


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