Skip to content

Commit

Permalink
Makefile etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjambon committed Oct 4, 2012
1 parent f3ddf17 commit 331b074
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions META
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description = "Statsd client"
requires = "lwt.unix"
archive(byte) = "statsd-client.cma"
archive(native) = "statsd-client.cmxa"
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: default all opt install uninstall

default: all opt

all:
ocamlfind ocamlc -c statsd_client.mli -package lwt.unix
ocamlfind ocamlc -a -g statsd_client.ml \
-o statsd_client.cma -package lwt.unix
opt:
ocamlfind ocamlc -c statsd_client.mli -package lwt.unix
ocamlfind ocamlopt -a -g statsd_client.ml \
-o statsd_client.cmxa -package lwt.unix
install:
ocamlfind install statsd-client META \
`find statsd_client.mli statsd_client.cmi \
statsd_client.cmo statsd_client.cma \
statsd_client.cmx statsd_client.o \
statsd_client.cmxa statsd_client.a`
uninstall:
ocamlfind remove statsd-client

.PHONY: clean
clean:
rm -f *.cm[ioxa] *.cmxa *.[oa] *~
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ ocaml-statsd-client
===================

[Statsd](https://github.com/etsy/statsd) client for OCaml.
Originally written by @mwells.

Originally written by [Mike Wells](https://github.com/mwells).
10 changes: 7 additions & 3 deletions statsd_client.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let ipaddr = ref None
let port = ref None

let log_debug = ref (fun s -> ())
let log_error = ref (fun s -> Printf.eprintf "[error] %s\n%!" s)

module Make(U : sig
val ipaddr : unit -> string option
(** Get the host ip address. Allows for dynamic setting *)
Expand Down Expand Up @@ -41,7 +44,7 @@ end) = struct
match !socket_ref with
| Some s -> s
| None ->
Log.logf `Debug "Creating statsd socket";
!log_debug "Creating statsd socket";
let s =
U.socket Unix.PF_INET Unix.SOCK_DGRAM
protocol_entry.Unix.p_proto
Expand Down Expand Up @@ -69,7 +72,8 @@ end) = struct
socket_ref := None;
U.catch
(fun () ->
Log.logf `Debug "Closing statsd socket: %d" retval;
!log_debug
(Printf.sprintf "Closing statsd socket: %d" retval);
U.close socket >>= U.return)
(fun _e -> U.return ());
end
Expand All @@ -84,7 +88,7 @@ end) = struct
let send ?(sample_rate = 1.0) data =
match U.ipaddr (), U.port () with
| None, _ | _, None ->
Log.logf `Error
!log_error
"Statsd_client.send: \
uninitialized Statsd_client.host or Statsd_client.port";
U.return ()
Expand Down
6 changes: 6 additions & 0 deletions statsd_client.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
val ipaddr : string option ref
val port : int option ref

val log_debug : (string -> unit) ref
(** Default: do nothing. *)

val log_error : (string -> unit) ref
(** Default: log to stderr. *)

module Sync :
sig
val gauge : ?sample_rate:float -> string -> int -> unit
Expand Down

0 comments on commit 331b074

Please sign in to comment.