Java Code Examples for io.prometheus.client.Collector#sanitizeMetricName()
The following examples show how to use
io.prometheus.client.Collector#sanitizeMetricName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultSampleBuilder.java From metrics with Apache License 2.0 | 6 votes |
@Override public Collector.MetricFamilySamples.Sample createSample(MetricName metricName, String suffix, List<String> labelNames, List<String> labelValues, double value) { String name = metricName.getKey(); String nameSuffix = suffix == null ? "" : suffix; Map<String, String> tags = metricName.getTags(); List<String> tagNames = labelNames == null ? new ArrayList<String>() : labelNames; List<String> tagValues = labelValues == null ? new ArrayList<String>() : labelValues; if (tags != null && tags.size() > 0) { for (Map.Entry<String, String> entry : tags.entrySet()) { tagNames.add(entry.getKey()); tagValues.add(entry.getValue()); } } return new Collector.MetricFamilySamples.Sample( Collector.sanitizeMetricName(name + nameSuffix), tagNames, tagValues, value); }
Example 2
Source File: MetricAdapter.java From opentelemetry-java with Apache License 2.0 | 5 votes |
private static String toMetricFullName( String descriptorMetricName, String instrumentationLibraryName) { if (instrumentationLibraryName.isEmpty()) { return Collector.sanitizeMetricName(descriptorMetricName); } // Use "_" here even though the right way would be to use "." in general, but "." will be // replaced with "_" anyway so one less replace call. return Collector.sanitizeMetricName(instrumentationLibraryName + "_" + descriptorMetricName); }
Example 3
Source File: PrometheusExportUtils.java From opencensus-java with Apache License 2.0 | 5 votes |
private static String getNamespacedName(String metricName, String namespace) { if (!namespace.isEmpty()) { if (!namespace.endsWith("/") && !namespace.endsWith("_")) { namespace += '_'; } metricName = namespace + metricName; } return Collector.sanitizeMetricName(metricName); }
Example 4
Source File: PrometheusMetricsProvider.java From pulsar with Apache License 2.0 | 5 votes |
public PrometheusMetricsProvider() { this.cachingStatsProvider = new CachingStatsProvider(new StatsProvider() { @Override public void start(Configuration conf) { // nop } @Override public void stop() { // nop } @Override public StatsLogger getStatsLogger(String scope) { return new PrometheusStatsLogger(PrometheusMetricsProvider.this, scope); } @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); } }); }
Example 5
Source File: DefaultSampleBuilder.java From client_java with Apache License 2.0 | 5 votes |
@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 ); }
Example 6
Source File: SpringBootMetricsCollector.java From client_java with Apache License 2.0 | 5 votes |
@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; }
Example 7
Source File: MetricAdapter.java From opentelemetry-java with Apache License 2.0 | 4 votes |
static String toLabelName(String labelKey) { return Collector.sanitizeMetricName(labelKey); }
Example 8
Source File: AlibabaMetricsExports.java From metrics with Apache License 2.0 | 4 votes |
private String normalizeName(String name) { return Collector.sanitizeMetricName(name); }