Skip to content

Clojure wrapper for Micrometer - vendor-neutral application observability facade, allowing you to instrument your JVM-based application code without vendor lock-in.

Notifications You must be signed in to change notification settings

oscaro/macrometer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

macrometer Clojure Umbrella Clojars Project Clojars Project Clojars Project

Clojure wrapper for http://micrometer.io/

Usage

Counters report a single metric, a count. The Counter interface allows you to increment by a fixed amount, which must be positive.

(require '[macrometer.counters :as c])

(c/defcounter a-counter
  :tags {:a "a" :b "b"}
  :description "A counter for something")

;(def a-counter (c/counter "a.counter" 
;                          :tags {:a "a" :b "b"}
;                          :description "A counter for something")) 
  
(c/increment a-counter)
(c/count a-counter)
; => 1.0

A gauge is a handle to get the current value. Typical examples for gauges would be the size of a collection or map or number of threads in a running state.

Never gauge something you can count with a Counter!

Reference tracking gauges

For atoms, AtomicLongs and other immutable Numbers etc...

(require '[macrometer.gauges :as g])

(let [a (atom 0)
      g (g/gauge "ext.gauge" a)]
  (swap! a + 10)
  (g/value g))
; => 10.0
Function gauges
; A random walking gauge ;)
(g/gauge "fn.gauge" (partial rand-int 100) :tags {:app "clio"})

Timers report short-duration latencies and the frequency of such events. This is useful for tracking http calls for instance.

(require '[macrometer.timers :as t])

(t/deftimer a-timer
  :tags {:a "a" :b "b"}
  :description "A timer for something")

;(def a-timer   (t/timer "a.timer" 
;                        :tags {:a "a" :b "b"}
;                        :description "A timer for something")) 
  
(t/dorecord a-timer (Thread/sleep 100))
(t/total-time a-timer :milliseconds)
; => 100.263522

There are 4 ways to use a timer:

  • Directly recoding a duration:

    (t/record a-timer 3 :seconds)
  • Registering a monitored function:

    (monitor t (fn [x] (Thread/sleep 100) x))
  • Monitoring a block a code:

    (dorecord t (Thread/sleep 100) true)
  • Using start/stop:

    (let [sample (t/start)]
      (Thread/sleep 100)
      (t/stop sample a-timer))

License

Copyright © 2019-2023 Oscaro

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Clojure wrapper for Micrometer - vendor-neutral application observability facade, allowing you to instrument your JVM-based application code without vendor lock-in.

Resources

Stars

Watchers

Forks

Packages

No packages published