Skip to content

Instantly share code, notes, and snippets.

@codification
Created December 30, 2011 08:55
Show Gist options
  • Save codification/1538837 to your computer and use it in GitHub Desktop.
Save codification/1538837 to your computer and use it in GitHub Desktop.
Graphite client in clojure
(ns clj-client.core
(import [java.net Socket]
[java.io PrintWriter]))
(defn now []
(int (/ (System/currentTimeMillis) 1000)))
(defn write-metric [name value timestamp]
(with-open [socket (Socket. "localhost" 2003)
os (.getOutputStream socket)]
(binding [*out* (PrintWriter. os)]
(println name value timestamp))))
(defn write-metric2 [name value timestamp]
(-> (Socket. "localhost" 2003)
(.getOutputStream)
(PrintWriter.)
(.println (str name value timestamp))))
(defn write-metric3 [name value timestamp]
(binding [*out* (-> (Socket. "localhost" 2003)
(.getOutputStream)
(PrintWriter.))]
(println name value timestamp)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment