turboFei commented on code in PR #6863: URL: https://github.com/apache/kyuubi/pull/6863#discussion_r1897132123
########## kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/PrometheusReporterService.scala: ########## @@ -100,4 +100,90 @@ class PrometheusReporterService(registry: MetricRegistry) } } } + + private def createPrometheusServlet(): HttpServlet = { + new HttpServlet { + override def doGet(request: HttpServletRequest, response: HttpServletResponse): Unit = { + try { + response.setContentType("text/plain;charset=utf-8") + response.setStatus(HttpServletResponse.SC_OK) + response.getWriter.print(getMetricsSnapshot()) + } catch { + case e: IllegalArgumentException => + response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage) + case e: Exception => + warn(s"GET ${request.getRequestURI} failed: $e", e) + throw e + } + } + // ensure TRACE is not supported + override protected def doTrace(req: HttpServletRequest, res: HttpServletResponse): Unit = { + res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED) + } + } + } + + private def getMetricsSnapshot(): String = { + import scala.collection.JavaConverters._ + + val gaugesLabel = s"""{type="gauges",$instanceLabel}""" + val countersLabel = s"""{type="counters",$instanceLabel}""" + val metersLabel = countersLabel + val histogramslabels = s"""{type="histograms",$instanceLabel}""" + val timersLabels = s"""{type="timers",$instanceLabel}""" + + val sb = new StringBuilder() + registry.getGauges.asScala.foreach { case (k, v) => + if (!v.getValue.isInstanceOf[String]) { + sb.append(s"${normalizeKey(k)}$gaugesLabel ${v.getValue}\n") Review Comment: Gauge example before: ``` # TYPE kyuubi_connection_total_hermesrno_b_brisk gauge kyuubi_connection_total_hermesrno_b_brisk 414.0 ``` -- 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: notifications-unsubscr...@kyuubi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@kyuubi.apache.org For additional commands, e-mail: notifications-h...@kyuubi.apache.org