• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TextFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: setupWebserver

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
private HttpServer setupWebserver(Handler<AsyncResult<HttpServer>> listenHandler) {
    String port = componentConfig.get("port");
    Objects.requireNonNull(port, "Must specify port for scrape server to listen on");
    return vertx.createHttpServer().requestHandler(request -> {
        HttpServerResponse response = request.response();
        StringWriter sw = new StringWriter();
        try {
            TextFormat.write004(sw, collectorRegistry.metricFamilySamples());
            response.setStatusCode(200)
                .putHeader("Content-Type", TextFormat.CONTENT_TYPE_004)
                .setChunked(true)
                .write(sw.toString());
        } catch (Exception e) {
            response.setStatusCode(500)
                .write(Json.encode(e));
        }
        response.end();
    }).listen(Integer.parseInt(port), listenHandler);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:20,代码来源:PrometheusScrapeMetrics.java


示例17: getTextFormat

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
public String getTextFormat() {
    try {
        StringWriter result = new StringWriter();
        TextFormat.write004(result, registry.metricFamilySamples());
        return result.toString();
    } catch (IOException e) {
        throw new RuntimeException("Unexpected error when writing metrics to a String: " + e.getMessage(), e);
    }
}
 
开发者ID:fstab,项目名称:promagent,代码行数:11,代码来源:Exporter.java


示例18: respondMetrics

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
private static void respondMetrics(CollectorRegistry registry, HttpExchange httpExchange) throws IOException {
    StringWriter respBodyWriter = new StringWriter();
    respBodyWriter.write("# Metrics will become visible when they are updated for the first time.\n");
    TextFormat.write004(respBodyWriter, registry.metricFamilySamples());
    byte[] respBody = respBodyWriter.toString().getBytes("UTF-8");
    httpExchange.getResponseHeaders().put("Context-Type", Collections.singletonList("text/plain; charset=UTF-8"));
    httpExchange.sendResponseHeaders(200, respBody.length);
    httpExchange.getResponseBody().write(respBody);
    httpExchange.getResponseBody().close();
}
 
开发者ID:fstab,项目名称:promagent,代码行数:11,代码来源:BuiltInServer.java


示例19: invoke

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
@Override
public ResponseEntity<String> invoke() {
    try {
        Writer writer = new StringWriter();
        TextFormat.write004(writer, collectorRegistry.metricFamilySamples());
        return ResponseEntity.ok()
            .header(CONTENT_TYPE, TextFormat.CONTENT_TYPE_004)
            .body(writer.toString());
    } catch (IOException e) {
        // This actually never happens since StringWriter::write() doesn't throw any IOException
        throw new RuntimeException("Writing metrics failed", e);
    }
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:14,代码来源:PrometheusScrapeEndpoint.java


示例20: scrape

import io.prometheus.client.exporter.common.TextFormat; //导入依赖的package包/类
/**
 * Content that should be included in the response body for an endpoint designate for
 * Prometheus to scrape from.
 */
public String scrape() {
    Writer writer = new StringWriter();
    try {
        TextFormat.write004(writer, registry.metricFamilySamples());
    } catch (IOException e) {
        // This actually never happens since StringWriter::write() doesn't throw any IOException
        throw new RuntimeException(e);
    }
    return writer.toString();
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:15,代码来源:PrometheusMeterRegistry.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SaslInputStream类代码示例发布时间:2022-05-21
下一篇:
Java Call类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap