turboFei commented on code in PR #6863:
URL: https://github.com/apache/kyuubi/pull/6863#discussion_r1897132509
##########
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")
+ }
+ }
+ registry.getCounters.asScala.foreach { case (k, v) =>
+ sb.append(s"${normalizeKey(k)}$countersLabel ${v.getCount}\n")
Review Comment:
Gauge and counter example
```
# HELP kyuubi_connection_opened_b_citrst Generated from Dropwizard metric
import (metric=kyuubi.connection.opened.b_citrst,
type=com.codahale.metrics.Counter)
# TYPE kyuubi_connection_opened_b_citrst gauge
kyuubi_connection_opened_b_citrst 0.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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]