Code Monkey home page Code Monkey logo

statsd's Introduction

StatsD

A very simple client to format and send metrics to a StatsD server.

Installation

gem install statsd

Client

In your client code:

require 'rubygems'
require 'statsd'
STATSD = Statsd::Client.new(:host => 'localhost', :port => 8125)

STATSD.increment('some_counter') # basic incrementing
STATSD.increment('system.nested_counter', 0.1) # incrementing with sampling (10%)

STATSD.decrement(:some_other_counter) # basic decrememting using a symbol
STATSD.decrement('system.nested_counter', 0.1) # decrementing with sampling (10%)

STATSD.timing('some_job_time', 20) # reporting job that took 20ms
STATSD.timing('some_job_time', 20, 0.05) # reporting job that took 20ms with sampling (5% sampling)

There is an option for reduced DNS lookups, you can specify an additional constructor option :resolve_always and set it to false. By default, the client will always resolve the address unless host is set to 'localhost' or '127.0.0.1'.

require 'rubygems'
require 'statsd'

STATSD = Statsd::Client.new(:host => 'specialstats.host.example',
                            :port => '8125',
                            :resolve_always => false)

STATSD.increment('some_counter') # basic incrementing

Note about thread-safety

Since class variables and instance variables are not thread-safe on initialization, there is a potential for multiple UDP sockets being opened upon if you are using a truly multithreaded ruby, i.e. JRuby. Make sure to take that in to account when initializing this library.

Guts

  • UDP Client libraries use UDP to send information to the StatsD daemon.

  • Graphite

Graphite

Graphite uses "schemas" to define the different round robin datasets it houses (analogous to RRAs in rrdtool):

[stats]
priority = 110
pattern = ^stats\..*
retentions = 10:2160,60:10080,600:262974

That translates to:

  • 6 hours of 10 second data (what we consider "near-realtime")
  • 1 week of 1 minute data
  • 5 years of 10 minute data

This has been a good tradeoff so far between size-of-file (round robin databases are fixed size) and data we care about. Each "stats" database is about 3.2 megs with these retentions.

Inspiration

Etsy's blog post.

StatsD was inspired (heavily) by the project (of the same name) at Flickr. Here's a post where Cal Henderson described it in depth: Counting and timing. Cal re-released the code recently: Perl StatsD

statsd's People

Contributors

avalade avatar dgolombek avatar ismith avatar oscil8 avatar quasor avatar smathieu avatar trane avatar

Watchers

 avatar  avatar

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.