0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

🎉 Add jetty metrics.

This commit is contained in:
Andrey Antukh 2021-01-19 14:45:49 +01:00 committed by Alonso Torres
parent d8ee07d1e4
commit 34e5e5c513
4 changed files with 38 additions and 16 deletions

View file

@ -21,6 +21,9 @@
io.prometheus/simpleclient {:mvn/version "0.9.0"} io.prometheus/simpleclient {:mvn/version "0.9.0"}
io.prometheus/simpleclient_hotspot {:mvn/version "0.9.0"} io.prometheus/simpleclient_hotspot {:mvn/version "0.9.0"}
io.prometheus/simpleclient_jetty {:mvn/version "0.9.0"
:exclusions [org.eclipse.jetty/jetty-server
org.eclipse.jetty/jetty-servlet]}
io.prometheus/simpleclient_httpserver {:mvn/version "0.9.0"} io.prometheus/simpleclient_httpserver {:mvn/version "0.9.0"}
selmer/selmer {:mvn/version "1.12.31"} selmer/selmer {:mvn/version "1.12.31"}

View file

@ -23,7 +23,10 @@
[reitit.ring :as rr] [reitit.ring :as rr]
[ring.adapter.jetty9 :as jetty]) [ring.adapter.jetty9 :as jetty])
(:import (:import
org.eclipse.jetty.server.handler.ErrorHandler)) org.eclipse.jetty.server.Server
org.eclipse.jetty.server.Handler
org.eclipse.jetty.server.handler.ErrorHandler
org.eclipse.jetty.server.handler.StatisticsHandler))
(s/def ::handler fn?) (s/def ::handler fn?)
(s/def ::ws (s/map-of ::us/string fn?)) (s/def ::ws (s/map-of ::us/string fn?))
@ -31,7 +34,7 @@
(s/def ::name ::us/string) (s/def ::name ::us/string)
(defmethod ig/pre-init-spec ::server [_] (defmethod ig/pre-init-spec ::server [_]
(s/keys :req-un [::handler ::port] (s/keys :req-un [::handler ::port ::mtx/metrics]
:opt-un [::ws ::name])) :opt-un [::ws ::name]))
(defmethod ig/prep-key ::server (defmethod ig/prep-key ::server
@ -40,28 +43,34 @@
(d/without-nils cfg))) (d/without-nils cfg)))
(defmethod ig/init-key ::server (defmethod ig/init-key ::server
[_ {:keys [handler ws port name] :as opts}] [_ {:keys [handler ws port name metrics] :as opts}]
(log/infof "Starting %s server on port %s." name port) (log/infof "Starting %s server on port %s." name port)
(let [options (merge (let [pre-start (fn [^Server server]
{:port port (let [handler (doto (ErrorHandler.)
:h2c? true (.setShowStacks true)
:join? false (.setServer server))
:allow-null-path-info true} stats (new StatisticsHandler)]
(when (seq ws) (.setHandler ^StatisticsHandler stats (.getHandler server))
{:websockets ws})) (.setHandler server stats)
server (jetty/run-jetty handler options) (.setErrorHandler server ^ErrorHandler handler)
handler (doto (ErrorHandler.) (mtx/instrument-jetty! (:registry metrics) stats)))
(.setShowStacks true)
(.setServer server))]
(.setErrorHandler server handler) options (merge
{:port port
:h2c? true
:join? false
:allow-null-path-info true
:configurator pre-start}
(when (seq ws)
{:websockets ws}))
server (jetty/run-jetty handler options)]
(assoc opts :server server))) (assoc opts :server server)))
(defmethod ig/halt-key! ::server (defmethod ig/halt-key! ::server
[_ {:keys [server name port] :as opts}] [_ {:keys [server name port] :as opts}]
(log/infof "Stoping %s server on port %s." name port) (log/infof "Stoping %s server on port %s." name port)
(.stop server)) (jetty/stop-server server))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Http Main Handler (Router) ;; Http Main Handler (Router)

View file

@ -69,6 +69,7 @@
:app.http/server :app.http/server
{:port (:http-server-port config) {:port (:http-server-port config)
:handler (ig/ref :app.http/router) :handler (ig/ref :app.http/router)
:metrics (ig/ref :app.metrics/metrics)
:ws {"/ws/notifications" (ig/ref :app.notifications/handler)}} :ws {"/ws/notifications" (ig/ref :app.notifications/handler)}}
:app.http/router :app.http/router

View file

@ -24,6 +24,8 @@
io.prometheus.client.Summary io.prometheus.client.Summary
io.prometheus.client.exporter.common.TextFormat io.prometheus.client.exporter.common.TextFormat
io.prometheus.client.hotspot.DefaultExports io.prometheus.client.hotspot.DefaultExports
io.prometheus.client.jetty.JettyStatisticsCollector
org.eclipse.jetty.server.handler.StatisticsHandler
java.io.StringWriter)) java.io.StringWriter))
(declare instrument-vars!) (declare instrument-vars!)
@ -228,3 +230,10 @@
:else :else
(ex/raise :type :not-implemented)))) (ex/raise :type :not-implemented))))
(defn instrument-jetty!
[^CollectorRegistry registry ^StatisticsHandler handler]
(doto (JettyStatisticsCollector. handler)
(.register registry))
nil)