Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soundcloud/prometheus-clj
Clojure wrappers for the Prometheus java client
https://github.com/soundcloud/prometheus-clj
Last synced: about 2 months ago
JSON representation
Clojure wrappers for the Prometheus java client
- Host: GitHub
- URL: https://github.com/soundcloud/prometheus-clj
- Owner: soundcloud
- License: apache-2.0
- Archived: true
- Created: 2014-03-26T13:41:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-08-04T07:20:22.000Z (over 4 years ago)
- Last Synced: 2024-04-24T08:15:14.010Z (7 months ago)
- Language: Clojure
- Homepage:
- Size: 41 KB
- Stars: 49
- Watchers: 78
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prometheus-clj
> :warning: **Archived**: This prometheus-clj project isn't longer maintained by SoundCloud. Check out [iapetos](https://github.com/clj-commons/iapetos) for an actively maintained Clojure wrapper around the official [Prometheus Java Client](https://github.com/prometheus/client_java).
## Installation
#### Leiningen
prometheus-clj is available from [Clojars](https://clojars.org/com.soundcloud/prometheus-clj).
![Clojars Project](http://clojars.org/com.soundcloud/prometheus-clj/latest-version.svg)
## Usage
Require prometheus core.
```clojure
(:require [prometheus.core :as prometheus])
```Wrap your ring handler so the prometheus client can start collecting metrics about your requests.
```clojure
(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.
```clojure
(GET "/metrics" [] (prometheus/dump-metrics your-prometheus-collector-registry))
```## Example with custom metrics
```clojure
(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 atUnless 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.