本文整理汇总了Java中io.prometheus.client.Collector.Type方法的典型用法代码示例。如果您正苦于以下问题:Java Collector.Type方法的具体用法?Java Collector.Type怎么用?Java Collector.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.prometheus.client.Collector
的用法示例。
在下文中一共展示了Collector.Type方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectorByName
import io.prometheus.client.Collector; //导入方法依赖的package包/类
private MicrometerCollector collectorByName(Meter.Id id, Collector.Type type) {
return collectorMap.compute(getConventionName(id), (name, existingCollector) -> {
if(existingCollector == null) {
return new MicrometerCollector(id, type, config().namingConvention(), prometheusConfig).register(registry);
}
List<String> tagKeys = getConventionTags(id).stream().map(Tag::getKey).collect(toList());
if(existingCollector.getTagKeys().equals(tagKeys)) {
return existingCollector;
}
throw new IllegalArgumentException("Prometheus requires that all meters with the same name have the same" +
" set of tag keys. There is already an existing meter containing tag keys [" +
existingCollector.getTagKeys().stream().collect(joining(", ")) + "]. The meter you are attempting to register" +
" has keys [" + tagKeys.stream().collect(joining(", ")) + "].");
});
}
示例2: typeString
import io.prometheus.client.Collector; //导入方法依赖的package包/类
private static String typeString(Collector.Type t) {
switch (t) {
case GAUGE:
return "gauge";
case COUNTER:
return "counter";
case SUMMARY:
return "summary";
case HISTOGRAM:
return "histogram";
default:
return "untyped";
}
}
示例3: newMeter
import io.prometheus.client.Collector; //导入方法依赖的package包/类
@Override
protected Meter newMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) {
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;
}
MicrometerCollector collector = collectorByName(id, promType);
List<String> tagValues = tagValues(id);
collector.add((conventionName, tagKeys) -> {
List<String> statKeys = new LinkedList<>(tagKeys);
statKeys.add("statistic");
return stream(measurements.spliterator(), false)
.map(m -> {
List<String> statValues = new LinkedList<>(tagValues);
statValues.add(m.getStatistic().toString());
String name = conventionName;
switch (m.getStatistic()) {
case Total:
case TotalTime:
name += "_sum";
break;
case Max:
name += "_max";
break;
case ActiveTasks:
name += "_active_count";
break;
case Duration:
name += "_duration_sum";
break;
}
return new Collector.MetricFamilySamples.Sample(name, tagKeys, tagValues, m.getValue());
});
});
return new DefaultMeter(id, type, measurements);
}