• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MetricFamilySamples类的典型用法和代码示例

java 4次浏览

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

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

示例1: generateSystemMetrics

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
private static void generateSystemMetrics(SimpleTextOutputStream stream, String cluster) {
    Enumeration<MetricFamilySamples> metricFamilySamples = CollectorRegistry.defaultRegistry.metricFamilySamples();
    while (metricFamilySamples.hasMoreElements()) {
        MetricFamilySamples metricFamily = metricFamilySamples.nextElement();

        for (int i = 0; i < metricFamily.samples.size(); i++) {
            Sample sample = metricFamily.samples.get(i);
            stream.write(sample.name);
            stream.write("{cluster=\"").write(cluster).write("\",");
            for (int j = 0; j < sample.labelNames.size(); j++) {
                stream.write(sample.labelNames.get(j));
                stream.write("=\"");
                stream.write(sample.labelValues.get(j));
                stream.write("\",");
            }

            stream.write("} ");
            stream.write(Collector.doubleToGoString(sample.value));
            stream.write('\n');
        }
    }
}
 

开发者ID:apache,
项目名称:incubator-pulsar,
代码行数:23,
代码来源:PrometheusMetricsGenerator.java

示例2: testMetricsReporter

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testMetricsReporter() {
    MetricFamilySamples samples = testCollectorRegistry.metricFamilySamples().nextElement();
    assertTrue(samples.samples.isEmpty());

    SpanData metricSpanData=Mockito.mock(SpanData.class);
    Mockito.when(metricSpanData.getOperationName()).thenReturn("testOp");
    Map<String,Object> testTags = new HashMap<String,Object>();
    testTags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
    Mockito.when(metricSpanData.getTags()).thenReturn(testTags);
    Mockito.when(metricSpanData.getDuration()).thenReturn(500L);
    metricsReporter.reportSpan(metricSpanData);

    samples = testCollectorRegistry.metricFamilySamples().nextElement();
    assertFalse(samples.samples.isEmpty());
}
 

开发者ID:opentracing-contrib,
项目名称:java-metrics,
代码行数:17,
代码来源:PrometheusMetricsReporterConfigurationTest.java

示例3: testWithCustomMetricTypeNames

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testWithCustomMetricTypeNames() {
    PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
            .withName("MyName")
            .withCollectorRegistry(collectorRegistry)
            .withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
            .build();

    SpanData spanData = mock(SpanData.class);
    when(spanData.getOperationName()).thenReturn("testop");
    when(spanData.getTags()).thenReturn(Collections.<String,Object>emptyMap());
    when(spanData.getDuration()).thenReturn(100000L);

    reporter.reportSpan(spanData);

    // Check span duration
    List<MetricFamilySamples> samples = reporter.getHistogram().collect();
    assertEquals(1, samples.size());
    assertEquals("MyName", samples.get(0).name);
}
 

开发者ID:opentracing-contrib,
项目名称:java-metrics,
代码行数:21,
代码来源:PrometheusMetricsReporterTest.java

示例4: testWithCustomLabel

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testWithCustomLabel() {
    MetricLabel metricLabel = new BaggageMetricLabel(METRIC_LABEL_NAME, METRIC_LABEL_VALUE);
    PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
            .withName("MyName")
            .withCollectorRegistry(collectorRegistry)
            .withCustomLabel(metricLabel)
            .withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
            .build();

    SpanData spanData = mock(SpanData.class);
    when(spanData.getOperationName()).thenReturn("testop");
    when(spanData.getTags()).thenReturn(Collections.<String,Object>emptyMap());
    when(spanData.getDuration()).thenReturn(100000L);

    reporter.reportSpan(spanData);

    List<MetricFamilySamples> samples = reporter.getHistogram().collect();
    assertEquals(1, samples.size());

    for (Sample sample : samples.get(0).samples) {
        assertTrue("Expected MetricLabel with name " + METRIC_LABEL_NAME, sample.labelNames.contains(METRIC_LABEL_NAME));
        assertTrue("Expected MetricLabel with value " + METRIC_LABEL_VALUE , sample.labelValues.contains(METRIC_LABEL_VALUE));
    }
}
 

开发者ID:opentracing-contrib,
项目名称:java-metrics,
代码行数:26,
代码来源:PrometheusMetricsReporterTest.java

示例5: doGet

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的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

示例6: clientStreamRpcMetrics

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void clientStreamRpcMetrics() throws Throwable {
  startGrpcServer(CHEAP_METRICS);
  StreamRecorder<HelloResponse> streamRecorder = StreamRecorder.create();
  StreamObserver<HelloRequest> requestStream =
      createGrpcStub().sayHelloClientStream(streamRecorder);
  requestStream.onNext(REQUEST);
  requestStream.onNext(REQUEST);
  requestStream.onNext(REQUEST);

  // Not a blocking stub, so we need to wait.
  streamRecorder.awaitCompletion();

  assertThat(findRecordedMetricOrThrow("grpc_server_started_total").samples).hasSize(1);
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_received_total").samples).hasSize(1);
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_sent_total").samples).isEmpty();

  MetricFamilySamples handled = findRecordedMetricOrThrow("grpc_server_handled_total");
  assertThat(handled.samples).hasSize(1);
  assertThat(handled.samples.get(0).labelValues).containsExactly(
      "CLIENT_STREAMING",
      HelloServiceImpl.SERVICE_NAME,
      HelloServiceImpl.CLIENT_STREAM_METHOD_NAME,
      "OK");
  assertThat(handled.samples.get(0).value).isWithin(0).of(1);
}
 

开发者ID:grpc-ecosystem,
项目名称:java-grpc-prometheus,
代码行数:27,
代码来源:MonitoringServerInterceptorIntegrationTest.java

示例7: serverStreamRpcMetrics

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void serverStreamRpcMetrics() throws Throwable {
  startGrpcServer(CHEAP_METRICS);
  ImmutableList<HelloResponse> responses =
      ImmutableList.copyOf(createGrpcBlockingStub().sayHelloServerStream(REQUEST));

  assertThat(findRecordedMetricOrThrow("grpc_server_started_total").samples).hasSize(1);
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_received_total").samples).isEmpty();
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_sent_total").samples).hasSize(1);

  MetricFamilySamples handled = findRecordedMetricOrThrow("grpc_server_handled_total");
  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);

  MetricFamilySamples messagesSent = findRecordedMetricOrThrow("grpc_server_msg_sent_total");
  assertThat(messagesSent.samples.get(0).labelValues).containsExactly(
      "SERVER_STREAMING",
      HelloServiceImpl.SERVICE_NAME,
      HelloServiceImpl.SERVER_STREAM_METHOD_NAME);
  assertThat(messagesSent.samples.get(0).value).isWithin(0).of(responses.size());
}
 

开发者ID:grpc-ecosystem,
项目名称:java-grpc-prometheus,
代码行数:27,
代码来源:MonitoringServerInterceptorIntegrationTest.java

示例8: bidiStreamRpcMetrics

点赞 3

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void bidiStreamRpcMetrics() throws Throwable {
  startGrpcServer(CHEAP_METRICS);
  StreamRecorder<HelloResponse> streamRecorder = StreamRecorder.create();
  StreamObserver<HelloRequest> requestStream =
      createGrpcStub().sayHelloBidiStream(streamRecorder);
  requestStream.onNext(REQUEST);
  requestStream.onNext(REQUEST);
  requestStream.onCompleted();

  // Not a blocking stub, so we need to wait.
  streamRecorder.awaitCompletion();

  assertThat(findRecordedMetricOrThrow("grpc_server_started_total").samples).hasSize(1);
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_received_total").samples).hasSize(1);
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_sent_total").samples).hasSize(1);

  MetricFamilySamples handled = findRecordedMetricOrThrow("grpc_server_handled_total");
  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,
代码行数:27,
代码来源:MonitoringServerInterceptorIntegrationTest.java

示例9: testMetricsReporterName

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testMetricsReporterName() {
    assertNotNull(metricsReporter);

    MetricFamilySamples samples = testCollectorRegistry.metricFamilySamples().nextElement();
    assertEquals(METRICS_NAME, samples.name);
}
 

开发者ID:opentracing-contrib,
项目名称:java-metrics,
代码行数:8,
代码来源:PrometheusMetricsReporterConfigurationWithNameTest.java

示例10: testWithTagAndBaggageLabels

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testWithTagAndBaggageLabels() {
    PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
            .withName("MyName")
            .withBaggageLabel(BAGGAGE_LABEL_NAME, BAGGAGE_LABEL_VALUE)
            .withTagLabel(TAG_LABEL_NAME, TAG_LABEL_VALUE)
            .withCollectorRegistry(collectorRegistry)
            .withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
            .build();

    SpanData spanData = mock(SpanData.class);
    when(spanData.getOperationName()).thenReturn("testop");
    when(spanData.getTags()).thenReturn(Collections.<String,Object>emptyMap());
    when(spanData.getDuration()).thenReturn(100000L);

    reporter.reportSpan(spanData);

    List<MetricFamilySamples> samples = reporter.getHistogram().collect();
    assertEquals(1, samples.size());

    for (Sample sample : samples.get(0).samples) {
        assertTrue("Expected BaggageLabel with name " + BAGGAGE_LABEL_NAME, sample.labelNames.contains(BAGGAGE_LABEL_NAME));
        assertTrue("Expected BaggageLabel with value " + BAGGAGE_LABEL_VALUE, sample.labelValues.contains(BAGGAGE_LABEL_VALUE));
        assertTrue("Expected TagLabel with name " + TAG_LABEL_NAME, sample.labelNames.contains(TAG_LABEL_NAME));
        assertTrue("Expected TagLabel with value " + TAG_LABEL_VALUE, sample.labelValues.contains(TAG_LABEL_VALUE));
    }
}
 

开发者ID:opentracing-contrib,
项目名称:java-metrics,
代码行数:28,
代码来源:PrometheusMetricsReporterTest.java

示例11: testReportSpanWithDefaultValuesForMissingTags

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testReportSpanWithDefaultValuesForMissingTags() {
    PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
            .withCollectorRegistry(collectorRegistry)
            .withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
            .build();

    Span span = Mockito.mock(Span.class);

    Map<String,Object> spanTags = new HashMap<String,Object>();
    spanTags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);

    reporter.reportSpan(span, "testop", spanTags, 100000L);

    // Check span count
    List<MetricFamilySamples> samples = reporter.getSpanCount().collect();
    assertEquals(1, samples.size());
    assertEquals(1, samples.get(0).samples.size());

    Sample sample=samples.get(0).samples.get(0);
    assertEquals(1, (int)sample.value); // Span count
    assertEquals(Arrays.asList(reporter.getLabelNames()), sample.labelNames);
    assertEquals("testop", sample.labelValues.get(0));

    // Check span duration
    samples = reporter.getSpanDuration().collect();
    assertEquals(1, samples.size());
    assertEquals(17, samples.get(0).samples.size());

    for (int i=0; i < samples.get(0).samples.size(); i++) {
        sample = samples.get(0).samples.get(i);
        // Verify operation name
        assertEquals("testop", sample.labelValues.get(0));
    }
}
 

开发者ID:objectiser,
项目名称:java-metrics-prototype,
代码行数:36,
代码来源:PrometheusMetricsReporterTest.java

示例12: unaryRpcMetrics

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void unaryRpcMetrics() throws Throwable {
  startGrpcServer(CHEAP_METRICS);
  createGrpcBlockingStub().sayHello(REQUEST);

  assertThat(findRecordedMetricOrThrow("grpc_server_started_total").samples).hasSize(1);
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_received_total").samples).isEmpty();
  assertThat(findRecordedMetricOrThrow("grpc_server_msg_sent_total").samples).isEmpty();

  MetricFamilySamples handled = findRecordedMetricOrThrow("grpc_server_handled_total");
  assertThat(handled.samples).hasSize(1);
  assertThat(handled.samples.get(0).labelValues).containsExactly(
      "UNARY", HelloServiceImpl.SERVICE_NAME, HelloServiceImpl.UNARY_METHOD_NAME, "OK");
  assertThat(handled.samples.get(0).value).isWithin(0).of(1);
}
 

开发者ID:grpc-ecosystem,
项目名称:java-grpc-prometheus,
代码行数:16,
代码来源:MonitoringServerInterceptorIntegrationTest.java

示例13: addsHistogramIfEnabled

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void addsHistogramIfEnabled() throws Throwable {
  startGrpcServer(ALL_METRICS);
  createGrpcBlockingStub().sayHello(REQUEST);

  MetricFamilySamples latency = findRecordedMetricOrThrow("grpc_server_handled_latency_seconds");
  assertThat(latency.samples.size()).isGreaterThan(0);
}
 

开发者ID:grpc-ecosystem,
项目名称:java-grpc-prometheus,
代码行数:9,
代码来源:MonitoringServerInterceptorIntegrationTest.java

示例14: addSingleMetric

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
private void addSingleMetric(Metric<?> metric, Set<MetricFamilySamples> mfs) {
	String springName = metric.getName();
	String prometheusName = prometeusMetricNameConverter.convertName(springName);
	double value = metric.getValue().doubleValue();

	// Spring counter is not prometheus counter because spring
	// counter implements the decrement method

	NameEqualsMetricFamilySamples metricFamilySamples = new NameEqualsMetricFamilySamples(prometheusName,
			Type.GAUGE, prometheusName, Collections
					.singletonList(new MetricFamilySamples.Sample(prometheusName, EMPTY_LIST, EMPTY_LIST, value)));
	mfs.add(metricFamilySamples);
}
 

开发者ID:akaGelo,
项目名称:spring-boot-starter-prometheus,
代码行数:14,
代码来源:PrometheusEndpoint.java

示例15: equals

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
	if (obj instanceof MetricFamilySamples) {
		String otherName = ((MetricFamilySamples) obj).name;
		return this.name.equals(otherName);
	}
	return super.equals(obj);
}
 

开发者ID:akaGelo,
项目名称:spring-boot-starter-prometheus,
代码行数:9,
代码来源:PrometheusEndpoint.java

示例16: testReportSpan

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
@Test
public void testReportSpan() {
    PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
            .withCollectorRegistry(collectorRegistry)
            .withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
            .build();

    Map<String,Object> spanTags = new HashMap<String,Object>();
    spanTags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);

    SpanData spanData = mock(SpanData.class);
    when(spanData.getOperationName()).thenReturn("testop");
    when(spanData.getTags()).thenReturn(spanTags);
    when(spanData.getDuration()).thenReturn(100000L);

    reporter.reportSpan(spanData);

    // Check histogram
    List<MetricFamilySamples> samples = reporter.getHistogram().collect();
    assertEquals(1, samples.size());
    assertEquals(17, samples.get(0).samples.size());
    
    for (int i=0; i < samples.get(0).samples.size(); i++) {
        Sample sample = samples.get(0).samples.get(i);
        // Verify operation name
        assertEquals("testop", sample.labelValues.get(0));
        List<String> labelNames = new ArrayList<String>(sample.labelNames);
        if (labelNames.get(labelNames.size()-1).equals("le")) {
            // Remove additional label added by previous for all but last sample
            labelNames.remove(labelNames.size()-1);

            // Check if value is "+Inf" - if so, then check count
            // See https://prometheus.io/docs/concepts/metric_types/ (Histogram explanation
            // of count)
            if (sample.labelValues.get(sample.labelNames.size()-1).equals("+Inf")) {
                assertEquals(1, (int)sample.value);                    
            }
        }
        assertEquals(Arrays.asList(reporter.getLabelNames()), labelNames);
    }
}
 

开发者ID:opentracing-contrib,
项目名称:java-metrics,
代码行数:42,
代码来源:PrometheusMetricsReporterTest.java

示例17: findRecordedMetricOrThrow

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
private MetricFamilySamples findRecordedMetricOrThrow(String name) {
  return RegistryHelper.findRecordedMetricOrThrow(name, collectorRegistry);
}
 

开发者ID:grpc-ecosystem,
项目名称:java-grpc-prometheus,
代码行数:4,
代码来源:MonitoringServerInterceptorIntegrationTest.java

示例18: PrometheusMetrics

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
public PrometheusMetrics(int status, Set<MetricFamilySamples> metricFamilySamples) {
	this.status = status;
	this.metricFamilySamples = metricFamilySamples;
}
 

开发者ID:akaGelo,
项目名称:spring-boot-starter-prometheus,
代码行数:5,
代码来源:PrometheusMetrics.java

示例19: getMetricFamilySamples

点赞 2

import io.prometheus.client.Collector.MetricFamilySamples; //导入依赖的package包/类
public Set<MetricFamilySamples> getMetricFamilySamples() {
	return metricFamilySamples;
}
 

开发者ID:akaGelo,
项目名称:spring-boot-starter-prometheus,
代码行数:4,
代码来源:PrometheusMetrics.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)