當前位置: 首頁>>代碼示例>>Java>>正文


Java Metrics類代碼示例

本文整理匯總了Java中io.prometheus.client.Metrics的典型用法代碼示例。如果您正苦於以下問題:Java Metrics類的具體用法?Java Metrics怎麽用?Java Metrics使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Metrics類屬於io.prometheus.client包,在下文中一共展示了Metrics類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: consumeMetric

import io.prometheus.client.Metrics; //導入依賴的package包/類
private void consumeMetric(final Metric metric) throws IOException {
  familyBuilder = createMetricFamily(metric);
  metricBuilder = Metrics.Metric.newBuilder();
  // registering all static labelValues
  staticLabels.forEach((n, v) ->
      metricBuilder.addLabel(createLabel(n, v)));

  // build metric family
  metric.forEachMetricData(this);

  // flush metric family into output stream
  familyBuilder.build().writeDelimitedTo(stream);
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:14,代碼來源:ProtobufFormatter.java

示例2: protobuf

import io.prometheus.client.Metrics; //導入依賴的package包/類
@Test
public void protobuf() {
  await(response(body -> {
    try {
      Metrics.MetricFamily.parseDelimitedFrom(new ByteArrayInputStream(body.getBytes()));
    } catch (IOException e) {
      context().fail(e);
    }
  }));
}
 
開發者ID:nolequen,項目名稱:vertx-prometheus-metrics,代碼行數:11,代碼來源:ProtobufFormatTest.java

示例3: consumeCounter

import io.prometheus.client.Metrics; //導入依賴的package包/類
@Override
public void consumeCounter(final Metric metric, final List<String> labelValues, final double value) {
  familyBuilder.setType(Metrics.MetricType.COUNTER);
  final Metrics.Counter counter = Metrics.Counter.newBuilder().setValue(value).build();
  addMetric(() -> metricBuilder.setCounter(counter).build(), metric.getLabelNames(), labelValues);

}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:8,代碼來源:ProtobufFormatter.java

示例4: consumeSummary

import io.prometheus.client.Metrics; //導入依賴的package包/類
@Override
public void consumeSummary(final Metric metric, final List<String> labelValues, final SummaryData data) {
  familyBuilder.setType(Metrics.MetricType.SUMMARY);
  final Metrics.Summary.Builder summaryBuilder = Metrics.Summary.newBuilder().
    setSampleCount(data.getCount()).setSampleSum(data.getSum());
  summaryBuilder.addQuantile(Metrics.Quantile.newBuilder().setQuantile(0.5d).setValue(data.getMedian()));
  summaryBuilder.addQuantile(Metrics.Quantile.newBuilder().setQuantile(0.75d).setValue(data.get75thPercentile()));
  summaryBuilder.addQuantile(Metrics.Quantile.newBuilder().setQuantile(0.95d).setValue(data.get95thPercentile()));
  summaryBuilder.addQuantile(Metrics.Quantile.newBuilder().setQuantile(0.98d).setValue(data.get98thPercentile()));
  summaryBuilder.addQuantile(Metrics.Quantile.newBuilder().setQuantile(0.99d).setValue(data.get99thPercentile()));
  summaryBuilder.addQuantile(Metrics.Quantile.newBuilder().setQuantile(0.999d).setValue(data.get999thPercentile()));
  addMetric(() -> metricBuilder.setSummary(summaryBuilder).build(), metric.getLabelNames(), labelValues);
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:14,代碼來源:ProtobufFormatter.java

示例5: consumeHistogram

import io.prometheus.client.Metrics; //導入依賴的package包/類
@Override
public void consumeHistogram(final Metric metric, final List<String> labelValues, final HistogramData data) {
  familyBuilder.setType(Metrics.MetricType.HISTOGRAM);
  final Metrics.Histogram.Builder histogramBuilder = Metrics.Histogram.newBuilder().
      setSampleCount(data.getCount()).setSampleSum(data.getSum());
  data.consumeBuckets((upperBound, count) -> {
    histogramBuilder.addBucket(Metrics.Bucket.newBuilder().setCumulativeCount(count).setUpperBound(upperBound));
  });

  addMetric(() -> metricBuilder.setHistogram(histogramBuilder).build(), metric.getLabelNames(), labelValues);
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:12,代碼來源:ProtobufFormatter.java

示例6: addMetric

import io.prometheus.client.Metrics; //導入依賴的package包/類
private void addMetric(final Supplier<Metrics.Metric> metricSupplier,
                           final List<String> labelNames,
                           final List<String> labelValues)  {
  // add labels to the builder
  final int previousCount = addLabels(metricBuilder, labelNames, labelValues);

  // create the metric object
  final Metrics.Metric metric = metricSupplier.get();

  // reset builders to be reused
  resetMetricBuilderLabels(metricBuilder, labelValues, previousCount);

  familyBuilder.addMetric(metric);
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:15,代碼來源:ProtobufFormatter.java

示例7: addLabels

import io.prometheus.client.Metrics; //導入依賴的package包/類
private static int addLabels(final Metrics.Metric.Builder metricBuilder, final List<String> labelNames, final List<String> labelValues) {
  final int labelsCount = metricBuilder.getLabelCount();
  for (int i = 0; i < labelValues.size(); i++) {
    metricBuilder.addLabel(createLabel(labelNames.get(i), labelValues.get(i)));
  }
  return labelsCount;
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:8,代碼來源:ProtobufFormatter.java

示例8: get

import io.prometheus.client.Metrics; //導入依賴的package包/類
public Map<String, Double> get(String url)  {
    Map<String, Double> result = new HashMap<>();
    try {
        Response response = CLIENT.prepareGet(url).setHeader("Accept", PB_ACCEPT_HEADER).execute().get();

        final ByteBuffer buf = response.getResponseBodyAsByteBuffer();
        final InputStream body = new InputStream() {

            @Override
            public int read() throws IOException {
                if (!buf.hasRemaining()) {
                    return -1;
                }
                return buf.get() & 0xFF;
            }

            @Override
            public int read(byte[] bytes, int off, int len) throws IOException {
                if (!buf.hasRemaining()) {
                    return -1;
                }

                len = Math.min(len, buf.remaining());
                buf.get(bytes, off, len);
                return len;
            }
        };

        while (buf.remaining() > 0) {
            Metrics.MetricFamily metrics = Metrics.MetricFamily.parseDelimitedFrom(body);
            if (metrics.getType() == Metrics.MetricType.SUMMARY) continue;
            metrics.getMetricList().forEach(metric -> {
                String labels = metric.getLabelList().stream().map(l -> l.getName() + "=\"" + l.getValue() + "\"").collect(Collectors.joining(","));
                if (!labels.isEmpty()) labels = "{" + labels + "}";
                String key = metrics.getName() + labels;
                double value = (metric.hasCounter()) ? metric.getCounter().getValue() : ((metric.hasGauge()) ? metric.getGauge().getValue() : -1);

                if (LOGGER.isDebugEnabled()) LOGGER.debug(key + " " + value);
                result.put(key, value);
            });
        }
    } catch (Exception ignore) {
        //
    }

    return result;
}
 
開發者ID:globocom,項目名稱:groot,代碼行數:48,代碼來源:NodeExporterClient.java

示例9: consumeGauge

import io.prometheus.client.Metrics; //導入依賴的package包/類
@Override
public void consumeGauge(final Metric metric, final List<String> labelValues, final double value) {
  familyBuilder.setType(Metrics.MetricType.GAUGE);
  final Metrics.Gauge gauge = Metrics.Gauge.newBuilder().setValue(value).build();
  addMetric(() -> metricBuilder.setGauge(gauge).build(), metric.getLabelNames(), labelValues);
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:7,代碼來源:ProtobufFormatter.java

示例10: createMetricFamily

import io.prometheus.client.Metrics; //導入依賴的package包/類
private static Metrics.MetricFamily.Builder createMetricFamily(final Metric metric) {
  return Metrics.MetricFamily.newBuilder().
      setName(metric.getName()).
      setHelp(metric.getHelp());
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:6,代碼來源:ProtobufFormatter.java

示例11: resetMetricBuilderLabels

import io.prometheus.client.Metrics; //導入依賴的package包/類
private static void resetMetricBuilderLabels(final Metrics.Metric.Builder metricBuilder, final List<String> labelValues, final int currentCount) {
  for (int i = labelValues.size() - 1; i >= 0; i--) {
    metricBuilder.removeLabel(currentCount + i);
  }
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:6,代碼來源:ProtobufFormatter.java

示例12: createLabel

import io.prometheus.client.Metrics; //導入依賴的package包/類
private static Metrics.LabelPair createLabel(final String n, final String v) {
  return Metrics.LabelPair.newBuilder().
      setName(n).
      setValue(v).
      build();
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:7,代碼來源:ProtobufFormatter.java


注:本文中的io.prometheus.client.Metrics類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。