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


Java TextFormat类代码示例

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


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

示例1: getServlet

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
public HttpHandler getServlet() {
    return exchange -> {
        final ByteArrayOutputStream response = new ByteArrayOutputStream(1 << 20);
        final OutputStreamWriter osw = new OutputStreamWriter(response);
        TextFormat.write004(osw, registry.metricFamilySamples());
        osw.flush();
        osw.close();
        response.flush();
        response.close();

        exchange.getResponseHeaders().set("Content-Type", TextFormat.CONTENT_TYPE_004);
        exchange.getResponseHeaders().set("Content-Length", String.valueOf(response.size()));
        exchange.sendResponseHeaders(200, response.size());
        response.writeTo(exchange.getResponseBody());
        exchange.close();
    };
}
 
开发者ID:secondbase,项目名称:secondbase,代码行数:19,代码来源:PrometheusWebConsole.java

示例2: doGet

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
protected void doGet(
        HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) throws IOException {
    String paramToken = httpServletRequest.getParameter("token");
    String storedToken = secureTokenManager.getToken();

    if (StringUtils.isNotBlank(storedToken) && !storedToken.equals(paramToken)) {
        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    httpServletResponse.setContentType(TextFormat.CONTENT_TYPE_004);

    try (Writer writer = httpServletResponse.getWriter()) {
        TextFormat.write004(writer, metricCollector.getRegistry().filteredMetricFamilySamples(parse(httpServletRequest)));
        writer.flush();
    }
}
 
开发者ID:AndreyVMarkelov,项目名称:jira-prometheus-exporter,代码行数:21,代码来源:PrometheusExporter.java

示例3: doGet

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
protected void doGet(
        final HttpServletRequest httpServletRequest,
        final HttpServletResponse httpServletResponse) throws ServletException, IOException {
    String paramToken = httpServletRequest.getParameter("token");
    String storedToken = secureTokenManager.getToken();

    if (StringUtils.isNotBlank(storedToken) && !storedToken.equals(paramToken)) {
        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    httpServletResponse.setContentType(TextFormat.CONTENT_TYPE_004);

    try (Writer writer = httpServletResponse.getWriter()) {
        TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(httpServletRequest)));
        writer.flush();
    }
}
 
开发者ID:AndreyVMarkelov,项目名称:prom-bitbucket-exporter,代码行数:21,代码来源:PrometheusExporter.java

示例4: doGet

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
protected void doGet(
        final HttpServletRequest httpServletRequest,
        final HttpServletResponse httpServletResponse) throws ServletException, IOException {
    String paramToken = httpServletRequest.getParameter("token");
    String storedToken = secureTokenManager.getToken();

    if (StringUtils.isNotBlank(storedToken) && !storedToken.equals(paramToken)) {
        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    httpServletResponse.setContentType(TextFormat.CONTENT_TYPE_004);

    try (Writer writer = httpServletResponse.getWriter()) {
        TextFormat.write004(writer, metricCollector.getRegistry().filteredMetricFamilySamples(parse(httpServletRequest)));
        writer.flush();
    }
}
 
开发者ID:AndreyVMarkelov,项目名称:prom-confluence-exporter,代码行数:21,代码来源:PrometheusExporter.java

示例5: handle

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
public void handle(@NotNull RoutingContext context) {
  context.vertx().<Buffer>executeBlocking(future -> {
    try (final BufferWriter writer = new BufferWriter()) {
      TextFormat.write004(writer, registry.metricFamilySamples());
      future.complete(writer.buffer);
    } catch (IOException e) {
      future.fail(e);
    }
  }, false, result -> {
    if (result.succeeded()) {
      context.response()
          .setStatusCode(HttpResponseStatus.OK.code())
          .putHeader("Content-Type", TextFormat.CONTENT_TYPE_004)
          .end(result.result());
    } else {
      context.fail(result.cause());
    }
  });
}
 
开发者ID:nolequen,项目名称:vertx-prometheus-metrics,代码行数:21,代码来源:MetricsTextHandler.java

示例6: doGet

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

    List<ProbeResult> probeResults = metricsCache.get();

    formatProbeResults(probeResults)
            .forEach(formattedProbeResult -> {
                try {
                    resp.getWriter().println(formattedProbeResult);
                } catch (IOException e) {
                    logger.error("IO error occurred writing to /metrics page.", e);
                }
            });

    try (Writer writer = resp.getWriter()) {
        TextFormat.write004(writer, registry.filteredMetricFamilySamples(parse(req)));
        writer.flush();
    }
}
 
开发者ID:tjheslin1,项目名称:Patterdale,代码行数:22,代码来源:MetricsServlet.java

示例7: parseMetrics

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

示例8: doGet

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

示例9: getMetrics

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@GET
@Path("/metrics")
private String getMetrics(Request request, Response response) throws IOException {
    response.header(CACHE_CONTROL, "must-revalidate,no-cache,no-store");
    response.status(HttpServletResponse.SC_OK);
    Optional<String> format = Optional.ofNullable(request.queryParams(FORMAT));
    String dFormat = format.orElse(JSON);
    switch (dFormat) {
        case PROMETHEUS:
            // Prometheus format for the metrics
            response.type(PROMETHEUS_CONTENT_TYPE);
            final Writer writer1 = new StringWriter();
            TextFormat.write004(writer1, this.prometheusRegistry.metricFamilySamples());
            return writer1.toString();
        case JSON:
            // Json/Dropwizard format
            response.type(APPLICATION_JSON);
            final ObjectWriter writer = mapper.writer();
            try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
                writer.writeValue(output, this.metricRegistry);
                return new String(output.toByteArray(), "UTF-8");
            }
        default:
            throw GraknServerException.requestInvalidParameter(FORMAT, dFormat);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:27,代码来源:SystemController.java

示例10: invoke

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
@GetMapping(produces = TextFormat.CONTENT_TYPE_004)
@HypermediaDisabled
@ResponseBody
public ResponseEntity<String> invoke() {
	PrometheusMetrics prometheusMetrics = (PrometheusMetrics) super.invoke();

	Writer writer = new StringWriter();
	try {
		TextFormat.write004(writer, Collections.enumeration(prometheusMetrics.getMetricFamilySamples()));
	} catch (IOException e) {
		log.error("metric write error", e);
	}

	HttpStatus status = prometheusMetrics.isUp() ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR;

	String body = writer.toString();
	ResponseEntity<String> response = new ResponseEntity<>(body, status);
	return response;
}
 
开发者ID:akaGelo,项目名称:spring-boot-starter-prometheus,代码行数:21,代码来源:PrometheusMvcEndpoint.java

示例11: shouldWriteNiceMetricsOutput

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Test
public void shouldWriteNiceMetricsOutput() throws IOException {
    // given
    HystrixPrometheusMetricsPublisher.builder().shouldExportDeprecatedMetrics(false).buildAndRegister();
    TestHystrixCommand command = new TestHystrixCommand("any");

    // when
    command.execute();

    // then
    Writer writer = new FileWriter("target/sample.txt");
    try {
        TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples());
        writer.flush();
    } finally {
        writer.close();
    }
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:19,代码来源:MetricsListTest.java

示例12: shouldHaveExponentialBuckets

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Test
public void shouldHaveExponentialBuckets() throws IOException {
    // given
    HystrixPrometheusMetricsPublisher.builder().withExponentialBuckets().buildAndRegister();
    TestHystrixCommand command = new TestHystrixCommand("any");

    // when
    command.execute();

    // then
    StringWriter writer = new StringWriter();
    try {
        TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples());
        writer.flush();
    } finally {
        writer.close();
    }
    String result = writer.toString();
    Assertions.assertThat(result).contains("le=\"0.001\"");
    Assertions.assertThat(result).contains("le=\"2.5169093494697568\"");
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:22,代码来源:MetricsListTest.java

示例13: shouldHaveLinearBuckets

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Test
public void shouldHaveLinearBuckets() throws IOException {
    // given
    HystrixPrometheusMetricsPublisher.builder().withLinearBuckets(0.1, 0.2, 3).buildAndRegister();
    TestHystrixCommand command = new TestHystrixCommand("any");

    // when
    command.execute();

    // then
    StringWriter writer = new StringWriter();
    try {
        TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples());
        writer.flush();
    } finally {
        writer.close();
    }
    String result = writer.toString();
    Assertions.assertThat(result).contains("le=\"0.1\"");
    Assertions.assertThat(result).contains("le=\"0.5\"");
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:22,代码来源:MetricsListTest.java

示例14: shouldHaveDistinctBuckets

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Test
public void shouldHaveDistinctBuckets() throws IOException {
    // given
    HystrixPrometheusMetricsPublisher.builder().withBuckets(0.1, 1.0).buildAndRegister();
    TestHystrixCommand command = new TestHystrixCommand("any");

    // when
    command.execute();

    // then
    StringWriter writer = new StringWriter();
    try {
        TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples());
        writer.flush();
    } finally {
        writer.close();
    }
    String result = writer.toString();
    Assertions.assertThat(result).contains("le=\"0.1\"");
    Assertions.assertThat(result).contains("le=\"1.0\"");
}
 
开发者ID:ahus1,项目名称:prometheus-hystrix,代码行数:22,代码来源:MetricsListTest.java

示例15: value

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@RequestMapping(
        method = {RequestMethod.GET},
        produces = { "*/*" }
)
@ResponseBody
public ResponseEntity value(
        @RequestParam(value = "name[]", required = false, defaultValue = "") Set<String> name) {
  if (!getDelegate().isEnabled()) {
    // Shouldn't happen - MVC endpoint shouldn't be registered when delegate's
    // disabled
    return getDisabledResponse();
  }

  String result = delgate.writeRegistry(name);
  return ResponseEntity.ok()
          .header(CONTENT_TYPE, TextFormat.CONTENT_TYPE_004)
          .body(result);
}
 
开发者ID:prometheus,项目名称:client_java,代码行数:19,代码来源:PrometheusMvcEndpoint.java


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