Commits

Steve Losh committed aa3e7bf

Add the reading functions and type hint ALL the things.

  • Participants
  • Parent commits 512e4c0

Comments (0)

Files changed (5)

File src/metrics/counters.clj

 (ns metrics.counters
   (use [metrics.utils :only (metric-name)])
-  (import (com.yammer.metrics Metrics)))
+  (import (com.yammer.metrics Metrics))
+  (import (com.yammer.metrics.core CounterMetric)))
 
+
+; Create ----------------------------------------------------------------------
 (defn counter [title]
   (Metrics/newCounter (metric-name title)))
 
+
+; Read ------------------------------------------------------------------------
+(defn value [^CounterMetric c]
+  (.count c))
+
+
+; Write -----------------------------------------------------------------------
 (defn inc!
-  ([c] (inc! c 1))
-  ([c n]
+  ([^CounterMetric c] (inc! c 1))
+  ([^CounterMetric c n]
    (.inc c n)
    c))
 
 (defn dec!
-  ([c] (dec! c 1))
-  ([c n]
+  ([^CounterMetric c] (dec! c 1))
+  ([^CounterMetric c n]
    (.dec c n)
    n))
 
+(defn clear! [^CounterMetric c]
+  (.clear c))
+

File src/metrics/gauges.clj

   (import (com.yammer.metrics.core GaugeMetric)))
 
 
-(defn gauge [title & body]
-  `(Metrics/newGauge (metric-name title)
+; Create ----------------------------------------------------------------------
+(defmacro gauge [title & body]
+  `(Metrics/newGauge (metric-name ~title)
                      (proxy [GaugeMetric] []
                        (value [] (do ~@body)))))
 
+; Read ------------------------------------------------------------------------
 (defn gauge-fn [title f]
   (Metrics/newGauge (metric-name title)
                     (proxy [GaugeMetric] []
                       (value [] (f)))))
 
+
+; Write -----------------------------------------------------------------------
+(defn value [^GaugeMetric g]
+  (.value g))

File src/metrics/histograms.clj

 (ns metrics.histograms
   (use [metrics.utils :only (metric-name)])
-  (import (com.yammer.metrics Metrics)))
+  (import (com.yammer.metrics Metrics))
+  (import (com.yammer.metrics.core HistogramMetric)))
 
 
+; Create ----------------------------------------------------------------------
 (defn histogram
   ([title] (histogram title false))
   ([title biased]
    (Metrics/newHistogram (metric-name title) biased)))
 
+
+; Read ------------------------------------------------------------------------
+(defn mean [^HistogramMetric h]
+  (.mean h))
+
+(defn std-dev [^HistogramMetric h]
+  (.stdDev h))
+
+(defn percentiles
+  ([^HistogramMetric h]
+   (percentiles h [0.75 0.90 0.95 1.0]))
+  ([^HistogramMetric h ps]
+   (zipmap ps
+           (.percentiles h (double-array ps)))))
+
+(defn number-recorded [^HistogramMetric h]
+  (.count h))
+
+(defn largest [^HistogramMetric h]
+  (.max h))
+
+(defn smallest [^HistogramMetric h]
+  (.min h))
+
+(defn sample [^HistogramMetric h]
+  (.values h))
+
+
+; Write -----------------------------------------------------------------------
 (defn update!
-  ([h] (update! h 1))
-  ([h n]
-   (.update h n)
+  ([^HistogramMetric h] (update! h 1))
+  ([^HistogramMetric h n]
+   (.update h (long n))
    h))
+
+(defn clear! [^HistogramMetric h]
+  (.clear h)
+  h)
+

File src/metrics/meters.clj

 (ns metrics.meters
   (use [metrics.utils :only (metric-name)])
   (import (com.yammer.metrics Metrics))
+  (import (com.yammer.metrics.core MeterMetric))
   (import (java.util.concurrent TimeUnit)))
 
 
+; Create ----------------------------------------------------------------------
 (defn meter [title event-type]
   (Metrics/newMeter (metric-name title)
                     event-type
                     TimeUnit/SECONDS))
 
-(defn mark! [m]
-  (.mark m)
-  m)
 
+; Read ------------------------------------------------------------------------
+(defn rates [^MeterMetric m]
+  {1 (.oneMinuteRate m)
+   5 (.fiveMinuteRate m)
+   15 (.fifteenMinuteRate m)})
+
+(defn rate-one [^MeterMetric m]
+  (.oneMinuteRate m))
+
+(defn rate-five [^MeterMetric m]
+  (.fiveMinuteRate m))
+
+(defn rate-fifteen [^MeterMetric m]
+  (.fifteenMinuteRate m))
+
+(defn rate-mean [^MeterMetric m]
+  (.meanRate m))
+
+
+; Write -----------------------------------------------------------------------
+(defn mark!
+  ([^MeterMetric m]
+   (mark! m 1))
+  ([^MeterMetric m n]
+   (.mark m (long n))
+   m))

File src/metrics/timers.clj

 (ns metrics.timers
   (use [metrics.utils :only (metric-name)])
   (import (com.yammer.metrics Metrics))
+  (import (com.yammer.metrics.core TimerMetric))
   (import (java.util.concurrent TimeUnit)))
 
 
+; Create ----------------------------------------------------------------------
 (defn timer [title]
   (Metrics/newTimer (metric-name title)
                     TimeUnit/MILLISECONDS
                     TimeUnit/SECONDS))
 
+
+; Read ------------------------------------------------------------------------
+(defn rates [^TimerMetric m]
+  {1 (.oneMinuteRate m)
+   5 (.fiveMinuteRate m)
+   15 (.fifteenMinuteRate m)})
+
+(defn rate-one [^TimerMetric m]
+  (.oneMinuteRate m))
+
+(defn rate-five [^TimerMetric m]
+  (.fiveMinuteRate m))
+
+(defn rate-fifteen [^TimerMetric m]
+  (.fifteenMinuteRate m))
+
+(defn rate-mean [^TimerMetric m]
+  (.meanRate m))
+
+(defn mean [^TimerMetric t]
+  (.mean t))
+
+(defn std-dev [^TimerMetric t]
+  (.stdDev t))
+
+(defn percentiles
+  ([^TimerMetric t]
+   (percentiles t [0.75 0.90 0.95 1.0]))
+  ([^TimerMetric t ps]
+   (zipmap ps
+           (.percentiles t (double-array ps)))))
+
+(defn number-recorded [^TimerMetric t]
+  (.count t))
+
+(defn largest [^TimerMetric t]
+  (.max t))
+
+(defn smallest [^TimerMetric t]
+  (.min t))
+
+(defn sample [^TimerMetric t]
+  (.values t))
+
+
+; Write -----------------------------------------------------------------------
 (defmacro time! [t & body]
   `(.time ~t
          (proxy [Callable] []
          (proxy [Callable] []
            (call [] (f)))))
 
+(defn clear! [^TimerMetric t]
+  (.clear t))