Created
April 26, 2011 20:53
-
-
Save apg/943119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def alphas (c/one-of "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")) | |
(def digits c/digit) | |
(def special (c/one-of ".-")) | |
(def float-value | |
(domonad c/parser-m | |
[sign (c/optional (c/is-char \-)) | |
rat c/natural | |
dec (c/optional (c/>> (c/is-char \.) c/natural))] | |
(Float/parseFloat (str sign rat "." dec)))) | |
(def graphite-key (c/stringify (c/many (c/either alphas digits special)))) | |
(def measurement (c/>> (c/is-char \:) float-value)) | |
(def measure-type | |
(domonad c/parser-m | |
[_ (c/is-char \|) | |
t (c/either (c/string "ms") (c/string "c"))] | |
({"c" :counter "ms" :timing} t))) | |
(def sample-rate (c/>> (c/is-char \@) float-value)) | |
(def parse-stat | |
(domonad c/parser-m | |
[key graphite-key | |
measure (c/optional measurement) | |
type measure-type | |
rate (c/optional sample-rate)] | |
{:type type | |
:key key | |
:value measure | |
:sample rate})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment