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


Java Counter类代码示例

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


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

示例1: addCounter

import io.prometheus.client.Counter; //导入依赖的package包/类
public Counter.Child addCounter(String subsystem, String metric, String helpDoc, SortedMap<String, String> labels) {
    lock.writeLock().lock();
    try {
        String name = name(subsystem, metric);
        Counter counter = counters.get(name);
        if (counter == null) {
            counter = Counter.build().name(name(subsystem, metric)).help(helpDoc).
                    labelNames(labels.keySet().toArray(new String[]{})).create();
            counter.register(registry);
            counters.put(name, counter);
        }
        return counter.labels(labels.values().toArray(new String[]{}));
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:17,代码来源:HystrixMetricsCollector.java

示例2: create

import io.prometheus.client.Counter; //导入依赖的package包/类
@Test
public void create() throws Exception {
  Counter counter1 = CounterFactory.create(
      Metric.builder()
          .setService(CounterFactoryTest.class)
          .setAction("test")
          .build()
  );
  assertThat(counter1).isNotNull();

  //test cached counter
  Counter counter2 = CounterFactory.create(
      Metric.builder()
          .setService(CounterFactoryTest.class)
          .setAction("test")
          .build()
  );
  assertThat(counter1).isSameAs(counter2);
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:20,代码来源:CounterFactoryTest.java

示例3: ServletHook

import io.prometheus.client.Counter; //导入依赖的package包/类
public ServletHook(MetricsStore metricsStore) {

        httpRequestsTotal = metricsStore.createOrGet(new MetricDef<>(
                "http_requests_total",
                (name, registry) -> Counter.build()
                        .name(name)
                        .labelNames("method", "path", "status")
                        .help("Total number of http requests.")
                        .register(registry)
        ));

        httpRequestsDuration = metricsStore.createOrGet(new MetricDef<>(
                "http_request_duration",
                (name, registry) -> Summary.build()
                        .quantile(0.5, 0.05)   // Add 50th percentile (= median) with 5% tolerated error
                        .quantile(0.9, 0.01)   // Add 90th percentile with 1% tolerated error
                        .quantile(0.99, 0.001) // Add 99th percentile with 0.1% tolerated error
                        .name(name)
                        .labelNames("method", "path", "status")
                        .help("Duration for serving the http requests in seconds.")
                        .register(registry)
        ));
    }
 
开发者ID:fstab,项目名称:promagent,代码行数:24,代码来源:ServletHook.java

示例4: createAssertionCollector

import io.prometheus.client.Counter; //导入依赖的package包/类
protected void createAssertionCollector(){
	if (!collectAssertions){
		return;
	}
	
	String[] labelNames = new String[]{};
	
	if (SampleEvent.getVarCount() > 0) {
		labelNames = this.combineAssertionLabelsWithSampleVars();
	}else {
		labelNames = this.assertionConfig.getLabels();
	}
	
	if(this.getSaveConfig().getAssertionClass().equals(Summary.class))
		this.assertionsCollector = Summary.build().name("jmeter_assertions_total").help("Counter for assertions")
			.labelNames(labelNames).quantile(0.5, 0.1).quantile(0.99, 0.1)
			.create().register(CollectorRegistry.defaultRegistry);
	
	else if(this.getSaveConfig().getAssertionClass().equals(Counter.class))
		this.assertionsCollector = Counter.build().name("jmeter_assertions_total").help("Counter for assertions")
		.labelNames(labelNames).create().register(CollectorRegistry.defaultRegistry);
		
}
 
开发者ID:johrstrom,项目名称:jmeter-prometheus-plugin,代码行数:24,代码来源:PrometheusListener.java

示例5: parseMetrics

import io.prometheus.client.Counter; //导入依赖的package包/类
@Test
public void parseMetrics() throws IOException {
    final Counter counter = Counter
            .build("testcounter", "testdescription")
            .labelNames("one", "two")
            .register();
    counter.labels("1", "2").inc();
    final HttpExchange mockExchange = mock(HttpExchange.class);
    final OutputStream outputStream = new ByteArrayOutputStream();
    when(mockExchange.getResponseBody()).thenReturn(outputStream);
    final Headers headers = new Headers();
    when(mockExchange.getResponseHeaders()).thenReturn(headers);

    new PrometheusWebConsole().getServlet().handle(mockExchange);

    assertEquals(TextFormat.CONTENT_TYPE_004, headers.get("Content-Type").get(0));

    final String response = outputStream.toString();
    assertTrue(response.contains("# HELP testcounter testdescription"));
    assertTrue(response.contains("# TYPE testcounter counter"));
    assertTrue(response.contains("one=\"1\""));
    assertTrue(response.contains("two=\"2\""));
}
 
开发者ID:secondbase,项目名称:secondbase,代码行数:24,代码来源:PrometheusWebConsoleTest.java

示例6: createAndRegisterCounted

import io.prometheus.client.Counter; //导入依赖的package包/类
public static Counter createAndRegisterCounted(String name, String[] labels, String doc) {
    Counter.Builder builder = Counter.build().name(name).help(doc);
    if (labels != null) {
        builder.labelNames(labels);
    }

    return builder.register();
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:9,代码来源:PrometheusMetricSystem.java

示例7: createAndRegisterExceptionCounted

import io.prometheus.client.Counter; //导入依赖的package包/类
public static Counter createAndRegisterExceptionCounted(String name, String[] labels, String doc) {
    Counter.Builder builder = Counter.build().name(name).help(doc);
    if (labels != null) {
        builder.labelNames(labels);
    }

    return builder.register();
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:9,代码来源:PrometheusMetricSystem.java

示例8: recordCount

import io.prometheus.client.Counter; //导入依赖的package包/类
public static void recordCount(Counter counter, String[] labels) {
    if (labels != null) {
        counter.labels(labels).inc();
    } else {
        counter.inc();
    }
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:8,代码来源:PrometheusMetricSystem.java

示例9: load

import io.prometheus.client.Counter; //导入依赖的package包/类
@Override
public Counter load(Metric metric) throws Exception {
  final String metricName = getMetricName(metric);

  Counter.Builder countBuilder = Counter.build()
      .name(metricName)
      .help(metricName);

  if (metric.labels().isPresent()) {
    countBuilder.labelNames(metric.labels().get().toArray(new String[metric.labels().get().size()]));
  }

  return countBuilder.create().register();
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:15,代码来源:CounterFactory.java

示例10: JdbcHook

import io.prometheus.client.Counter; //导入依赖的package包/类
public JdbcHook(MetricsStore metricsStore) {

        sqlQueriesTotal = metricsStore.createOrGet(new MetricDef<>(
                "sql_queries_total",
                (name, registry) -> Counter.build()
                        .name(name)
                        .labelNames("method", "path", "query")
                        .help("Total number of sql queries.")
                        .register(registry)
        ));

        sqlQueriesDuration = metricsStore.createOrGet(new MetricDef<>(
                "sql_query_duration",
                (name, registry) -> Summary.build()
                        .quantile(0.5, 0.05)   // Add 50th percentile (= median) with 5% tolerated error
                        .quantile(0.9, 0.01)   // Add 90th percentile with 1% tolerated error
                        .quantile(0.99, 0.001) // Add 99th percentile with 0.1% tolerated error
                        .name(name)
                        .labelNames("method", "path", "query")
                        .help("Duration for serving the sql queries in seconds.")
                        .register(registry)
        ));
    }
 
开发者ID:fstab,项目名称:promagent,代码行数:24,代码来源:JdbcHook.java

示例11: PrometheusMetricsReporter

import io.prometheus.client.Counter; //导入依赖的package包/类
private PrometheusMetricsReporter(CollectorRegistry registry, List<MetricLabel> labels) {
    super(labels);

    String[] labelNames = getLabelNames();
    this.count = Counter.build().name("span_count").help("The span count")
            .labelNames(labelNames).register(registry);
    this.duration = Histogram.build().name("span_duration").help("The span duration")
            .labelNames(labelNames).register(registry);
}
 
开发者ID:objectiser,项目名称:java-metrics-prototype,代码行数:10,代码来源:PrometheusMetricsReporter.java

示例12: sampleOccurred

import io.prometheus.client.Counter; //导入依赖的package包/类
public void sampleOccurred(SampleEvent event) {

		try {

			// build the label values from the event and observe the sampler
			// metrics
			String[] samplerLabelValues = this.labelValues(event);
			if (collectSamples)
				samplerCollector.labels(samplerLabelValues).observe(event.getResult().getTime());

			if (collectThreads)
				threadCollector.set(JMeterContextService.getContext().getThreadGroup().getNumberOfThreads());

			// if there are any assertions to
			if (collectAssertions) {
				if (event.getResult().getAssertionResults().length > 0) {
					for (AssertionResult assertionResult : event.getResult().getAssertionResults()) {
						String[] assertionsLabelValues = this.labelValues(event, assertionResult);
						
						if(assertionsCollector instanceof Summary)
							((Summary) assertionsCollector).labels(assertionsLabelValues).observe(event.getResult().getTime());
						else if (assertionsCollector instanceof Counter)
							((Counter) assertionsCollector).labels(assertionsLabelValues).inc();
					}
				}
			}

		} catch (Exception e) {
			log.error("Didn't update metric because of exception. Message was: {}", e.getMessage());
		}
	}
 
开发者ID:johrstrom,项目名称:jmeter-prometheus-plugin,代码行数:32,代码来源:PrometheusListener.java

示例13: PrometheusSaveConfig

import io.prometheus.client.Counter; //导入依赖的package包/类
public PrometheusSaveConfig(boolean save) {
	this.setSaveLabel(save);
	this.setSaveCode(save);
	this.setSaveThreads(save);
	this.setSaveSuccess(save);
	this.setSaveAssertions(save);
	this.setAssertionClass(Counter.class);
	this.setPort(9270);
}
 
开发者ID:johrstrom,项目名称:jmeter-prometheus-plugin,代码行数:10,代码来源:PrometheusSaveConfig.java

示例14: modifyTestElementForAssertionClass

import io.prometheus.client.Counter; //导入依赖的package包/类
private void modifyTestElementForAssertionClass(PrometheusSaveConfig config){
	int selectedIndex = this.assertionComboBox.getSelectedIndex();
	if(selectedIndex == 0)
		config.setAssertionClass(Counter.class);
	else if(selectedIndex == 1)
		config.setAssertionClass(Summary.class);
}
 
开发者ID:johrstrom,项目名称:jmeter-prometheus-plugin,代码行数:8,代码来源:PrometheusListenerGui.java

示例15: configureAssertionClass

import io.prometheus.client.Counter; //导入依赖的package包/类
private void configureAssertionClass(PrometheusSaveConfig config){
	Class<? extends Collector> assertionClass = config.getAssertionClass();
	String name = "";
	if(assertionClass.equals(Summary.class))
		name = Summary.class.getSimpleName();
	else if(assertionClass.equals(Counter.class))
		name = Counter.class.getSimpleName();
		
	this.assertionComboBox.setSelectedItem(name);
}
 
开发者ID:johrstrom,项目名称:jmeter-prometheus-plugin,代码行数:11,代码来源:PrometheusListenerGui.java


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