use of io.opencensus.stats.Measure in project instrumentation-java by census-instrumentation.
the class MeasureToViewMap method registerView.
/**
* Enable stats collection for the given {@link View}.
*/
synchronized void registerView(View view, Clock clock) {
exportedViews = null;
View existing = registeredViews.get(view.getName());
if (existing != null) {
if (existing.equals(view)) {
// Ignore views that are already registered.
return;
} else {
throw new IllegalArgumentException("A different view with the same name is already registered: " + existing);
}
}
Measure measure = view.getMeasure();
Measure registeredMeasure = registeredMeasures.get(measure.getName());
if (registeredMeasure != null && !registeredMeasure.equals(measure)) {
throw new IllegalArgumentException("A different measure with the same name is already registered: " + registeredMeasure);
}
registeredViews.put(view.getName(), view);
if (registeredMeasure == null) {
registeredMeasures.put(measure.getName(), measure);
}
Timestamp now = clock.now();
mutableMap.put(view.getMeasure().getName(), MutableViewData.create(view, now));
}
use of io.opencensus.stats.Measure in project instrumentation-java by census-instrumentation.
the class MetricUtils method viewToMetricDescriptor.
@javax.annotation.Nullable
static MetricDescriptor viewToMetricDescriptor(View view) {
if (view.getWindow() instanceof View.AggregationWindow.Interval) {
// Only creates Metric for cumulative stats.
return null;
}
List<LabelKey> labelKeys = new ArrayList<LabelKey>();
for (TagKey tagKey : view.getColumns()) {
// TODO: add description
labelKeys.add(LabelKey.create(tagKey.getName(), ""));
}
Measure measure = view.getMeasure();
Aggregation aggregation = view.getAggregation();
return MetricDescriptor.create(view.getName().asString(), view.getDescription(), getUnit(measure, aggregation), getType(measure, aggregation), labelKeys);
}
use of io.opencensus.stats.Measure in project instrumentation-java by census-instrumentation.
the class StatszZPageHandler method groupViewsByDirectoriesAndGetMeasures.
// Parses view names, creates a tree that represents the directory structure and put each view
// under appropriate directory. Also gets measures from the given views.
// Directories are the namespaces in view name, separated by '/'.
private static void groupViewsByDirectoriesAndGetMeasures(Set<View> views, TreeNode root, Map<String, Measure> measures, Set<View> cachedViews) {
for (View view : views) {
if (cachedViews.contains(view)) {
continue;
}
cachedViews.add(view);
List<String> dirs = PATH_SPLITTER.splitToList(view.getName().asString());
TreeNode node = root;
for (int i = 0; i < dirs.size(); i++) {
if (node == null) {
// Should never happen. Work around the nullness checker.
break;
}
String dir = dirs.get(i);
if ("".equals(dir) && i == 0) {
// In case view name starts with a '/'.
continue;
}
node.views++;
if (i != dirs.size() - 1) {
// Non-leaf node (directory node)
node.children.putIfAbsent(dir, new TreeNode());
node = node.children.get(dir);
} else {
// Leaf node (view node)
node.children.putIfAbsent(dir, new TreeNode(view.getName()));
}
}
Measure measure = view.getMeasure();
measures.putIfAbsent(measure.getName(), measure);
}
}
use of io.opencensus.stats.Measure in project instrumentation-java by census-instrumentation.
the class MeasureToViewMap method record.
// Records stats with a set of tags.
synchronized void record(TagContext tags, MeasureMapInternal stats, Timestamp timestamp) {
Iterator<Measurement> iterator = stats.iterator();
Map<String, AttachmentValue> attachments = stats.getAttachments();
while (iterator.hasNext()) {
Measurement measurement = iterator.next();
Measure measure = measurement.getMeasure();
if (!measure.equals(registeredMeasures.get(measure.getName()))) {
// unregistered measures will be ignored.
continue;
}
Collection<MutableViewData> viewDataCollection = mutableMap.get(measure.getName());
for (MutableViewData viewData : viewDataCollection) {
viewData.record(tags, RecordUtils.getDoubleValueFromMeasurement(measurement), timestamp, attachments);
}
}
}
use of io.opencensus.stats.Measure in project ignite by apache.
the class OpenCensusMetricExporterSpi method createMeasure.
/**
*/
private Measure createMeasure(Metric m, Function<Metric, Measure> factory) {
Measure msr = factory.apply(m);
addView(msr);
return msr;
}
Aggregations