Provides a Racket DogStatsD client for sending metrics to Datadog. DogStatsD is an extension of the StatsD protocol developed by Etsy for metrics aggregation. DogStatsD requires that you have the Datadog Agent running on the host, or another service listening for udp traffic on port 8125.
| ; Create a socket on 127.0.0.1:8125 which the Agent listens on|
| (define (send-times)|
| ; Wrap some code with a timer metric - the elapsed time (ms) for the execution|
| ; of the body will be sent to the agent|
| (with-timer "rkt.timer" #:tags '("proc:send-times" "proc:with-timer")|
| (let ([xs (range 10)])|
| (for ([i xs])|
| ; Send a counter metric|
| (counter "rkt.counter" i #:tags '("proc:send-times"|
| #:sample-rate 0.25))))|
| (println (current-seconds))|
| (sleep 2)|
2 Setup a socket
Create and open a udp?
socket for host-name on host-port. You should only do this once in your program.
Manually send a metric string on the socket created with sock-create
. This is a low-level building block used by the metric procedures.
Close the currently open socket.
Send a DogStatsD Counter
metric. Counters track how many times something happens per second, like page views or downloads.
|; Simple counter|
|(counter "dogeapp.downloads" 5)|
|; Counter with tags|
|(counter "dogeapp.dowloads" 5 #:tags '("size:small" "type:shibainu"))|
|; Counter with sample-rate|
|(counter "dogeapp.dowloads" 5 #:sample-rate 0.25)|
Send a DogStatsD Gauge
metric. Gauges track the ebb and flow of a particular metric value over time, like the number of active users on a website.
|; Simple gauge|
|(gauge "dogeapp.users.active" (get-active-users))|
|; Gauge with tags|
|(gauge "dogeapp.users.active" (get-active-users) #:tags '("type:shibainu"))|
|; Gauge with sample-rate|
|(gauge "dogeapp.users.active" (get-active-users) #:sample-rate 0.25)|
Send a DogStatsD Histogram
metric. Histograms calculate the statistical distribution of any kind of value. For instance you can track distributions for anything, like the size of files users upload to your site.
Send a DogStatsD Set
metric. Sets count the number of unique elements in a group. To track the number of unique visitors to your site, use a set.
|; Simple set|
|(set "dogeapp.users.uniques" (current-user-id))|
|; Set with tags|
|(set "dogeapp.users.uniques" (current-user-id) #:tags '("type:shibainu"))|
|; Set with sample-rate|
|(set "dogeapp.users.uniques" (current-user-id) #:sample-rate 0.75)|
Timers measure the amount of time a section of code takes to execute, like the time it takes to render a web page. This module provides a manual timer procedure and a with-timer macro you can wrap code with.
Manually send a DogStatsD timing
metrics. The value should be the milliseconds you wish to record. Read the documentation on Timers, as they create Histogram metrics automatically.
|(define timed (... some procedure that returns milliseconds you wish to record ...))|
|; Simple timer|
|(timer "dogeapp.page.render" timed)|
|; Timer with tags|
|(timer "dogeapp.page.render" timed #:tags '("type:shibainu"))|
|; Timer with sample-rate|
|(timer "dogeapp.page.render" timed #:sample-rate 0.45)|
|(with-timer name tags-clause sample-clause|
| body ...)|
|name|| ||=|| ||metric-name|
| || ||||| ||...|
| || || || || |
|tags-clause|| ||=|| |
| || ||||| ||#:tags (tags-id:id)|
| || ||||| ||#:tags (tags-id:id) ...|
| || || || || |
|sample-clause|| ||=|| |
| || ||||| ||#:sample-rate sample-id:id|
| || ||||| ||#:sample-rate sample-id:id ...|
provides an easy to use macro for timing chunks of code. Wrapping your function or let-body will automatically time its execution and send the metric. It also returns the value of the executed body clause, so you can use it in a define
if you like.
|; Time the execution of code in milliseconds and send metric to Agent|
|(with-timer "dogeapp.page.render" #:tags '("type:threaded")|
| ; code you want to instrument here|
|; Used in a define, will set timed-value to the result of (call-databass)|
|; and send the timing metric to the Agent|
|(define timed-value (with-timer "dogeapp.databass.call" (call-databass ...)))|
For performance sensitive code you may want to batch up metrics before sending to the Agent. In this case you can create buffered versions of a metric, which only dispatch to the Agent when their limit has been reached.
Wraps a metric procedure such as counter
with a buffer, which will store metrics until limit
is reached. The default is a buffer of size 25.
|; Will buffer 15 metrics before sending to the Agent|
|(define buffered-counter (make-buffered counter 15))|
|; Only the first 15 metrics will be sent|
|(for ([x (range 17)])|
| (buffered-counter "dogeapp.items" x #:tags '("type:buffered")))|
|(event|| ||title|| || || || |
| || ||text|| || || || |
| || [||#:timestamp timestamp|| || || || |
| || ||#:hostname hostname|| || || || |
| || ||#:aggregation-ket aggregation-key|| || || || |
| || ||#:priority priority|| || || || |
| || ||#:source-type-name source-type-name|| || || || |
| || ||#:alert-type alert-type|| || || || |
| || ||#:tags tags])|| ||→|| ||void?|
| title : string?|
| text : string?|
| timestamp : number? = #f|
| hostname : string? = #f|
| aggregation-key : string? = #f|
| priority : (one-of/c "normal" "low") = "normal"|
| source-type-name : string? = #f|
| ||alert-type|| ||:|| ||(one-of/c "info" "error" "warning" "success")|
| || || ||=|| ||"info"|
| tags : (listof string?) = #f|
Send a DogStatsD Event
. DogStatsD can emit events to your Datadog event stream. For example, you may want to see errors and exceptions in Datadog.
7 Service Checks
DogStatsD can send Service checks to track the status of services your application depends on.