Search in sources :

Example 1 with Measure

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));
}
Also used : Measure(io.opencensus.stats.Measure) View(io.opencensus.stats.View) Timestamp(io.opencensus.common.Timestamp)

Example 2 with Measure

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);
}
Also used : Aggregation(io.opencensus.stats.Aggregation) ArrayList(java.util.ArrayList) TagKey(io.opencensus.tags.TagKey) Measure(io.opencensus.stats.Measure) LabelKey(io.opencensus.metrics.LabelKey) View(io.opencensus.stats.View)

Example 3 with Measure

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);
    }
}
Also used : Measure(io.opencensus.stats.Measure) View(io.opencensus.stats.View)

Example 4 with 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);
        }
    }
}
Also used : Measurement(io.opencensus.stats.Measurement) AttachmentValue(io.opencensus.metrics.data.AttachmentValue) Measure(io.opencensus.stats.Measure)

Example 5 with Measure

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;
}
Also used : Measure(io.opencensus.stats.Measure)

Aggregations

Measure (io.opencensus.stats.Measure)5 View (io.opencensus.stats.View)3 Timestamp (io.opencensus.common.Timestamp)1 LabelKey (io.opencensus.metrics.LabelKey)1 AttachmentValue (io.opencensus.metrics.data.AttachmentValue)1 Aggregation (io.opencensus.stats.Aggregation)1 Measurement (io.opencensus.stats.Measurement)1 TagKey (io.opencensus.tags.TagKey)1 ArrayList (java.util.ArrayList)1