You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/09/28 07:16:45 UTC
[incubator-eventmesh] branch master updated: add grpc metrics exporter
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new dca42d03 add grpc metrics exporter
new b50f3a98 Merge pull request #1447 from horoc/add-grpc-metrics-branch
dca42d03 is described below
commit dca42d0352c770e3b6100232b3372b7d516d94ce
Author: horoc <ho...@gmail.com>
AuthorDate: Tue Sep 27 21:13:05 2022 +0800
add grpc metrics exporter
---
.../prometheus/PrometheusMetricsRegistry.java | 6 +++
.../prometheus/metrics/PrometheusGrpcExporter.java | 56 ++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/PrometheusMetricsRegistry.java b/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/PrometheusMetricsRegistry.java
index d96a07b9..60e5d587 100644
--- a/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/PrometheusMetricsRegistry.java
+++ b/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/PrometheusMetricsRegistry.java
@@ -18,10 +18,12 @@
package org.apache.eventmesh.metrics.prometheus;
import org.apache.eventmesh.metrics.api.MetricsRegistry;
+import org.apache.eventmesh.metrics.api.model.GrpcSummaryMetrics;
import org.apache.eventmesh.metrics.api.model.HttpSummaryMetrics;
import org.apache.eventmesh.metrics.api.model.Metric;
import org.apache.eventmesh.metrics.api.model.TcpSummaryMetrics;
import org.apache.eventmesh.metrics.prometheus.config.PrometheusConfiguration;
+import org.apache.eventmesh.metrics.prometheus.metrics.PrometheusGrpcExporter;
import org.apache.eventmesh.metrics.prometheus.metrics.PrometheusHttpExporter;
import org.apache.eventmesh.metrics.prometheus.metrics.PrometheusTcpExporter;
@@ -78,6 +80,10 @@ public class PrometheusMetricsRegistry implements MetricsRegistry {
if (metric instanceof TcpSummaryMetrics) {
PrometheusTcpExporter.export("apache-eventmesh", (TcpSummaryMetrics) metric);
}
+
+ if (metric instanceof GrpcSummaryMetrics) {
+ PrometheusGrpcExporter.export("apache-eventmesh", (GrpcSummaryMetrics) metric);
+ }
}
@Override
diff --git a/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/metrics/PrometheusGrpcExporter.java b/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/metrics/PrometheusGrpcExporter.java
new file mode 100644
index 00000000..a99da83b
--- /dev/null
+++ b/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/metrics/PrometheusGrpcExporter.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.metrics.prometheus.metrics;
+
+import org.apache.eventmesh.metrics.api.model.GrpcSummaryMetrics;
+
+import java.util.function.Supplier;
+
+import io.opentelemetry.api.metrics.GlobalMeterProvider;
+import io.opentelemetry.api.metrics.Meter;
+import io.opentelemetry.api.metrics.common.Labels;
+
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+public class PrometheusGrpcExporter {
+
+ private static final String UNIT = "GRPC";
+ private static final String METRICS_NAME_PREFIX = "eventmesh.grpc.";
+
+ private void observeOfValue(Meter meter, String name, String desc, Supplier<Long> supplier) {
+ meter.doubleValueObserverBuilder(METRICS_NAME_PREFIX + name)
+ .setDescription(desc)
+ .setUnit(UNIT)
+ .setUpdater(result -> result.observe(supplier.get(), Labels.empty()))
+ .build();
+ }
+
+ public static void export(final String meterName, final GrpcSummaryMetrics summaryMetrics) {
+ final Meter meter = GlobalMeterProvider.getMeter(meterName);
+
+ observeOfValue(meter, "sub.topic.num", "get sub topic num.", summaryMetrics::getSubscribeTopicNum);
+ observeOfValue(meter, "retry.queue.size", "get size of retry queue.", summaryMetrics::getRetrySize);
+
+ observeOfValue(meter, "server.tps", "get size of retry queue.", summaryMetrics::getClient2EventMeshTPS);
+ observeOfValue(meter, "client.tps", "get tps of eventMesh to mq.", summaryMetrics::getEventMesh2ClientTPS);
+
+ observeOfValue(meter, "mq.provider.tps", "get tps of eventMesh to mq.", summaryMetrics::getEventMesh2MqTPS);
+ observeOfValue(meter, "mq.consumer.tps", "get tps of eventMesh to mq.", summaryMetrics::getMq2EventMeshTPS);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org