Giter Club home page Giter Club logo

prometheus-clj's Introduction

prometheus-clj

A Clojure library designed to provide ring/compojure wrappers for Prometheus SimpleClient metrics.

Installation

Leiningen

prometheus-clj is available from Clojars.

Clojars Project

Usage

Require prometheus core.

(:require [prometheus.core :as prometheus])

Wrap your ring handler so the prometheus client can start collecting metrics about your requests.

(prometheus/instrument-handler handler your-app-name your-prometheus-collector-registry)

Create a compojure route so that the prometheus server can poll your application for metrics.

(GET "/metrics" [] (prometheus/dump-metrics your-prometheus-collector-registry))

Example with custom metrics

(ns prometheus.example
  (:require [prometheus.core :as prometheus]
            [ring.server.standalone :refer [serve]]))

(defonce store (atom nil))

(defn register-metrics [store]
  (->
    store
    (prometheus/register-counter "test" "some_counter" "some test" ["foo"])
    (prometheus/register-gauge "test" "some_gauge" "some test" ["foo"])
    (prometheus/register-histogram "test" "some_histogram" "some test" ["foo"] [0.7 0.8 0.9])))

(defn init! []
  (->> (prometheus/init-defaults)
       (register-metrics)
       (reset! store)))

(defn handler [_]
  (prometheus/increase-counter @store "test" "some_counter" ["bar"] 3)
  (prometheus/set-gauge @store "test" "some_gauge" 101 ["bar"])
  (prometheus/track-observation @store "test" "some_histogram" 0.71 ["bar"])
  (prometheus/dump-metrics (:registry @store)))


(defn -main [&]
  (init!)
  (serve
    (prometheus/instrument-handler handler
                                   "test_app"
                                   (:registry @store))))

Run the example server:

lein run -m prometheus.example

License

Copyright 2014 SoundCloud, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

prometheus-clj's People

Contributors

tomcz avatar schnipseljagd avatar grobie avatar pieterbreed avatar

Watchers

dikang123 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.