statsd-default_instrumentation 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ The MIT License (MIT) Copyright (c) 2011 Viximo, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4
+ associated documentation files (the "Software"), to deal in the Software without restriction,
5
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
6
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7
+ furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial
10
+ portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
13
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
15
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ StatsD::DefaultInstrumentation
2
+ ===
3
+
4
+ A set of instrumentation for Rails and common libraries.
5
+
6
+ Configuration
7
+ ---
8
+
9
+ After loading your libraries run `StatsD::DefaultInstrumentation.detect!`. Rails apps should do this in an initializer.
10
+
11
+ The following options are supported and are configured with `StatsD::DefaultInstrumentation.option = value`
12
+
13
+ * prefix: Sets the stat name prefix string. By default this is "default_instrumentation" but should be configured to something like "environment.application".
14
+
15
+ Instrumentation
16
+ ---
17
+
18
+ **ActionController**
19
+
20
+ * Count of controller actions grouped by response code. Example: controller.action.403
21
+
22
+ **MemCache**
23
+
24
+ * Count of each operation. Example: memcache.set
25
+ * Count of hits/misses for get operations as memcache.get.hit and memcache.get.miss
26
+
27
+ **Redis**
28
+
29
+ * Count and timing of each operation. Example: redis.get
@@ -0,0 +1 @@
1
+ require 'statsd/default_instrumentation'
@@ -0,0 +1,15 @@
1
+ module StatsD
2
+ module DefaultInstrumentation
3
+ class << self
4
+ attr_accessor :prefix
5
+ end
6
+
7
+ self.prefix = "default_instrumentation"
8
+
9
+ def self.detect!
10
+ require 'statsd/default_instrumentation/action_controller' if defined?(ActionController)
11
+ require 'statsd/default_instrumentation/memcache-client' if defined?(MemCache)
12
+ require 'statsd/default_instrumentation/redis' if defined?(Redis)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ ActionController::Base.around_filter do |controller, action|
2
+ action.call
3
+
4
+ # Record requests per response code
5
+ StatsD.increment(
6
+ [StatsD::DefaultInstrumentation.prefix,
7
+ controller.params[:action],
8
+ controller.response.status.to_i].join('.'))
9
+ end
@@ -0,0 +1,18 @@
1
+ MemCache.class_eval do
2
+ extend StatsD::Instrument
3
+
4
+ [:decr, :incr, :cas, :add, :set].each do |method|
5
+ statsd_count method, [StatsD::DefaultInstrumentation.prefix, "memcache", method].join('.')
6
+ end
7
+
8
+ def get_with_statsd(*args)
9
+ get_without_statsd(*args).tap do |result|
10
+ stat = [StatsD::DefaultInstrumentation.prefix, "memcache", "get"].join('.')
11
+ StatsD.increment stat
12
+ StatsD.increment [stat, result.nil? ? 'miss' : 'hit'].join('.')
13
+ end
14
+ end
15
+
16
+ alias_method :get_without_statsd, :get
17
+ alias_method :get, :get_with_statsd
18
+ end
@@ -0,0 +1,16 @@
1
+ Redis.class_eval do
2
+ extend StatsD::Instrument
3
+
4
+ %w(auth bgrewriteaof bgsave blpop brpop dbsize debug decr decrby del exists expire expireat
5
+ flushall flushdb get getset hset hsetnx hget hincrby hmget hmset hdel hexists hlen hkeys
6
+ hvals hgetall incr incrby info keys lastsave lindex llen lpop lpush lrange lrem lset ltrim
7
+ mapped_hmset mapped_mget mget monitor move mset msetnx psubscribe publish punsubscribe quit
8
+ randomkey rename renamenx rpop rpoplpush rpush sadd save scard sdiff sdiffstore select set
9
+ setex setnx shutdown sinter sinterstore sismember slaveof smembers smove sort spop srandmember
10
+ srem subscribe sunion sunionstore ttl type unsubscribe zadd zcard zcount zincrby zinterstore
11
+ zrange zrangebyscore zrank zrem zremrangebyrank zremrangebyscore zrevrange zrevrangebyscore
12
+ zrevrank zscore zunionstore).each do |method|
13
+ statsd_count method.to_sym, [StatsD::DefaultInstrumentation.prefix, 'redis', method].join('.')
14
+ statsd_measure method.to_sym, [StatsD::DefaultInstrumentation.prefix, 'redis', method].join('.')
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module StatsD
2
+ module DefaultInstrumentation
3
+ module VERSION
4
+ MAJOR = 0
5
+ MINOR = 2
6
+ PATCH = 0
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, PATCH].join('.')
10
+ end
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statsd-default_instrumentation
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Matt Griffin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-08 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: statsd-instrument
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Provides a default set of instrumentation for Rails and common caching libraries.
36
+ email: matt@griffinonline.org
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - LICENSE
45
+ - README.md
46
+ - lib/statsd-default_instrumentation.rb
47
+ - lib/statsd/default_instrumentation.rb
48
+ - lib/statsd/default_instrumentation/action_controller.rb
49
+ - lib/statsd/default_instrumentation/memcache-client.rb
50
+ - lib/statsd/default_instrumentation/redis.rb
51
+ - lib/statsd/default_instrumentation/version.rb
52
+ has_rdoc: true
53
+ homepage: https://github.com/Viximo/statsd-default-instrumentation
54
+ licenses:
55
+ - MIT
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.5.3
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Default StatsD instrumentation for common libraries
86
+ test_files: []
87
+