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:
parent
d8ee07d1e4
commit
34e5e5c513
4 changed files with 38 additions and 16 deletions
|
@ -21,6 +21,9 @@
|
|||
|
||||
io.prometheus/simpleclient {: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"}
|
||||
|
||||
selmer/selmer {:mvn/version "1.12.31"}
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
[reitit.ring :as rr]
|
||||
[ring.adapter.jetty9 :as jetty])
|
||||
(: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 ::ws (s/map-of ::us/string fn?))
|
||||
|
@ -31,7 +34,7 @@
|
|||
(s/def ::name ::us/string)
|
||||
|
||||
(defmethod ig/pre-init-spec ::server [_]
|
||||
(s/keys :req-un [::handler ::port]
|
||||
(s/keys :req-un [::handler ::port ::mtx/metrics]
|
||||
:opt-un [::ws ::name]))
|
||||
|
||||
(defmethod ig/prep-key ::server
|
||||
|
@ -40,28 +43,34 @@
|
|||
(d/without-nils cfg)))
|
||||
|
||||
(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)
|
||||
(let [options (merge
|
||||
{:port port
|
||||
:h2c? true
|
||||
:join? false
|
||||
:allow-null-path-info true}
|
||||
(when (seq ws)
|
||||
{:websockets ws}))
|
||||
server (jetty/run-jetty handler options)
|
||||
handler (doto (ErrorHandler.)
|
||||
(.setShowStacks true)
|
||||
(.setServer server))]
|
||||
(let [pre-start (fn [^Server server]
|
||||
(let [handler (doto (ErrorHandler.)
|
||||
(.setShowStacks true)
|
||||
(.setServer server))
|
||||
stats (new StatisticsHandler)]
|
||||
(.setHandler ^StatisticsHandler stats (.getHandler server))
|
||||
(.setHandler server stats)
|
||||
(.setErrorHandler server ^ErrorHandler handler)
|
||||
(mtx/instrument-jetty! (:registry metrics) stats)))
|
||||
|
||||
(.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)))
|
||||
|
||||
(defmethod ig/halt-key! ::server
|
||||
[_ {:keys [server name port] :as opts}]
|
||||
(log/infof "Stoping %s server on port %s." name port)
|
||||
(.stop server))
|
||||
(jetty/stop-server server))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Http Main Handler (Router)
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
:app.http/server
|
||||
{:port (:http-server-port config)
|
||||
:handler (ig/ref :app.http/router)
|
||||
:metrics (ig/ref :app.metrics/metrics)
|
||||
:ws {"/ws/notifications" (ig/ref :app.notifications/handler)}}
|
||||
|
||||
:app.http/router
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
io.prometheus.client.Summary
|
||||
io.prometheus.client.exporter.common.TextFormat
|
||||
io.prometheus.client.hotspot.DefaultExports
|
||||
io.prometheus.client.jetty.JettyStatisticsCollector
|
||||
org.eclipse.jetty.server.handler.StatisticsHandler
|
||||
java.io.StringWriter))
|
||||
|
||||
(declare instrument-vars!)
|
||||
|
@ -228,3 +230,10 @@
|
|||
|
||||
:else
|
||||
(ex/raise :type :not-implemented))))
|
||||
|
||||
(defn instrument-jetty!
|
||||
[^CollectorRegistry registry ^StatisticsHandler handler]
|
||||
(doto (JettyStatisticsCollector. handler)
|
||||
(.register registry))
|
||||
nil)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue