Prometheus metrics in clojure with dropwizard

(ns metricsaurus-rex.ring.handlers
  (:require [metricsaurus-rex.metrics.snapshot :as snapshot]
            [metricsaurus-rex.healthchecks :as healthchecks]
            [metricsaurus-rex.metrics :as metrics]
            [cheshire.core :as json]
            [cheshire.generate :as generate])


  (:import [io.prometheus.client.dropwizard.DropwizardExports]
            [io.prometheus.client.exporter.common]
            [io.prometheus.client.CollectorRegistry]
            [io.prometheus.client.Collector]
           )

  )

; Return the metrics registry in prometheus format
(defn prometheus-metrics [dwregistry]
  (def cr (io.prometheus.client.CollectorRegistry. ) )
  (.register cr (io.prometheus.client.dropwizard.DropwizardExports. dwregistry))
  (def sw (java.io.StringWriter.))
  (def tf (io.prometheus.client.exporter.common.TextFormat.))
  (. io.prometheus.client.exporter.common.TextFormat (write004 sw  (.metricFamilySamples cr) ))
  (.toString sw)
)

Little snippet that will export Dropwizard metrics in a format that Prometheus can read via clojure.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s