samples.add(new MetricFamilySamples.Sample( "jmx_scrape_duration_seconds", new ArrayList<String>(), new ArrayList<String>(), (System.nanoTime() - start) / 1.0E9)); mfsList.add(new MetricFamilySamples("jmx_scrape_duration_seconds", Type.GAUGE, "Time this JMX scrape took, in seconds.", samples)); mfsList.add(new MetricFamilySamples("jmx_scrape_error", Type.GAUGE, "Non-zero if this scrape failed.", samples)); return mfsList;
private static List<MetricFamilySamples> meter(MetricName metricName, Meter meter) { String name = normalize(metricName); Tuple2<List<String>, List<String>> tuple = tags(metricName); List<Sample> samples = singletonList(new Sample(name + "_total", tuple.getV1(), tuple.getV2(), meter.getCount())); return singletonList(new MetricFamilySamples(name + "_total", COUNTER, message(metricName, meter), samples)); }
private static List<MetricFamilySamples> counter(MetricName metricName, Counter counter) { String name = normalize(metricName); Tuple2<List<String>, List<String>> tuple = tags(metricName); Sample sample = new Sample(name, tuple.getV1(), tuple.getV2(), new Long(counter.getCount()).doubleValue()); return singletonList(new MetricFamilySamples(name, GAUGE, message(metricName, counter), singletonList(sample))); }
public MetricFamilySamples fromSnapshotAndCount(String name, Snapshot snapshot, long count, double factor, String helpMessage) { List<String> labelNames = addToEnd(this.labelNames, "quantile"); List<Sample> samples = Arrays.asList( new Sample(name, labelNames, addToEnd(labelValues, "0.5"), snapshot.getMedian() * factor), new Sample(name, labelNames, addToEnd(labelValues, "0.75"), snapshot.get75thPercentile() * factor), new Sample(name, labelNames, addToEnd(labelValues, "0.95"), snapshot.get95thPercentile() * factor), new Sample(name, labelNames, addToEnd(labelValues, "0.98"), snapshot.get98thPercentile() * factor), new Sample(name, labelNames, addToEnd(labelValues, "0.99"), snapshot.get99thPercentile() * factor), new Sample(name, labelNames, addToEnd(labelValues, "0.999"), snapshot.get999thPercentile() * factor), new Sample(name + "_count", new ArrayList<String>(), new ArrayList<String>(), count) ); return new MetricFamilySamples(name, Type.SUMMARY, helpMessage, samples); }
static MetricFamilySamples createMetricFamilySamples(Metric metric) { MetricDescriptor metricDescriptor = metric.getMetricDescriptor(); String name = Collector.sanitizeMetricName(metricDescriptor.getName()); Type type = getType(metricDescriptor.getType()); List<String> labelNames = convertToLabelNames(metricDescriptor.getLabelKeys()); List<Sample> samples = Lists.newArrayList(); for (io.opencensus.metrics.export.TimeSeries timeSeries : metric.getTimeSeriesList()) { for (io.opencensus.metrics.export.Point point : timeSeries.getPoints()) { samples.addAll(getSamples(name, labelNames, timeSeries.getLabelValues(), point.getValue())); } } return new MetricFamilySamples(name, type, metricDescriptor.getDescription(), samples); }
/** * Export a Meter as as prometheus COUNTER. */ public List<Collector.MetricFamilySamples> fromMeter(String registryName, String metricName, Meter meter, List<String> labels, List<String> labelValues) { final String name = metricNameUtil.sanitizeMetricName(metricName) + UNDERSCORE_TOTAL; return Lists.newArrayList( new Collector.MetricFamilySamples(name, Collector.Type.COUNTER, getHelpMessage(registryName, metricName, meter), Lists.newArrayList( new Collector.MetricFamilySamples.Sample(name, labels, labelValues, meter.getCount()))) ); }
@Override public List<MetricFamilySamples> collect() { String name = getSanitizedName(); Type metricType = metric.getType() == Metric.Type.COUNT ? Type.COUNTER : Type.GAUGE; List<Sample> samples = Collections.singletonList(getSample(metric, name)); return Collections.singletonList(new MetricFamilySamples(name, metricType, "", samples)); }
@Override public List<MetricFamilySamples> collect() { return Collections.singletonList(new MetricFamilySamples(name, Type.UNTYPED, " ", children.stream() .flatMap(Child::collect).collect(toList()))); } }
@Override public List<MetricFamilySamples> collect() { return Collections.singletonList(new MetricFamilySamples(name, Type.UNTYPED, description == null ? " " : description, children.stream() .flatMap(Child::collect).collect(toList()))); } }
@Override public List<MetricFamilySamples> collect() { Type type = children.stream().anyMatch(c -> c.histogram != null) ? Type.HISTOGRAM : Type.SUMMARY; return Collections.singletonList(new MetricFamilySamples(name, type, description == null ? " " : description, children.stream() .flatMap(Child::collect).collect(toList()))); } }
private void addToMap(Map<String, MetricFamilySamples> mfSamplesMap, MetricFamilySamples newMfSamples) { if (newMfSamples != null) { MetricFamilySamples currentMfSamples = mfSamplesMap.get(newMfSamples.name); if (currentMfSamples == null) { mfSamplesMap.put(newMfSamples.name, newMfSamples); } else { List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(currentMfSamples.samples); samples.addAll(newMfSamples.samples); mfSamplesMap.put(newMfSamples.name, new MetricFamilySamples(newMfSamples.name, currentMfSamples.type, currentMfSamples.help, samples)); } } }
/** * Export counter as Prometheus <a href="https://prometheus.io/docs/concepts/metric_types/#gauge">Gauge</a>. */ public List<Collector.MetricFamilySamples> fromCounter(String registryName, String metricName, Counter counter, List<String> labels, List<String> labelValues) { final String name = metricNameUtil.sanitizeMetricName(metricName); final Collector.MetricFamilySamples.Sample sample = new Collector.MetricFamilySamples.Sample(name, labels, labelValues, Long.valueOf(counter.getCount()).doubleValue()); return Lists.newArrayList(new Collector.MetricFamilySamples(name, Collector.Type.GAUGE, getHelpMessage(registryName, metricName, counter), Lists.newArrayList(sample))); }
private void collectElapsedTime( final double timeMillis, final List<MetricFamilySamples> mfsList) { mfsList.add( new MetricFamilySamples( "" + this.hashCode(), Type.GAUGE, help, Collections.singletonList( newSample(METRIC_NAME_TIME, "value", timeMillis / Constants.K)))); }
/** * Export a Meter as as prometheus COUNTER. */ MetricFamilySamples fromMeter(String dropwizardName, Meter meter) { final MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "_total", new ArrayList<String>(), new ArrayList<String>(), meter.getCount()); return new MetricFamilySamples(sample.name, Type.COUNTER, getHelpMessage(dropwizardName, meter), Arrays.asList(sample)); }
/** * Export counter as Prometheus <a href="https://prometheus.io/docs/concepts/metric_types/#gauge">Gauge</a>. */ MetricFamilySamples fromCounter(String dropwizardName, Counter counter) { MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "", new ArrayList<String>(), new ArrayList<String>(), new Long(counter.getCount()).doubleValue()); return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, counter), Arrays.asList(sample)); }
private MetricFamilySamples createSample(String name, String helpMessage, double value) { List<MetricFamilySamples.Sample> samples = Collections.singletonList(new MetricFamilySamples.Sample(name, labelNames, labelValues, value)); return new MetricFamilySamples(name, Type.GAUGE, helpMessage, samples); } }
protected List<MetricFamilySamples> familySamplesList(Collector.Type type, List<MetricFamilySamples.Sample> samples) { MetricFamilySamples mfs = new MetricFamilySamples(fullname, type, help, samples); List<MetricFamilySamples> mfsList = new ArrayList<MetricFamilySamples>(1); mfsList.add(mfs); return mfsList; }
public MetricFamilySamples toSamples(List<Value> values) { List<MetricFamilySamples.Sample> list = new ArrayList<MetricFamilySamples.Sample>(); for (Value v : values) { MetricFamilySamples.Sample sample = v.toSample(name); if (sample != null) { list.add(sample); } } return new MetricFamilySamples(name, Type.GAUGE, helpDoc, list); }
@Override public List<MetricFamilySamples> collect() { return Collections.singletonList(new MetricFamilySamples(name, type, " ", children.stream() .flatMap(Child::collect).collect(toList()))); }
public @NotNull List<MetricFamilySamples> stop() { final long duration = System.nanoTime() - startTime; final List<MetricFamilySamples> samples = receiver.samples(); samples.add(new MetricFamilySamples(METRICS_NAME, Type.GAUGE, HELP, Collections.singletonList( new MetricFamilySamples.Sample(METRICS_NAME, Collections.emptyList(), Collections.emptyList(), duration)))); return samples; } }