Skip to content

Commit

Permalink
Merge pull request #48 from jwhitlark/ganglia
Browse files Browse the repository at this point in the history
First cut of a ganglia reporter. Attempts to fix #36.
  • Loading branch information
michaelklishin committed Aug 28, 2014
2 parents a3a9667 + 99bf9a7 commit f5184d4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog.md
@@ -1,5 +1,10 @@
## Changes Between 2.2.x and 2.3.0


## Added first cut of a Ganglia reporter

Contributed by Jason Whitlark.

## Added CSV Reporter and documentation

Contributed by Jason Whitlark.
Expand Down
28 changes: 27 additions & 1 deletion docs/source/aggregation.rst
Expand Up @@ -48,7 +48,33 @@ Optional arguments to graphite/reporter are:
Sending Metrics to Ganglia
--------------------------

**TODO**
Note: You must include ``metrics-clojure-ganglia`` in your project.clj.

I don't have a ganglia server to test against, so while this compiles,
and should work, it still needs testing.

metrics-clojure supports aggregating metrics to ganglia::

(require '[metrics.reporters.ganglia :as ganglia])
(import '[java.util.concurrent.TimeUnit])
(import '[com.codahale.metrics MetricFilter])

(def ganglia (... your ganglia GMetric config here ...))
(def GR (ganglia/reporter ganglia
{:rate-unit TimeUnit/SECONDS
:duration-unit TimeUnit/MILLISECONDS
:filter MetricFilter/ALL}))
(ganglia/start GR 1)

This will tell ``metrics`` to aggregate all metrics to ganglia every
minute.

Optional arguments to ganglia/reporter are:

- :rate-unit
- :duration-unit
- :filter


Implementing a Simple Graphing Server
-------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions metrics-clojure-ganglia/project.clj
@@ -0,0 +1,4 @@
(defproject metrics-clojure-ganglia "2.3.0-SNAPSHOT"
:description "Ganglia reporter integration for metrics-clojure"
:dependencies [[metrics-clojure "2.3.0-SNAPSHOT"]
[com.codahale.metrics/metrics-ganglia "3.0.2"]])
30 changes: 30 additions & 0 deletions metrics-clojure-ganglia/src/metrics/reporters/ganglia.clj
@@ -0,0 +1,30 @@
(ns metrics.reporters.ganglia
"Ganglia reporter interface"
(:require [metrics.core :refer [default-registry]]
[metrics.reporters :as mrep])
(:import java.util.concurrent.TimeUnit
[com.codahale.metrics MetricRegistry MetricFilter]
[com.codahale.metrics.ganglia GangliaReporter GangliaReporter$Builder]))

(defn ^GangliaReporter reporter
([ganglia opts]
(reporter default-registry opts))
([^MetricRegistry reg ganglia opts]
(let [b (GangliaReporter/forRegistry reg)]
(when-let [^TimeUnit ru (:rate-unit opts)]
(.convertRatesTo b ru))
(when-let [^TimeUnit du (:duration-unit opts)]
(.convertDurationsTo b du))
(when-let [^MetricFilter f (:filter opts)]
(.filter b f))
(.build b ganglia))))

(defn start
"Report all metrics to ganglia periodically."
[^GangliaReporter r ^long minutes]
(mrep/start r minutes))

(defn stop
"Stops reporting."
[^GangliaReporter r]
(mrep/stop r))

0 comments on commit f5184d4

Please sign in to comment.