hyperscaledesignhub commented on code in PR #8:
URL: https://github.com/apache/fluss-benchmarks/pull/8#discussion_r3412977378


##########
e2e-iot/fluss_flink_realtime/src/main/java/org/apache/fluss/benchmark/e2eplatformaws/producer/ProducerMetrics.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.fluss.benchmark.e2eplatformaws.producer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
+
+import com.sun.net.httpserver.HttpServer;
+
+/**
+ * Simple Prometheus metrics server for the producer.
+ * Exposes metrics on port 8080 at /metrics endpoint.
+ */
+public class ProducerMetrics {
+    private static final Logger LOG = 
LoggerFactory.getLogger(ProducerMetrics.class);
+    
+    private final LongAdder totalRecords = new LongAdder();
+    private final AtomicLong startTime = new 
AtomicLong(System.currentTimeMillis());
+    private final AtomicLong lastStatsTime = new 
AtomicLong(System.currentTimeMillis());
+    private final AtomicLong lastStatsRecords = new AtomicLong(0);
+    
+    private HttpServer server;
+    private final int port;
+    
+    public ProducerMetrics(int port) {
+        this.port = port;
+    }
+    
+    public void start() throws IOException {
+        // Bind to 0.0.0.0 to make it accessible from outside the container
+        server = HttpServer.create(new InetSocketAddress("0.0.0.0", port), 0);
+        server.createContext("/metrics", this::handleMetrics);
+        server.setExecutor(null); // Use default executor
+        server.start();
+        LOG.info("Producer metrics server started on port {} (bound to 
0.0.0.0)", port);
+    }
+    
+    public void stop() {
+        if (server != null) {
+            server.stop(0);
+            LOG.info("Producer metrics server stopped");
+        }
+    }
+    
+    public void recordWrite() {
+        totalRecords.increment();
+    }
+    
+    public void updateStats(long records) {
+        lastStatsRecords.set(records);
+        lastStatsTime.set(System.currentTimeMillis());
+    }
+    
+    private void handleMetrics(com.sun.net.httpserver.HttpExchange exchange) 
throws IOException {
+        long currentTime = System.currentTimeMillis();
+        long total = totalRecords.sum();
+        long elapsedSeconds = (currentTime - startTime.get()) / 1000;
+        long windowRecords = lastStatsRecords.get();

Review Comment:
   Changed code to use delta count by subtracting total records at this point 
from last updated records. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to