static Metadata metadataOf(String name, MetricType metricType) { Metadata res = new Metadata(name, metricType); res.setReusable(true); return res; }
/** * Constructs a Metadata object from a map with the following keys * <ul> * <li>{@code name} - The name of the metric</li> * <li>{@code displayName} - The display (friendly) name of the metric</li> * <li>{@code description} - The description of the metric</li> * <li>{@code type} - The type of the metric</li> * <li>{@code unit} - The units of the metric</li> * <li>{@code tags} - The tags of the metric - cannot be null</li> * <li>{@code reusable} - If <tt>true</tt>, this metric name is permitted to be used at multiple registration points. If * <tt>false</tt>, this metric name is only permitted to be used at one registration point per MetricRegistry.</li> * </ul> * * @param in a map of key/value pairs representing Metadata */ public Metadata(Map<String, String> in) { this(); this.name = (String) in.get("name"); this.description = (String) in.get("description"); this.displayName = (String) in.get("displayName"); this.setType((String) in.get("type")); this.setUnit((String) in.get("unit")); if (in.keySet().contains("tags")) { String tagString = (String) in.get("tags"); addTags(tagString); } this.setReusable(Boolean.parseBoolean(in.get("reusable"))); }
public void badRegisterReusableMixed() { Metadata metadata = new Metadata("badReusableMixed", MetricType.HISTOGRAM); metadata.setReusable(true); Histogram histogram = registry.histogram(metadata); histogram.update(1); // We register a different metric type - that is forbidden // so we expect an exception Metadata metadata2 = new Metadata("badReusableMixed", MetricType.COUNTER); metadata2.setReusable(true); registry.counter(metadata2); }
public void registerReusableHistogram() { Metadata metadata = new Metadata("reusableHisto", MetricType.HISTOGRAM); metadata.setReusable(true); Histogram histogram = registry.histogram(metadata); histogram.update(1); Histogram histogram1 = registry.histogram(metadata); histogram1.update(3); }
@Override @Deprecated public <T extends Metric> T register(String name, T t, Metadata metadata) throws IllegalArgumentException { Metadata metadataCopy = new Metadata(name, metadata.getDisplayName(), metadata.getDescription(), metadata.getTypeRaw(), metadata.getUnit(), metadata.getTagsAsString()); metadataCopy.setReusable(metadata.isReusable()); metadataCopy.setName(name); return register(metadataCopy, t); }
private Holder(final T metric, final Metadata metadata) { this.metric = metric; this.metadata = new Metadata(metadata.getName(), metadata.getDisplayName(), metadata.getDescription(), metadata.getTypeRaw(), metadata.getUnit()); this.metadata.setReusable(metadata.isReusable()); this.metadata.setTags(metadata.getTags()); } }
metadata.setDescription(description); metadata.setUnit(unit); metadata.setReusable(reusable);