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));
}
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();
}
}
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();
}
}
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);
}
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);
}
Aggregations