public CustomPrometheusCollector(Meter.Id id, Type type) { this.type = type; this.name = id.getConventionName(); this.tagKeys = id.getConventionTags().stream().map(Tag::getKey).collect(toList()); }
public CustomPrometheusLongTaskTimer(Meter.Id id, Clock clock) { this.name = id.getConventionName(); this.description = id.getDescription(); this.clock = clock; this.tagKeys = id.getConventionTags().stream().map(Tag::getKey).collect(toList()); this.activeTasksName = name + "_active_count"; this.durationName = name + "_sum"; }
public CustomPrometheusSummary(Meter.Id id) { this.name = id.getConventionName(); this.description = id.getDescription(); this.countName = name + "_count"; this.sumName = name + "_sum"; this.tagKeys = id.getConventionTags().stream().map(Tag::getKey).collect(toList()); }
@Override protected void newMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) { CustomPrometheusCollector c = (CustomPrometheusCollector) collectorMap.computeIfAbsent(id.getConventionName(), name2 -> { Collector.Type promType = Collector.Type.UNTYPED; switch (type) { case Counter: promType = Collector.Type.COUNTER; break; case Gauge: promType = Collector.Type.GAUGE; break; case DistributionSummary: case Timer: promType = Collector.Type.SUMMARY; break; } Collector collector = new CustomPrometheusCollector(id, promType); registry.register(collector); return collector; }); c.child(id.getConventionTags(), measurements); }
@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); }
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { for (; ; ) { if (namingConventionUpdater.compareAndSet(this, this.namingConvention, next)) break; } this.name = telegrafEscape(next.name(id.getName(), id.getType(), id.getBaseUnit())); this.tags = HashTreePMap.empty(); this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ? id.getConventionTags(this.namingConvention).stream() .map(t -> telegrafEscape(t.getKey()) + "=" + telegrafEscape(t.getValue())) .collect(Collectors.joining(",")) : null; this.tagsNoStat = tags(null, conventionTags, "=", ","); } }
@Nullable private MetricDatum metricDatum(Meter.Id id, @Nullable String suffix, @Nullable String unit, double value) { if (Double.isNaN(value)) { return null; } List<Tag> tags = id.getConventionTags(config().namingConvention()); return new MetricDatum() .withMetricName(getMetricName(id, suffix)) .withDimensions(toDimensions(tags)) .withTimestamp(new Date(wallTime)) .withValue(CloudWatchUtils.clampMetricValue(value)) .withUnit(toStandardUnit(unit)); }
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { this.namingConvention = next; this.name = sanitize(next.name(id.getName(), id.getType(), id.getBaseUnit())); this.tags = HashTreePMap.empty(); this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ? id.getConventionTags(this.namingConvention).stream() .map(t -> sanitize(t.getKey()) + "=" + sanitize(t.getValue())) .collect(Collectors.joining(",")) : null; this.tagsNoStat = tags(null, conventionTags, "=", "#"); } }
private <B extends SimpleCollector.Builder<B, C>, C extends SimpleCollector<D>, D> C buildCollector(Meter.Id id, SimpleCollector.Builder<B, C> builder) { return builder .name(id.getConventionName()) .help(!sendDescriptions || id.getDescription() == null ? " " : id.getDescription()) .labelNames(id.getConventionTags().stream() .map(Tag::getKey) .collect(Collectors.toList()) .toArray(new String[]{})) .register(registry); }
@Override protected io.micrometer.core.instrument.Timer newTimer(Meter.Id id, Histogram.Builder<?> histogram, Quantiles quantiles) { id.setBaseUnit("seconds"); final CustomPrometheusSummary summary = collectorByName(CustomPrometheusSummary.class, id.getConventionName(), n -> new CustomPrometheusSummary(id).register(registry)); return new PrometheusTimer(id, summary.child(id.getConventionTags(), quantiles, buildHistogramIfNecessary(histogram)), config().clock()); }
@Override protected LongTaskTimer newLongTaskTimer(Meter.Id id) { final CustomPrometheusLongTaskTimer longTaskTimer = collectorByName(CustomPrometheusLongTaskTimer.class, id.getConventionName(), n -> new CustomPrometheusLongTaskTimer(id, config().clock()).register(registry)); return new PrometheusLongTaskTimer(id, longTaskTimer.child(id.getConventionTags())); }
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { this.namingConvention = next; this.name = next.name(sanitize(id.getName()), id.getType(), id.getBaseUnit()) + ":"; this.tags = HashTreePMap.empty(); this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ? id.getConventionTags(this.namingConvention).stream() .map(t -> sanitize(t.getKey()) + ":" + sanitize(t.getValue())) .collect(Collectors.joining(",")) : null; this.tagsNoStat = tags(null, conventionTags, ":", "|#"); } }
@Override public Counter newCounter(Meter.Id id) { io.prometheus.client.Counter counter = collectorByName(io.prometheus.client.Counter.class, id.getConventionName(), n -> buildCollector(id, io.prometheus.client.Counter.build())); return new PrometheusCounter(id, counter.labels(id.getConventionTags().stream() .map(Tag::getValue) .collect(Collectors.toList()) .toArray(new String[]{}))); }
@Override public DistributionSummary newDistributionSummary(Meter.Id id, Histogram.Builder<?> histogram, Quantiles quantiles) { final CustomPrometheusSummary summary = collectorByName(CustomPrometheusSummary.class, id.getConventionName(), n -> new CustomPrometheusSummary(id).register(registry)); return new PrometheusDistributionSummary(id, summary.child(id.getConventionTags(), quantiles, buildHistogramIfNecessary(histogram))); }