SatwikBhandiwad commented on a change in pull request #3257: NIFI-5435 
Prometheus /metrics http endpoint for monitoring integration
URL: https://github.com/apache/nifi/pull/3257#discussion_r288664013
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-prometheus-bundle/nifi-prometheus-reporting-task/src/main/java/org/apache/nifi/reporting/prometheus/PrometheusServer.java
 ##########
 @@ -0,0 +1,168 @@
+/*
+ * 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.nifi.reporting.prometheus;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.nifi.controller.status.ProcessGroupStatus;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.reporting.ReportingContext;
+import org.apache.nifi.reporting.prometheus.api.PrometheusMetricsUtil;
+import org.apache.nifi.ssl.SSLContextService;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.SecureRequestCustomizer;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.SslConnectionFactory;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+import com.yammer.metrics.core.VirtualMachineMetrics;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.exporter.common.TextFormat;
+
+public class PrometheusServer {
+    private static ComponentLog logger;
+    private Server server;
+    private ServletContextHandler handler;
+    private ReportingContext context;
+    private boolean sendJvmMetrics;
+    private String instanceId;
+
+    class MetricsServlet extends HttpServlet {
+        private CollectorRegistry nifiRegistry, jvmRegistry;
+        private ProcessGroupStatus rootGroupStatus;
+
+        @Override
+        protected void doGet(final HttpServletRequest req, final 
HttpServletResponse resp) throws ServletException, IOException {
+            logger.info("PrometheusServer Do get called");
+
+            rootGroupStatus = 
PrometheusServer.this.context.getEventAccess().getControllerStatus();
+            ServletOutputStream response = resp.getOutputStream();
+            OutputStreamWriter osw = new OutputStreamWriter(response);
+            nifiRegistry = 
PrometheusMetricsUtil.createNifiMetrics(rootGroupStatus, 
PrometheusServer.this.instanceId);
 
 Review comment:
   Thanks @mattyb149  for reviewing. I've made the suugested changes by adding 
process_group_name  and process_group_id labels to metrics , also changed 
logger to debug level.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to