Giter Club home page Giter Club logo

macrometer's Introduction

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.

macrometer's People

Contributors

neuromantik33 avatar iomonad avatar rolt avatar vielmath avatar

Stargazers

 avatar

Watchers

Sébastien Aperghis-Tramoni avatar Germain Maurice avatar  avatar Rousseau Baptiste avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.