Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose JVM metrics with Prometheus inline exporter #67

Open
piotr-yuxuan opened this issue May 29, 2021 · 3 comments
Open

Expose JVM metrics with Prometheus inline exporter #67

piotr-yuxuan opened this issue May 29, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@piotr-yuxuan
Copy link
Contributor

piotr-yuxuan commented May 29, 2021

Hello, thanks for this nice project! I've been stumbling upon one exception, and one unexpected behaviour while trying to expose JVM metrics to Prometheus scrapper:

(ns piotr-yuxuan.mulog-expose-kafka-publisher
  (:require [com.brunobonacci.mulog :as mulog]
            [com.brunobonacci.mulog.publishers.prometheus :as prom]))

(def pub
  (prom/prometheus-publisher {:type :prometheus}))

(def px
  (mulog/start-publisher! {:type :inline :publisher pub}))

(prom/registry pub)
;; Execution error (ClassCastException) at com.brunobonacci.mulog.publishers.prometheus.PrometheusPublisher/registry (prometheus.clj:226).
;; class io.prometheus.client.CollectorRegistry cannot be cast to class clojure.lang.IFn (io.prometheus.client.CollectorRegistry and clojure.lang.IFn are in unnamed module of loader 'app')

(prom/write-str pub)
;; => ""

(mulog/log "event-name" :a "a" :b "b")

(prom/write-str pub)
;; => "# HELP piotr_yuxuan_mulog_expose_kafka_publisher_event_name Counter of piotr-yuxuan.mulog-expose-kafka-publisher/\"event-name\" events.
;;     # TYPE piotr_yuxuan_mulog_expose_kafka_publisher_event_name counter
;;     piotr_yuxuan_mulog_expose_kafka_publisher_event_name{a=\"a\",b=\"b\",} 1.0
;;     "

(def jvm-pub
  (mulog/start-publisher! {:type :jvm-metrics
                           ;; the interval in millis between two samples (default: 60s)
                           :sampling-interval 100
                           :jvm-metrics {:memory true
                                         :gc true
                                         :threads true
                                         :jvm-attrs true}}))

(prom/write-str pub)
;; => "# HELP clojure_core_mulog_jvm_metrics_sampled Counter of clojure.core/:mulog/jvm-metrics-sampled events.
;;     # TYPE clojure_core_mulog_jvm_metrics_sampled counter
;;     clojure_core_mulog_jvm_metrics_sampled 113.0
;;     # HELP piotr_yuxuan_mulog_expose_kafka_publisher_event_name Counter of piotr-yuxuan.mulog-expose-kafka-publisher/\"event-name\" events.
;;     # TYPE piotr_yuxuan_mulog_expose_kafka_publisher_event_name counter
;;     piotr_yuxuan_mulog_expose_kafka_publisher_event_name{a=\"a\",b=\"b\",} 1.0
;;     "

So far the counter clojure_core_mulog_jvm_metrics_sampled increases, but no further metrics are exposed. I think this snippet is pretty close to the doc so I'm a bit puzzled.

On my machine this behaviour appeared consistent accross versions 0.5.0, 0.6.0, 0.7.0, and 0.7.1.

piotr-yuxuan added a commit to piotr-yuxuan/mulog that referenced this issue May 29, 2021
Attempt at avoiding the exception reported here: BrunoBonacci#67 (comment)
piotr-yuxuan added a commit to piotr-yuxuan/mulog that referenced this issue May 29, 2021
Attempt at avoiding the exception reported here: BrunoBonacci#67 (comment)
BrunoBonacci pushed a commit that referenced this issue Jun 8, 2021
* Rename variable that shadows type fn

Attempt at avoiding the exception reported here: #67 (comment)

* Better name for collector-registry

Co-authored-by: piotr-yuxuan <piotr-yuxuan@users.noreply.github.com>
@BrunoBonacci
Copy link
Owner

This issue if fixed (thanks @piotr-yuxuan) it will be released with the next release (v0.7.2 or v0.8.0)

@BrunoBonacci
Copy link
Owner

Reopening as this issue needs more work.

@BrunoBonacci BrunoBonacci self-assigned this Jun 8, 2021
@BrunoBonacci BrunoBonacci added the enhancement New feature or request label Jun 8, 2021
@BrunoBonacci
Copy link
Owner

Currently the μ/log Prometheus publisher converts events into metrics by creating a new metrics for every numerical value.
It uses string values as labels. However, it only looks at numerical values on the top-level event map, it doesn't nest.

See here:
https://github.com/brunobonacci/mulog/blob/master/mulog-prometheus/src/com/brunobonacci/mulog/publishers/prometheus/metrics.clj#L70

One option/workaround is to add a :transform function on your
Prometheus publisher to copy the metrics you are interested into
publishing on the top level.

If you want all metrics you will need to "flatten" a nested map while
preserving the names.

I will think whether this could be something that it is done
automatically by μ/log publisher. My worry is that this might cause an
explosion of metrics to be published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants