io.prometheus.client.Gauge.build()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(639)

本文整理了Java中io.prometheus.client.Gauge.build()方法的一些代码示例,展示了Gauge.build()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gauge.build()方法的具体详情如下:
包路径:io.prometheus.client.Gauge
类名称:Gauge
方法名:build

Gauge.build介绍

[英]Return a Builder to allow configuration of a new Gauge.
[中]返回生成器以允许配置新仪表。

代码示例

代码示例来源:origin: qunarcorp/qmq

@Override
  public Gauge create() {
    return Gauge.build().name(name).help(name).labelNames(tags).create().register();
  }
}

代码示例来源:origin: prometheus/client_java

@Setup
public void setup() {
 prometheusGauge = io.prometheus.client.metrics.Gauge.newBuilder()
  .name("name")
  .documentation("some description..")
  .build();
 prometheusGaugeChild = prometheusGauge.newPartial().apply();
 prometheusSimpleGauge = io.prometheus.client.Gauge.build()
  .name("name")
  .help("some description..")
  .labelNames("some", "group").create();
 prometheusSimpleGaugeChild = prometheusSimpleGauge.labels("test", "group");
 prometheusSimpleGaugeNoLabels = io.prometheus.client.Gauge.build()
  .name("name")
  .help("some description..")
  .create();
 registry = new MetricRegistry();
 codahaleCounter = registry.counter("name");
}

代码示例来源:origin: io.micrometer/micrometer-prometheus-starter

@SuppressWarnings("unchecked")
@Override
protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, T obj, ToDoubleFunction<T> f) {
  final WeakReference<T> ref = new WeakReference<>(obj);
  io.prometheus.client.Gauge gauge = collectorByName(Gauge.class, id.getConventionName(),
    i -> buildCollector(id, io.prometheus.client.Gauge.build()));
  String[] labelValues = id.getConventionTags().stream()
    .map(Tag::getValue)
    .collect(Collectors.toList())
    .toArray(new String[]{});
  Gauge.Child child = new Gauge.Child() {
    @Override
    public double get() {
      final T obj2 = ref.get();
      return (obj2 == null) ? Double.NaN : f.applyAsDouble(obj2);
    }
  };
  gauge.setChild(child, labelValues);
  return new PrometheusGauge(id, child);
}

代码示例来源:origin: smartcat-labs/cassandra-diagnostics

/**
 * Get the Gauge object for the given measurementName from the metricNameGuageMap. If the object does not exist:
 * create and register the metric and put it into the metricNameGuageMap.
 *
 * @param measurement
 * @param measurementName parameter is added (instead of being fetched from Measurement object) because name of the
 *            complex measurement is calculated for each field
 * @return Gauge object for the given measurementName
 */
private Gauge getOrCreateGaugeMeasurement(final Measurement measurement, String measurementName) {
  Gauge gauge = metricNameGuageMap.get(measurementName);
  if (gauge == null) {
    String[] tagKeys = measurement.tags().keySet().toArray(new String[0]);
    gauge = Gauge.build().labelNames(tagKeys).name(measurementName).help(measurement.name()).register();
    metricNameGuageMap.put(measurementName, gauge);
  }
  return gauge;
}

代码示例来源:origin: no.skatteetaten.aurora/aurora-prometheus

public Size() {
  sizes = Gauge.build()
    .name("sizes")
    .help("Sizes of things")
    .labelNames("name", "type")
    .create();
}

代码示例来源:origin: com.jonnymatts.prometheus/metrics-core

public PrometheusGauge(String name, String description, String... labels) {
  this.gauge = Gauge.build()
      .name(name)
      .help(description)
      .labelNames(labels)
      .create();
}

代码示例来源:origin: org.springframework.metrics/spring-metrics

@SuppressWarnings("unchecked")
@Override
public <T> T gauge(String name, Iterable<Tag> tags, T obj, ToDoubleFunction<T> f) {
  final WeakReference<T> ref = new WeakReference<>(obj);
  MeterId id = new MeterId(name, tags);
  io.prometheus.client.Gauge gauge = collectorByName(Gauge.class, name,
      i -> buildCollector(id, io.prometheus.client.Gauge.build()));
  computeIfAbsent(meterMap, id, g -> {
    String[] labelValues = id.getTags().stream()
        .map(Tag::getValue)
        .collect(Collectors.toList())
        .toArray(new String[]{});
    Gauge.Child child = new Gauge.Child() {
      @Override
      public double get() {
        final T obj = ref.get();
        return (obj == null) ? Double.NaN : f.applyAsDouble(obj);
      }
    };
    gauge.setChild(child, labelValues);
    return new PrometheusGauge(id, child);
  });
  return obj;
}

代码示例来源:origin: no.skatteetaten.aurora/aurora-prometheus

public Status() {
  statuses = Gauge.build()
    .name("statuses")
    .help("Status of things")
    .labelNames("name")
    .create();
}

代码示例来源:origin: org.apache.bookkeeper.stats/prometheus-metrics-provider

registerMetrics(Gauge.build("jvm_memory_direct_bytes_used", "-").create().setChild(new Child() {
  @Override
  public double get() {
registerMetrics(Gauge.build("jvm_memory_direct_bytes_max", "-").create().setChild(new Child() {
  @Override
  public double get() {

代码示例来源:origin: nlighten/tomcat_exporter

@Override
public void init(FilterConfig filterConfig) throws ServletException {
  if (servletLatency == null) {
    Histogram.Builder servletLatencyBuilder = Histogram.build()
        .name("servlet_request_seconds")
        .help("The time taken fulfilling servlet requests")
        .labelNames("context", "method");
    if ((filterConfig.getInitParameter(BUCKET_CONFIG_PARAM) != null) && (!filterConfig.getInitParameter(BUCKET_CONFIG_PARAM).isEmpty())) {
      String[] bucketParams = filterConfig.getInitParameter(BUCKET_CONFIG_PARAM).split(",");
      double[] buckets = new double[bucketParams.length];
      for (int i = 0; i < bucketParams.length; i++) {
        buckets[i] = Double.parseDouble(bucketParams[i].trim());
      }
      servletLatencyBuilder.buckets(buckets);
    } else {
      servletLatencyBuilder.buckets(.01, .05, .1, .25, .5, 1, 2.5, 5, 10, 30);
    }
    servletLatency = servletLatencyBuilder.register();
    Gauge.Builder servletConcurrentRequestBuilder = Gauge.build()
        .name("servlet_request_concurrent_total")
        .help("Number of concurrent requests for given context.")
        .labelNames("context");
    servletConcurrentRequest = servletConcurrentRequestBuilder.register();
    Gauge.Builder servletStatusCodesBuilder = Gauge.build()
        .name("servlet_response_status_total")
        .help("Number of requests for given context and status code.")
        .labelNames("context", "status");
    servletStatusCodes = servletStatusCodesBuilder.register();
  }
}

代码示例来源:origin: hellobike/tunnel

public PrometheusMonitor(ExporterConfig config) {
  this.gauge = Gauge.build()
      .name(config.getMetricName())
      .labelNames(config.getLabelNames()).help("Tunnel Requests.")
      .register();
}

代码示例来源:origin: nlighten/tomcat_exporter

failedQueryStatsEnabled = true;
if (failedQueryStats == null) {
  Gauge.Builder builder = Gauge.build()
      .help("Number of errors for give JDBC query")
      .name("tomcat_jdbc_failedquery_total")

代码示例来源:origin: com.yahoo.pulsar/pulsar-zookeeper

Gauge.build().name("zookeeper_server_znode_count").help("Number of z-nodes stored").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_data_size_bytes").help("Size of all of z-nodes stored (bytes)").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_connections").help("Number of currently opened connections").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_watches_count").help("Number of watches").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_ephemerals_count").help("Number of ephemerals z-nodes").create()
    .setChild(new Gauge.Child() {
      @Override

代码示例来源:origin: org.apache.pulsar/pulsar-zookeeper

Gauge.build().name("zookeeper_server_znode_count").help("Number of z-nodes stored").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_data_size_bytes").help("Size of all of z-nodes stored (bytes)").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_connections").help("Number of currently opened connections").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_watches_count").help("Number of watches").create()
    .setChild(new Gauge.Child() {
      @Override
Gauge.build().name("zookeeper_server_ephemerals_count").help("Number of ephemerals z-nodes").create()
    .setChild(new Gauge.Child() {
      @Override

代码示例来源:origin: johrstrom/jmeter-prometheus-plugin

this.threadCollector = Gauge.build().name("jmeter_running_threads").help("Counter for running threds")
    .create().register(CollectorRegistry.defaultRegistry);

相关文章