Skip to content

Instantly share code, notes, and snippets.

@YarekTyshchenko
Created July 31, 2017 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YarekTyshchenko/db4ebbc11037d39cc26b9bbe20a67868 to your computer and use it in GitHub Desktop.
Save YarekTyshchenko/db4ebbc11037d39cc26b9bbe20a67868 to your computer and use it in GitHub Desktop.
Makefile statsd instrumentation
STATSD_HOST ?= graphite.example.com
STATSD_PREFIX := development.makefile
# Start timer
# $(call start,test.counter)
define start
-@perl -MTime::HiRes=time -we"open my \$$f, '>', '._timing_$(1)'; print \$$f int time * 1000; close \$$f"
endef
# End timer, and send metric
# $(call end,test.counter)
define end
-@printf "$(STATSD_PREFIX).%s:%d|ms\n" $(1) $$(perl -MTime::HiRes=time -we"open my \$$f, '<', '._timing_$(1)'; print int time * 1000 - <\$$f>") | nc -w 0 -u $(STATSD_HOST) 8125
-@rm ._timing_$(1)
endef
# Send counter metric
# $(call count,test.counter)
define count
-@printf "$(STATSD_PREFIX).%s:1|c\n" $(1) | nc -w 0 -u $(STATSD_HOST) 8125
endef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment