Giter Site home page Giter Site logo

unbounce / clojure-dogstatsd-client Goto Github PK

View Code? Open in Web Editor NEW
18.0 30.0 6.0 51 KB

A thin veneer over the official java dogstatsd client

Home Page: https://cljdoc.org/d/com.unbounce/clojure-dogstatsd-client/

License: MIT License

Clojure 100.00%
statsd-client ring-middleware monitoring owner-platform-services

clojure-dogstatsd-client's Introduction

clojure-statsd-client

Clojars Project CircleCI

A thin veneer over the officia Java dogstatsd client. This library favours pragmatism where possible.

Instrumenting your code should be easy, you shouldn't be forced to thread a statsd client in your code. This library keeps a global client around so your application doesn't need to know about it.

Usage

Somewhere in your code, you should setup the client:

(require '[com.unbounce.dogstatsd.core :as statsd])

;; Do this once in your code
;; Or statd calls will default to use NoOpStatsDClient to avoid nullpointer exception
;; You can also configure the host/port by setting the environment variables: DD_AGENT_HOST and DD_DOGSTATSD_PORT
(statsd/setup! :host "127.0.0.1" :port 8125 :prefix "my.app")

;; Increment or decrement a counter
(statsd/increment "counter")           ; increment by 1
(statsd/increment "counter" {:by 2.5}) ; increment by 2.5
(statsd/decrement "another.counter")   ; decrement by 1

;; Records a value at given time
(statsd/gauge "a.gauge" 10)

;; Record a histogram value (i.e for measuring percentiles)
(statsd/histogram "a.histogram" 10)

;; Time how long body takes and records it to the metric
(statsd/time! ["a.timed.body" {}]
  (Thread/sleep 100)
  (Thread/sleep 100))

;; Time how long it takes with a tag/sample-rate
(statsd/time! ["my.metric.with.tags" {:tags #{"foo"} :sample-rate 0.3}}]
  (Thread/sleep 1000))

;; Shutdown client to ensure all messages are emitted to statsd and resources are cleaned up
(statsd/shutdown!)

Ring Middleware

This library also has comes with a ring middleware to capture HTTP requests. See com.unbounce.dogstatsd.ring for more information.

The middleware provides these metrics:

  • http.1xx counter of 1xx responses
  • http.2xx counter of 2xx responses
  • http.3xx counter of 3xx responses
  • http.4xx counter of 4xx responses
  • http.5xx counter of 5xx responses
  • http.count counter for total requests
  • http.exception counter for exceptions raised
  • http.duration histogram of request duration

Usage:

(require '[com.unbounce.dogstatsd.ring :as dogstatsd.ring])

;; by default instrument all requests
(def handler (-> (constantly {:status 200})
                 (dogstatsd.ring/wrap-http-metrics)))

;; when sample-rate is set, only 20% of requests will be instrumented
(def handler (-> (constantly {:status 200})
                 (dogstatsd.ring/wrap-http-metrics {:sample-rate 0.2})))

License

Copyright © 2018 Unbounce Marketing Solutions Inc.

Distributed under the MIT License.

clojure-dogstatsd-client's People

Contributors

bbvebjorn avatar gzmask avatar j0ni avatar jpb avatar rymndhng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clojure-dogstatsd-client's Issues

Support configuring the client from environment variables

All of the official Datadog dogstatsd clients can now be configured via standard environment variables. As the maintainer of the closure dogstatsd library, could you port the same functionality to this client? We would prefer that configuration be consistent across client libraries.

Sample changes from the Go implementation can be found here: DataDog/datadog-go#78

Let me know if you have any questions about the code or the feature more generally.

Thanks,

Ahmed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.