Comments (1)
This is how I currently implemented this:
Add the dependencies to project.clj
or equivalent project file:
[iapetos "0.1.8"]
;; bump the versions of the io.prometheus libs
[io.prometheus/simpleclient "0.9.0"]
[io.prometheus/simpleclient_common "0.9.0"]
[io.prometheus/simpleclient_hotspot "0.9.0"]
[io.prometheus/simpleclient_pushgateway "0.9.0"]
;; iapetos does not include this currently.
[io.prometheus/simpleclient_jetty "0.9.0" :exclusions [org.eclipse.jetty/jetty-server
org.eclipse.jetty/jetty-servlet]]
(require '[iapetos.core :as prometheus]])
(import [io.prometheus.client Collector$MetricFamilySamples])
(import [org.eclipse.jetty.server.handler StatisticsHandler])
(import [io.prometheus.client.jetty JettyStatisticsCollector])
(defn- metric-family-samples->metric
[^io.prometheus.client.Collector v ^Collector$MetricFamilySamples s]
(if-let [n (.name s)]
(let [[a b] (.split n "_" 2)]
(if b
{:name b, :namespace a}
{:name a, :namespace "raw"}))
{:name (str (.getSimpleName (class v)) "_" (hash v))
:namespace "raw"}));
(defonce jetty-statistics-handler (delay (StatisticsHandler.)))
(defn wrap-jetty-statistics
"Replaces the handler configured on the given jetty server with a handler wrapped by the jetty statistics handler, returns the server."
[^org.eclipse.jetty.server.Server server]
(let [existing-handler (.getHandler server)]
(.setHandler @jetty-statistics-handler existing-handler)
(.setHandler server @jetty-statistics-handler)
server))
(defn- jetty-initialise [registry]
(let [collector (JettyStatisticsCollector. @jetty-statistics-handler)
metricFamilySamples (.collect collector)]
(doseq [sample metricFamilySamples]
(prometheus/register registry (reify iapetos.collector.Collector
(instantiate [_ _]
collector)
(metric [this]
(metric-family-samples->metric collector sample))
(label-instance [_ instance values]
(if-not (empty? values)
(throw (UnsupportedOperationException.))
instance)))))
registry))
(defonce registry
(-> (prometheus/collector-registry)
(jetty-initialise)))
;; start your server
(require '[ring.adapter.jetty :refer [run-jetty]])
(defn start-server []
(run-jetty app {:configurator (fn [server]
(-> server
wrap-jetty-statistics))
:port 8080
:join? false})
)
For reference, this currently exposes the following metrics:
jetty_requests_total
jetty_requests_active
jetty_requests_active_max
jetty_request_time_max_seconds
jetty_request_time_seconds_total
jetty_dispatched_total
jetty_dispatched_active
jetty_dispatched_active_max
jetty_dispatched_time_max
jetty_dispatched_time_seconds_total
jetty_async_requests_total
jetty_async_requests_waiting
jetty_async_requests_waiting_max
jetty_async_dispatches_total
jetty_expires_total
jetty_responses_total{code="1xx",}
jetty_responses_total{code="2xx",}
jetty_responses_total{code="3xx",}
jetty_responses_total{code="4xx",}
jetty_responses_total{code="5xx",}
jetty_stats_seconds
jetty_responses_bytes_total
There's probably some improvements to avoid re-defining the Collector -> metric mapping and some other improvements (I'm still relatively new to Clojure).
I'd like to add this to iapetos directly but may not have time to put a PR together anytime soon.
from iapetos.
Related Issues (20)
- choose where to publish jars HOT 4
- openjdk 11 doesn't work on travis. HOT 3
- investigate about codecoverage migration HOT 2
- Recreate changelog
- Upstream doc HOT 1
- index documentatoin of readme HOT 2
- fix clidoc badge HOT 1
- jvm collector broke HOT 5
- Allow fn instrument and wrap-instrumentation to take labels HOT 1
- Add optional exception label to with-duration
- get a release version `0.1.10` HOT 1
- thrown exceptions are not reported to the HTTP counter on ring collector HOT 1
- Expose ring internal functions
- Remove `dec` function HOT 1
- Support "Info" metrics HOT 2
- Trying to add the labels for JVM metrics HOT 1
- Trying to modify buckets for existing http_request_latency_seconds_bucket HOT 1
- Missing with-activity-counter for percentage; variable `inc`/`dec`
- Migrate to 1.0.0 library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iapetos.