@Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { final String suffix = nameSuffix == null ? "" : nameSuffix; final List<String> labelNames = additionalLabelNames == null ? Collections.<String>emptyList() : additionalLabelNames; final List<String> labelValues = additionalLabelValues == null ? Collections.<String>emptyList() : additionalLabelValues; return new Collector.MetricFamilySamples.Sample( Collector.sanitizeMetricName(dropwizardName + suffix), new ArrayList<String>(labelNames), new ArrayList<String>(labelValues), value ); } }
@Override public List<MetricFamilySamples> collect() { ArrayList<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); for (PublicMetrics publicMetrics : this.publicMetrics) { for (Metric<?> metric : publicMetrics.metrics()) { String name = Collector.sanitizeMetricName(metric.getName()); double value = metric.getValue().doubleValue(); MetricFamilySamples metricFamilySamples = new MetricFamilySamples( name, Type.GAUGE, name, Collections.singletonList( new MetricFamilySamples.Sample(name, Collections.<String>emptyList(), Collections.<String>emptyList(), value))); samples.add(metricFamilySamples); } } return samples; }
private String completeName(String name) { String completeName = scope.isEmpty() ? name : Joiner.on('_').join(scope, name); return Collector.sanitizeMetricName(completeName); } }
@Override public String getStatsName(String... statsComponents) { String completeName; if (statsComponents.length == 0) { return ""; } else if (statsComponents[0].isEmpty()) { completeName = StringUtils.join(statsComponents, '_', 1, statsComponents.length); } else { completeName = StringUtils.join(statsComponents, '_'); } return Collector.sanitizeMetricName(completeName); } });
@VisibleForTesting static List<String> convertToLabelNames(List<LabelKey> labelKeys) { final List<String> labelNames = new ArrayList<String>(labelKeys.size()); for (LabelKey labelKey : labelKeys) { labelNames.add(Collector.sanitizeMetricName(labelKey.getKey())); } return labelNames; }
@Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { final String suffix = nameSuffix == null ? "" : nameSuffix; final List<String> labelNames = additionalLabelNames == null ? Collections.<String>emptyList() : additionalLabelNames; final List<String> labelValues = additionalLabelValues == null ? Collections.<String>emptyList() : additionalLabelValues; return new Collector.MetricFamilySamples.Sample( Collector.sanitizeMetricName(dropwizardName + suffix), new ArrayList<String>(labelNames), new ArrayList<String>(labelValues), value ); } }
@Override public List<MetricFamilySamples> collect() { ArrayList<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); for (PublicMetrics publicMetrics : this.publicMetrics) { for (Metric<?> metric : publicMetrics.metrics()) { String name = Collector.sanitizeMetricName(metric.getName()); double value = metric.getValue().doubleValue(); MetricFamilySamples metricFamilySamples = new MetricFamilySamples( name, Type.GAUGE, name, Collections.singletonList( new MetricFamilySamples.Sample(name, Collections.<String>emptyList(), Collections.<String>emptyList(), value))); samples.add(metricFamilySamples); } } return samples; }
static MetricFamilySamples createDescribableMetricFamilySamples( MetricDescriptor metricDescriptor) { String name = Collector.sanitizeMetricName(metricDescriptor.getName()); Type type = getType(metricDescriptor.getType()); List<String> labelNames = convertToLabelNames(metricDescriptor.getLabelKeys()); if (containsDisallowedLeLabelForHistogram(labelNames, type)) { throw new IllegalStateException( "Prometheus Histogram cannot have a label named 'le', " + "because it is a reserved label for bucket boundaries. " + "Please remove this key from your view."); } if (containsDisallowedQuantileLabelForSummary(labelNames, type)) { throw new IllegalStateException( "Prometheus Summary cannot have a label named 'quantile', " + "because it is a reserved label. Please remove this key from your view."); } return new MetricFamilySamples( name, type, metricDescriptor.getDescription(), Collections.<Sample>emptyList()); }
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); }