id | title | sidebar_label |
---|---|---|
functions-metrics |
Metrics for Pulsar Functions |
Metrics |
Pulsar Functions can publish arbitrary metrics to the metrics interface which can then be queried. This doc contains instructions for publishing metrics using the Java and Python Pulsar Functions SDKs.
If a Pulsar Function uses the language-native interface for Java or Python, that function will not be able to publish metrics and stats to Pulsar.
For a guide to accessing metrics created by Pulsar Functions, see the guide to Monitoring in Pulsar.
If you're creating a Pulsar Function using the Java SDK, the {@inject: javadoc:Context:/pulsar-functions/org/apache/pulsar/functions/api/Context} object has a recordMetric
method that you can use to register both a name for the metric and a value. Here's the signature for that method:
void recordMetric(String metricName, double value);
Here's an example function:
import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.api.Function;
public class MetricRecordingFunction implements Function<String, Void> {
@Override
public void apply(String input, Context context) {
context.recordMetric("number-of-characters", input.length());
return null;
}
}
This function counts the length of each incoming message (of type String
) and then registers that under the number-of-characters
metric.
Documentation for the Python SDK is coming soon.