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


Java Collector.MetricFamilySamples方法代码示例

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


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

示例1: doGet

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
		throws ServletException, IOException {
	resp.setStatus(HttpServletResponse.SC_OK);
	resp.setContentType(TextFormat.CONTENT_TYPE_004);

	Writer writer = resp.getWriter();
	Enumeration<Collector.MetricFamilySamples> metricsWithDuplicates = registry.metricFamilySamples();
	List<String> names = new ArrayList<String>();
	List<Collector.MetricFamilySamples> metricsWithoutDuplicates = new ArrayList<Collector.MetricFamilySamples>();
	while (metricsWithDuplicates.hasMoreElements()) {
		MetricFamilySamples metric = metricsWithDuplicates.nextElement();
		if (!names.contains(metric.name)) {
			metricsWithoutDuplicates.add(metric);
			names.add(metric.name);
		}
	}

	TextFormat.write004(writer, Collections.enumeration(metricsWithoutDuplicates));
	writer.flush();
	writer.close();
}
 
开发者ID:ewolff,项目名称:microservice-consul,代码行数:23,代码来源:MetricsServletFix.java

示例2: countSamples

import io.prometheus.client.Collector; //导入方法依赖的package包/类
public static int countSamples(
    String metricName, String sampleName, CollectorRegistry collectorRegistry) {
  Enumeration<Collector.MetricFamilySamples> samples = collectorRegistry.metricFamilySamples();
  while (samples.hasMoreElements()) {
    Collector.MetricFamilySamples sample = samples.nextElement();
    if (sample.name.equals(metricName)) {
      int result = 0;
      for (Collector.MetricFamilySamples.Sample s : sample.samples) {
        if (s.name.equals(sampleName)) {
          ++result;
        }
      }
      return result;
    }
  }
  throw new IllegalArgumentException("Could not find sample family with name: " + metricName);
}
 
开发者ID:grpc-ecosystem,项目名称:java-grpc-prometheus,代码行数:18,代码来源:RegistryHelper.java

示例3: serverStreamRpcMetrics

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void serverStreamRpcMetrics() throws Throwable {
  createClientStub(CHEAP_METRICS).sayHelloServerStream(REQUEST, responseRecorder);
  responseRecorder.awaitCompletion();

  assertThat(extractMetricValue("grpc_client_started_total")).isWithin(0).of(1);
  assertThat(extractMetricValue("grpc_client_msg_received_total")).isWithin(0).of(1);
  assertThat(findRecordedMetricOrThrow("grpc_client_msg_sent_total").samples).isEmpty();

  Collector.MetricFamilySamples handled = findRecordedMetricOrThrow("grpc_client_completed");
  assertThat(handled.samples).hasSize(1);
  assertThat(handled.samples.get(0).labelValues).containsExactly(
      "SERVER_STREAMING",
      HelloServiceImpl.SERVICE_NAME,
      HelloServiceImpl.SERVER_STREAM_METHOD_NAME,
      "OK");
  assertThat(handled.samples.get(0).value).isWithin(0).of(1);
}
 
开发者ID:grpc-ecosystem,项目名称:java-grpc-prometheus,代码行数:19,代码来源:MonitoringClientInterceptorIntegrationTest.java

示例4: bidiStreamRpcMetrics

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void bidiStreamRpcMetrics() throws Throwable {
  StreamObserver<HelloProto.HelloRequest> requestStream =
      createClientStub(CHEAP_METRICS).sayHelloBidiStream(responseRecorder);
  requestStream.onNext(REQUEST);
  requestStream.onNext(REQUEST);
  requestStream.onCompleted();

  responseRecorder.awaitCompletion();

  assertThat(extractMetricValue("grpc_client_started_total")).isWithin(0).of(1);
  assertThat(extractMetricValue("grpc_client_msg_received_total")).isWithin(0).of(2);
  assertThat(extractMetricValue("grpc_client_msg_sent_total")).isWithin(0).of(2);

  Collector.MetricFamilySamples handled = findRecordedMetricOrThrow("grpc_client_completed");
  assertThat(handled.samples).hasSize(1);
  assertThat(handled.samples.get(0).labelValues).containsExactly(
      "BIDI_STREAMING",
      HelloServiceImpl.SERVICE_NAME,
      HelloServiceImpl.BIDI_STREAM_METHOD_NAME,
      "OK");
  assertThat(handled.samples.get(0).value).isWithin(0).of(1);
}
 
开发者ID:grpc-ecosystem,项目名称:java-grpc-prometheus,代码行数:24,代码来源:MonitoringClientInterceptorIntegrationTest.java

示例5: push

import io.prometheus.client.Collector; //导入方法依赖的package包/类
/**
 * Push samples from the given registry to Graphite.
 */
public void push(CollectorRegistry registry) throws IOException {
  Socket s = new Socket(host, port);
  BufferedWriter writer = new BufferedWriter(new PrintWriter(s.getOutputStream()));
  Matcher m = INVALID_GRAPHITE_CHARS.matcher("");
  long now = System.currentTimeMillis() / 1000;
  for (Collector.MetricFamilySamples metricFamilySamples: Collections.list(registry.metricFamilySamples())) {
    for (Collector.MetricFamilySamples.Sample sample: metricFamilySamples.samples) {
      m.reset(sample.name);
      writer.write(m.replaceAll("_"));
      for (int i = 0; i < sample.labelNames.size(); ++i) {
        m.reset(sample.labelValues.get(i));
        writer.write("." + sample.labelNames.get(i) + "." + m.replaceAll("_"));
      }
      writer.write(" " + sample.value + " " + now + "\n");
    }
  }
  writer.close();
  s.close();
}
 
开发者ID:prometheus,项目名称:client_java,代码行数:23,代码来源:Graphite.java

示例6: getValues

import io.prometheus.client.Collector; //导入方法依赖的package包/类
/**
 * @see MetricMBean#getValues()
 */
@Override
public Map<Map<String, String>, Double> getValues() {
    Map<Map<String, String>, Double> result = new HashMap<>();
    for (Collector.MetricFamilySamples samples : metric.collect()) {
        for (Collector.MetricFamilySamples.Sample sample : samples.samples) {
            Map<String, String> labels = new HashMap<>();
            for (int i = 0; i < sample.labelNames.size(); i++) {
                labels.put(sample.labelNames.get(i), sample.labelValues.get(i));
            }
            result.put(labels, sample.value);
        }
    }
    return result;
}
 
开发者ID:fstab,项目名称:promagent,代码行数:18,代码来源:Metric.java

示例7: withNameAndTagKey

import io.prometheus.client.Collector; //导入方法依赖的package包/类
private Condition<Enumeration<Collector.MetricFamilySamples>> withNameAndTagKey(String name, String tagKey) {
    return new Condition<>(m -> {
        while (m.hasMoreElements()) {
            Collector.MetricFamilySamples samples = m.nextElement();
            if (samples.samples.stream().anyMatch(s -> s.name.equals(name) && s.labelNames.contains(tagKey))) {
                return true;
            }
        }
        return false;
    }, "a meter with name `%s` and tag `%s`", name, tagKey);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:12,代码来源:PrometheusMeterRegistryTest.java

示例8: shouldProvideF5ScraperDependencyUp

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void shouldProvideF5ScraperDependencyUp() throws Exception{
    Node node = new Node(NODE_NAME);
    F5ScraperServiceExports f5ScraperServiceExports = new F5ScraperServiceExports(node,registry,f5MetricsGateway);
    when(f5MetricsGateway.isHealthy()).thenReturn(true);

    final List<Collector.MetricFamilySamples> collect = f5ScraperServiceExports.collect();
    assertThat(collect.size()).isEqualTo(1);
    assertThat(collect.get(0).samples.get(0).name).isEqualTo("f5_scraper_service_health");
    assertThat(collect.get(0).samples.get(0).labelNames).isEqualTo(Collections.singletonList("node_name"));
    assertThat(collect.get(0).samples.get(0).labelValues).isEqualTo(Collections.singletonList(NODE_NAME));
    assertThat(collect.get(0).samples.get(0).value).isEqualTo(1.0);
    verify(f5MetricsGateway, times(1)).isHealthy();
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:15,代码来源:PrometheusMetricsTest.java

示例9: shouldProvideF5ScraperDependencyDown

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void shouldProvideF5ScraperDependencyDown() throws Exception{
    Node node = new Node(NODE_NAME);
    F5ScraperServiceExports f5ScraperServiceExports = new F5ScraperServiceExports(node,registry,f5MetricsGateway);
    when(f5MetricsGateway.isHealthy()).thenReturn(false);

    final List<Collector.MetricFamilySamples> collect = f5ScraperServiceExports.collect();
    assertThat(collect.size()).isEqualTo(1);
    assertThat(collect.get(0).samples.get(0).name).isEqualTo("f5_scraper_service_health");
    assertThat(collect.get(0).samples.get(0).labelNames).isEqualTo(Collections.singletonList("node_name"));
    assertThat(collect.get(0).samples.get(0).labelValues).isEqualTo(Collections.singletonList(NODE_NAME));
    assertThat(collect.get(0).samples.get(0).value).isEqualTo(0.0);
    verify(f5MetricsGateway, times(1)).isHealthy();
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:15,代码来源:PrometheusMetricsTest.java

示例10: shouldProvideMarathonScraperDependencyUp

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void shouldProvideMarathonScraperDependencyUp() throws Exception{
    Node node = new Node(NODE_NAME);
    MarathonServiceExports marathonServiceExports = new MarathonServiceExports(node,registry,marathonGateway);
    when(marathonGateway.isHealthy()).thenReturn(true);

    final List<Collector.MetricFamilySamples> collect = marathonServiceExports.collect();
    assertThat(collect.size()).isEqualTo(1);
    assertThat(collect.get(0).samples.get(0).name).isEqualTo("marathon_service_health");
    assertThat(collect.get(0).samples.get(0).labelNames).isEqualTo(Collections.singletonList("node_name"));
    assertThat(collect.get(0).samples.get(0).labelValues).isEqualTo(Collections.singletonList(NODE_NAME));
    assertThat(collect.get(0).samples.get(0).value).isEqualTo(1.0);
    verify(marathonGateway, times(1)).isHealthy();
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:15,代码来源:PrometheusMetricsTest.java

示例11: shouldProvideMarathonScraperDependencyDown

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void shouldProvideMarathonScraperDependencyDown() throws Exception{
    Node node = new Node(NODE_NAME);
    MarathonServiceExports marathonServiceExports = new MarathonServiceExports(node,registry,marathonGateway);
    when(marathonGateway.isHealthy()).thenReturn(false);

    final List<Collector.MetricFamilySamples> collect = marathonServiceExports.collect();
    assertThat(collect.size()).isEqualTo(1);
    assertThat(collect.get(0).samples.get(0).name).isEqualTo("marathon_service_health");
    assertThat(collect.get(0).samples.get(0).labelNames).isEqualTo(Collections.singletonList("node_name"));
    assertThat(collect.get(0).samples.get(0).labelValues).isEqualTo(Collections.singletonList(NODE_NAME));
    assertThat(collect.get(0).samples.get(0).value).isEqualTo(0.0);
    verify(marathonGateway, times(1)).isHealthy();
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:15,代码来源:PrometheusMetricsTest.java

示例12: shouldProvideAutoscaleDependencyUp

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void shouldProvideAutoscaleDependencyUp() throws Exception{
    Node node = new Node(NODE_NAME);
    AutoscaleServiceExports autoscaleServiceExports = new AutoscaleServiceExports(node,registry,autoscaleService);
    when(autoscaleService.isHealthy()).thenReturn(true);

    final List<Collector.MetricFamilySamples> collect = autoscaleServiceExports.collect();
    assertThat(collect.size()).isEqualTo(1);
    assertThat(collect.get(0).samples.get(0).name).isEqualTo("autoscale_service_health");
    assertThat(collect.get(0).samples.get(0).labelNames).isEqualTo(Collections.singletonList("node_name"));
    assertThat(collect.get(0).samples.get(0).labelValues).isEqualTo(Collections.singletonList(NODE_NAME));
    assertThat(collect.get(0).samples.get(0).value).isEqualTo(1.0);
    verify(autoscaleService, times(1)).isHealthy();
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:15,代码来源:PrometheusMetricsTest.java

示例13: shouldProvideAutoscaleDependencyDown

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void shouldProvideAutoscaleDependencyDown() throws Exception{
    Node node = new Node(NODE_NAME);
    AutoscaleServiceExports autoscaleServiceExports = new AutoscaleServiceExports(node,registry,autoscaleService);
    when(marathonGateway.isHealthy()).thenReturn(false);

    final List<Collector.MetricFamilySamples> collect = autoscaleServiceExports.collect();
    assertThat(collect.size()).isEqualTo(1);
    assertThat(collect.get(0).samples.get(0).name).isEqualTo("autoscale_service_health");
    assertThat(collect.get(0).samples.get(0).labelNames).isEqualTo(Collections.singletonList("node_name"));
    assertThat(collect.get(0).samples.get(0).labelValues).isEqualTo(Collections.singletonList(NODE_NAME));
    assertThat(collect.get(0).samples.get(0).value).isEqualTo(0.0);
    verify(autoscaleService, times(1)).isHealthy();
}
 
开发者ID:dcos-utilities,项目名称:f5-marathon-autoscale,代码行数:15,代码来源:PrometheusMetricsTest.java

示例14: collect

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Override
public List<Collector.MetricFamilySamples> collect() {
    List<Collector.MetricFamilySamples> result = new ArrayList<>();
    result.addAll(successAuthCounter.collect());
    result.addAll(failedAuthCounter.collect());
    result.addAll(pushCounter.collect());
    return result;
}
 
开发者ID:AndreyVMarkelov,项目名称:prom-bitbucket-exporter,代码行数:9,代码来源:MetricCollectorImpl.java

示例15: testHelpFromPattern

import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Test
public void testHelpFromPattern() throws Exception {
  JmxCollector jc = new JmxCollector(
          "\n---\nrules:\n- pattern: `^(hadoop)<service=DataNode, name=DataNodeActivity-ams-hdd001-50010><>replaceBlockOpMinTime:`\n  name: foo\n  help: bar $1".replace('`','"')).register(registry);
  for(Collector.MetricFamilySamples mfs : jc.collect()) {
    if (mfs.name.equals("foo") && mfs.help.equals("bar hadoop")) {
      return;
    }
  }
  fail("MetricFamilySamples foo with help 'bar hadoop' not found.");
}
 
开发者ID:flokkr,项目名称:jmxpromo,代码行数:12,代码来源:JmxCollectorTest.java


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