List of usage examples for org.apache.hadoop.metrics2 MetricsException MetricsException
public MetricsException(Throwable cause)
From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java
License:Apache License
/** * Add a tag to the metrics/* w w w . j av a 2 s . c o m*/ * @param name of the tag * @param description of the tag * @param value of the tag * @param override existing tag if true * @return the registry (for keep adding tags) */ public DynamicMetricsRegistry tag(String name, String description, String value, boolean override) { MetricsTag tag = new MetricsTag(name, description, value); if (!override) { MetricsTag existing = tagsMap.putIfAbsent(name, tag); if (existing != null) { throw new MetricsException("Tag " + name + " already exists!"); } return this; } tagsMap.put(name, tag); return this; }
From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java
License:Apache License
/** * Get a MetricMutableGaugeLong from the storage. If it is not there * atomically put it./*from w w w . ja v a2s . co m*/ * * @param gaugeName name of the gauge to create or get. * @param potentialStartingValue value of the new counter if we have to create * it. * @return a metric object */ public MetricMutableGaugeLong getLongGauge(String gaugeName, long potentialStartingValue) { // Try and get the guage. MetricMutable metric = metricsMap.get(gaugeName); // If it's not there then try and put a new one in the storage. if (metric == null) { // Create the potential new gauge. MetricMutableGaugeLong newGauge = mf.newGauge(gaugeName, "", potentialStartingValue); // Try and put the gauge in. This is atomic. metric = metricsMap.putIfAbsent(gaugeName, newGauge); // If the value we get back is null then the put was successful and we // will // return that. Otherwise gaugeLong should contain the thing that was in // before the put could be completed. if (metric == null) { return newGauge; } } if (!(metric instanceof MetricMutableGaugeLong)) { throw new MetricsException("Metric already exists in registry for metric name: " + name + " and not of type MetricMutableGaugeLong"); } return (MetricMutableGaugeLong) metric; }
From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java
License:Apache License
/** * Get a MetricMutableCounterLong from the storage. If it is not there * atomically put it.// w w w . j a v a 2 s . c om * * @param counterName Name of the counter to get * @param potentialStartingValue starting value if we have to create a new * counter * @return a metric object */ public MetricMutableCounterLong getLongCounter(String counterName, long potentialStartingValue) { // See getLongGauge for description on how this works. MetricMutable counter = metricsMap.get(counterName); if (counter == null) { MetricMutableCounterLong newCounter = mf.newCounter(counterName, "", potentialStartingValue); counter = metricsMap.putIfAbsent(counterName, newCounter); if (counter == null) { return newCounter; } } if (!(counter instanceof MetricMutableCounterLong)) { throw new MetricsException("Metric already exists in registry for metric name: " + name + "and not of type MetricMutableCounterLong"); } return (MetricMutableCounterLong) counter; }
From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java
License:Apache License
public MetricMutableHistogram getHistogram(String histoName) { // See getLongGauge for description on how this works. MetricMutable histo = metricsMap.get(histoName); if (histo == null) { MetricMutableHistogram newHisto = new MetricMutableHistogram(histoName, ""); histo = metricsMap.putIfAbsent(histoName, newHisto); if (histo == null) { return newHisto; }/*from w w w.j av a 2 s . c o m*/ } if (!(histo instanceof MetricMutableHistogram)) { throw new MetricsException("Metric already exists in registry for metric name: " + name + "and not of type MetricMutableHistogram"); } return (MetricMutableHistogram) histo; }
From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java
License:Apache License
public MetricMutableQuantiles getQuantile(String histoName) { // See getLongGauge for description on how this works. MetricMutable histo = metricsMap.get(histoName); if (histo == null) { MetricMutableQuantiles newHisto = new MetricMutableQuantiles(histoName, ""); histo = metricsMap.putIfAbsent(histoName, newHisto); if (histo == null) { return newHisto; }// w w w. java 2 s. c o m } if (!(histo instanceof MetricMutableQuantiles)) { throw new MetricsException("Metric already exists in registry for metric name: " + name + "and not of type MetricMutableQuantiles"); } return (MetricMutableQuantiles) histo; }
From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java
License:Apache License
private <T> T returnExistingWithCast(MetricMutable metric, Class<T> metricClass, String name) { if (!metricClass.isAssignableFrom(metric.getClass())) { throw new MetricsException("Metric already exists in registry for metric name: " + name + " and not of type " + metricClass); }// w w w.jav a 2s . c o m return (T) metric; }