boundDimensions, MetricSettings customSettings) {
if (customSettings != null) {
addMetricDefinition(name, customSettings);
}
Point defaultDimensions = null;
if (boundDimensions.isPresent()) {
defaultDimensions = boundDimensions.get();
}
return new Gauge(name, defaultDimensions, this);
}
/**
* Create a PointBuilder instance with no default settings. PointBuilder
* instances are not thread-safe.
*
* @return an "empty" point builder instance
*/
public PointBuilder pointBuilder() {
return new PointBuilder();
}
/**
* Fetch the latest metric values, aggregated over all threads for the
* configured sample history (by default five minutes). The values will be
* less than 1 second old, and this method has only a memory barrier as side
* effect.
*
* @return the latest five minutes of metrics
*/
public Bucket getSnapshot() {
return currentSnapshot.get();
}
/**
* Add how to build a histogram for a given metric.
*
*
* Do note, this is not part of the public API.
*
*
* @param metricName
* the metric where samples should be put in a histogram
* @param definition
* settings for a histogram
*/
void addMetricDefinition(String metricName, MetricSettings definition) {
synchronized (histogramDefinitionsLock) {
// read the volatile _after_ acquiring the lock
Map oldMetricDefinitions = metricSettings;
Map builderMap = new HashMap<>(oldMetricDefinitions.size() + 1);
builderMap.putAll(oldMetricDefinitions);
builderMap.put(metricName, definition);
metricSettings = ImmutableMap.copyOf(builderMap);
}
}
/**
* Get how to build a histogram for a given metric, or null if no histogram
* should be created.
*
*
* Do note, this is not part of the public API.
*
*
* @param metricName
* the name of an arbitrary metric
* @return the corresponding histogram definition or null
*/
MetricSettings getMetricDefinition(String metricName) {
return metricSettings.get(metricName);
}
}