Upload
rick-chang
View
436
Download
0
Tags:
Embed Size (px)
Citation preview
StatsD IntroductionRick chang
Agenda
History!
Architecture!
Concept!
Demo!
Implementation
History
StatsD is a front-end proxy for the Graphite/Carbon metrics server.!
Originally written by Etsy’s Erik Kastner!
The first idea from Flickr by Cal Henderson!
Implemented in Node
StatsD in many languages
Flickr’s StatsD: Perl. The real original statsd from 2008.!
Etsy’s statsd: Node.js. The new statsd.!
petef-statsd: Ruby. Supports AMQP.!
quasor/statsd: Ruby. can send data to graphite or mongoDB!
py-statsd: Python (including python client code).!
statsd.scala: Scala. Sends data to Ganglia instead of Graphite. Different messaging protocol, uses JSON.!
statsd-c: C. compatible with original etsy statsd!
bucky: Python. A small server for collecting and translating metrics for Graphite. It can current collect metric data from CollectD daemons and from StatsD clients.
Reference: http://www.joemiller.me/2011/09/21/list-of-statsd-server-implementations/
Architecture
Your App send data to StatsD by UDP port 8125!
StatsD send data to Carbon by TCP port 2003
Metric Types
Count [key]:[value]|c!
sample.counter:1|c!
At each flush the current count is sent and reset to 0!
Sampling!
sample.counter:1|[email protected]!
sent sampled every 1/10th of the time!
Scenarios!
View count
Reference: https://github.com/etsy/statsd/blob/master/docs/metric_types.md
Metric Types
Gauge [key]:[value]|g!
sample.gauge:75|g!
If the gauge is not updated at the next flush, it will send the previous value.!
Scenarios!
Resource number
Metric Types
Set [key]:[value]|s!
sapmle.set:4219|s!
Counting unique occurrences of events between flushes, using a Set to store all occurring events.!
Scenarios!
Unique user count
Metric Types
Timing [key]:[value]|ms!
sample.timer:10000|ms!
Scenarios!
To calculate the difference time!
Response time calculation
Demo
StatsD Server
Install Node before using npm!
Install StatsD!
npm install -g statsd!
Run StatsD!
node stats.js config.js
config.js!
Statsd UDP port: 8125!
Backends: [ "./backends/console", "./backends/graphite" ]
{ graphitePort: 2003, graphiteHost: "graphite.hostname", address: "127.0.0.1", port: 8125, mgmt_address: "127.0.0.1", mgmt_port: 8126, backends: [ "./backends/graphite" ], graphite: { legacyNamespace: false, globalPrefix: "stats", prefixCounter: "counters", prefixTimer: "timers", prefixGauge: "gauges", prefixSet: "sets" }}
StatsD Server
StatsD Clients
Node client!
https://github.com/msiebuhr/node-statsd-client!
Java client!
https://github.com/tim-group/java-statsd-client
Reference: https://github.com/etsy/statsd/wiki
Node Client
var SDC = require(‘statsd-client');!
Increment!
sdc.increment("sample.counter");!
sdc.increment("sample.mycounter", 10);!
Gauge!
sdc.gauge("sample.gauge", randomInteger(100));
Node Client
Set!
sdc.set("sapmle.set", randomInteger(10000));!
Timer!
timer = new Date();!
sdc.timing("sample.timer", timer);
Java Client
public class Foo { private static final StatsDClient statsd = new NonBlockingStatsDClient("my.prefix", "statsd-‐host", 8125); ! public static final void main(String[] args) { statsd.incrementCounter("bar"); statsd.recordGaugeValue("baz", 100); statsd.recordExecutionTime("bag", 25); statsd.recordSetEvent("qux", "one"); }
CollectD vs StatsD?
CollectD: Collect system data!
StatsD: Collect application data
Next?
Further Items
StatsD Cluster Proxy!
Refactor 3DS FrontServer!
Collect response time during component communication!
Collect data from GPS (Windows)