Search in sources :

Example 1 with Metric

use of com.ibm.streams.operator.metrics.Metric in project streamsx.topology by IBMStreams.

the class FunctionOperatorContext method createCustomMetric.

@Override
public synchronized void createCustomMetric(String name, String description, String kind, LongSupplier value) {
    name = requireNonNull(name);
    description = requireNonNull(description);
    LongSupplier supplier = requireNonNull(value);
    Kind ekind = Metric.Kind.valueOf(kind.toUpperCase(Locale.US));
    Metric cm;
    try {
        cm = context.getMetrics().createCustomMetric(name, description, ekind);
    } catch (IllegalArgumentException e) {
        // the new value supplier.
        if (metrics != null) {
            synchronized (metrics) {
                for (MetricSetter ms : metrics) if (ms.metric.getName().equals(name))
                    throw e;
            }
        }
        cm = context.getMetrics().getCustomMetric(name);
    }
    cm.setValue(supplier.getAsLong());
    if (metrics == null) {
        metrics = Collections.synchronizedList(new ArrayList<>());
        metricsGetter = getScheduledExecutorService().scheduleWithFixedDelay(this::updateMetrics, 1, 1, TimeUnit.SECONDS);
    }
    metrics.add(new MetricSetter(cm, value));
}
Also used : Kind(com.ibm.streams.operator.metrics.Metric.Kind) ArrayList(java.util.ArrayList) Metric(com.ibm.streams.operator.metrics.Metric) LongSupplier(java.util.function.LongSupplier)

Example 2 with Metric

use of com.ibm.streams.operator.metrics.Metric in project streamsx.topology by IBMStreams.

the class Resetter method checkRequiredResets.

/**
 * See if the condition has become valid by having
 * executed the minimum number of resets for each region.
 *
 * Once it becomes valid then stop any resetting.
 */
private void checkRequiredResets() {
    if (fail.getValue() != 0 || valid.getValue() != 0)
        return;
    synchronized (resetCounts) {
        for (Metric resetCount : resetCounts) {
            if (resetCount.getValue() < getMinimumResets())
                return;
        }
    }
    if (fail.getValue() == 0) {
        valid.setValue(1);
        // and stop resetting.
        cancelFutures();
    }
}
Also used : Metric(com.ibm.streams.operator.metrics.Metric)

Example 3 with Metric

use of com.ibm.streams.operator.metrics.Metric in project streamsx.topology by IBMStreams.

the class Resetter method setup.

@Override
public void setup(MBeanServerConnection mbs, OperatorContext context) throws InstanceNotFoundException, Exception {
    seq.increment();
    ObjectName consistentWildcard = ObjectName.getInstance("com.ibm.streams.control:type=consistent,index=*");
    Set<ObjectName> regions = mbs.queryNames(consistentWildcard, null);
    if (regions.isEmpty()) {
        fail.setValue(1);
        trace.severe("No consistent regions!");
        return;
    }
    for (ObjectName name : regions) {
        ConsistentRegionMXBean crbean = JMX.newMXBeanProxy(mbs, name, ConsistentRegionMXBean.class, true);
        if (trace.isLoggable(Level.FINE))
            trace.fine("Discovered consistent region: " + crbean.getName());
        String metricName = "nResets." + crbean.getName();
        Metric resetCount;
        try {
            resetCount = context.getMetrics().createCustomMetric(metricName, "Requested resets for region", Metric.Kind.COUNTER);
        } catch (IllegalArgumentException e) {
            resetCount = context.getMetrics().getCustomMetric(metricName);
        }
        resetCounts.add(resetCount);
        scheduleReset(crbean, resetCount);
        seq.increment();
    }
}
Also used : Metric(com.ibm.streams.operator.metrics.Metric) ConsistentRegionMXBean(com.ibm.streams.operator.control.ConsistentRegionMXBean) ObjectName(javax.management.ObjectName)

Example 4 with Metric

use of com.ibm.streams.operator.metrics.Metric in project streamsx.topology by IBMStreams.

the class Resetter method initialize.

@Override
public synchronized void initialize(OperatorContext context) throws Exception {
    super.initialize(context);
    createConditionMetrics();
    Metric mrm = getOperatorContext().getMetrics().createCustomMetric("nMinimumResets", "Minimum number of resets per channel", Metric.Kind.COUNTER);
    mrm.setValue(getMinimumResets());
    ControlPlaneContext control = context.getOptionalContext(ControlPlaneContext.class);
    control.connect(this);
}
Also used : ControlPlaneContext(com.ibm.streams.operator.control.ControlPlaneContext) Metric(com.ibm.streams.operator.metrics.Metric)

Example 5 with Metric

use of com.ibm.streams.operator.metrics.Metric in project streamsx.kafka by IBMStreams.

the class AbstractKafkaClient method tryCreateCustomMetric.

/**
 * Tests existence of a custom metric and creates the metric if it does not yet exist.
 * @param name  the name of the metric
 * @param descr the description
 * @param kind  the kind of the metric
 * @return the Metric object.
 */
protected Metric tryCreateCustomMetric(final String name, final String descr, final Metric.Kind kind) {
    OperatorMetrics metrics = getOperatorContext().getMetrics();
    Metric m = metrics.getCustomMetrics().get(name.trim());
    if (m != null)
        return m;
    return metrics.createCustomMetric(name, descr, kind);
}
Also used : OperatorMetrics(com.ibm.streams.operator.metrics.OperatorMetrics) Metric(com.ibm.streams.operator.metrics.Metric)

Aggregations

Metric (com.ibm.streams.operator.metrics.Metric)5 ConsistentRegionMXBean (com.ibm.streams.operator.control.ConsistentRegionMXBean)1 ControlPlaneContext (com.ibm.streams.operator.control.ControlPlaneContext)1 Kind (com.ibm.streams.operator.metrics.Metric.Kind)1 OperatorMetrics (com.ibm.streams.operator.metrics.OperatorMetrics)1 ArrayList (java.util.ArrayList)1 LongSupplier (java.util.function.LongSupplier)1 ObjectName (javax.management.ObjectName)1