You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/03/13 06:16:23 UTC

[GitHub] srkukarni commented on a change in pull request #1373: Functions metrics prometheus

srkukarni commented on a change in pull request #1373: Functions metrics prometheus
URL: https://github.com/apache/incubator-pulsar/pull/1373#discussion_r174025115
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/FunctionsStatsGenerator.java
 ##########
 @@ -0,0 +1,78 @@
+package org.apache.pulsar.broker.stats.prometheus;
+
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.functions.proto.InstanceCommunication;
+import org.apache.pulsar.functions.runtime.Runtime;
+import org.apache.pulsar.functions.runtime.RuntimeSpawner;
+import org.apache.pulsar.functions.worker.FunctionRuntimeInfo;
+import org.apache.pulsar.utils.SimpleTextOutputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * A class to generate stats for pulsar functions running on this broker
+ */
+public class FunctionsStatsGenerator {
+
+    private static final Logger log = LoggerFactory.getLogger(FunctionsStatsGenerator.class);
+
+    public static void generate(PulsarService pulsar, SimpleTextOutputStream out) {
+        if (pulsar.getWorkerService() != null) {
+            Map<String, FunctionRuntimeInfo> functionRuntimes
+                    = pulsar.getWorkerService().getFunctionRuntimeManager().getFunctionRuntimeInfos();
+            String cluster = pulsar.getConfiguration().getClusterName();
+
+            for (Map.Entry<String, FunctionRuntimeInfo> entry : functionRuntimes.entrySet()) {
+                String fullyQualifiedInstanceName = entry.getKey();
+                FunctionRuntimeInfo functionRuntimeInfo = entry.getValue();
+                RuntimeSpawner functionRuntimeSpawner = functionRuntimeInfo.getRuntimeSpawner();
+
+                if (functionRuntimeSpawner != null) {
+                    Runtime functionRuntime = functionRuntimeSpawner.getRuntime();
+                    if (functionRuntime != null) {
+                        try {
+                            InstanceCommunication.MetricsData metrics = functionRuntime.getAndResetMetrics().get();
+                            for (Map.Entry<String, InstanceCommunication.MetricsData.DataDigest> metricsEntry
+                                    : metrics.getMetricsMap().entrySet()) {
+                                String metricName = metricsEntry.getKey();
+                                InstanceCommunication.MetricsData.DataDigest dataDigest = metricsEntry.getValue();
+
+                                String tenant = functionRuntimeInfo.getFunctionInstance()
+                                        .getFunctionMetaData().getFunctionConfig().getTenant();
+                                String namespace = functionRuntimeInfo.getFunctionInstance()
+                                        .getFunctionMetaData().getFunctionConfig().getNamespace();
+                                String name = functionRuntimeInfo.getFunctionInstance()
+                                        .getFunctionMetaData().getFunctionConfig().getName();
+                                int instanceId = functionRuntimeInfo.getFunctionInstance().getInstanceId();
+                                String qualifiedNamespace = String.format("%s/%s", tenant, namespace);
+
+                                metric(out, cluster, qualifiedNamespace, name, String.format("pulsar_function%scount", metricName),
 
 Review comment:
   maybe _ before count

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services