seismograph 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8985d0e21554d6c00633a9cb03a2f46a97679a10
4
+ data.tar.gz: dc9d5c64bcc0d864a64c995b89de37421046f5bb
5
+ SHA512:
6
+ metadata.gz: 6e707ac8b165d80eb3113304b557869155ebbd3c6cb53b13eebf58e12fa3547c98849c6578c0720739b132220b69392db25b7842f00a90763df737cc3f920bc2
7
+ data.tar.gz: 3aa9ea075f8f466fc844c99f15ab2bcfcdd2a644863900de392fe4defd1a6b4564fb3927b17e19ce0e7a8b59b1315bd0e6b778734be519b8204eb155772e78d6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+
17
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seismograph.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1 @@
1
+ Proprietary
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Seismograph
2
+
3
+ A helper library for writing metrics and events to (http://datadoghq.com)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'seismograph'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Configure your statsd server:
16
+
17
+ ```ruby
18
+ require 'seismograph'
19
+
20
+ Seismograph.config do |config|
21
+ config.app_name = 'cabbagepult'
22
+ config.statsd_host = ENV.fetch('STATSD_HOST')
23
+ config.statsd_port = ENV.fetch('STATSD_PORT')
24
+ end
25
+ ```
26
+
27
+ After creating a sensor that designates a metric namespace, you can write values to it:
28
+
29
+ ```ruby
30
+ require 'seismograph'
31
+
32
+ def sensor
33
+ @_sensor ||= Seismograph::Sensor.new('account')
34
+ end
35
+
36
+ def create
37
+ users_to_create = [user1, user_2]
38
+
39
+ sensor.count('signup', users_to_create.size) do
40
+ # If an error is raised, the 'account.signup.failure' metric will be incremented instead
41
+ User.create!(users_to_create)
42
+ end
43
+ end
44
+ ```
45
+
46
+ #### Benchmarking:
47
+
48
+ ```ruby
49
+ def create
50
+ sensor.benchmark('signup') do
51
+ # Timing will be written for the account.signup metric
52
+ User.create!(params)
53
+ end
54
+ end
55
+ ```
56
+
57
+ #### Logging events:
58
+
59
+ ```ruby
60
+ task :deploy do
61
+ begin
62
+ deploy!
63
+ Seismograph::Log.info('App Deployed')
64
+ rescue StandardError => e
65
+ Seismograph::Log.error('Deployment failed!', description: e.message)
66
+ end
67
+
68
+ # "warning" and "success" are the remaining type alert type possibilities
69
+ end
70
+
71
+
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ dependencies:
2
+ pre:
3
+ - gem install bundler -v 1.10.6
@@ -0,0 +1,40 @@
1
+ module Seismograph
2
+ class Configuration
3
+ attr_writer :statsd_host
4
+ attr_writer :statsd_port
5
+ attr_writer :app_name
6
+ attr_writer :env
7
+
8
+ def statsd_host=(host)
9
+ @statsd_host = host
10
+ end
11
+
12
+ def statsd_port=(port)
13
+ @statsd_port = port.to_s
14
+ end
15
+
16
+ def app_name=(name)
17
+ @app_name = name
18
+ end
19
+
20
+ def env=(env)
21
+ @env = env
22
+ end
23
+
24
+ def statsd_host
25
+ @statsd_host || fail('No statsd_host configured')
26
+ end
27
+
28
+ def statsd_port
29
+ @statsd_port || fail('No statsd_port configured')
30
+ end
31
+
32
+ def app_name
33
+ @app_name || fail('No app_name configured')
34
+ end
35
+
36
+ def env
37
+ @env || ENV['RAILS_ENV'] || ENV['RACK_ENV']
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ require 'statsd'
2
+
3
+ module Seismograph
4
+ module Gateway
5
+ class << self
6
+ [:histogram, :increment, :time, :event].each do |method|
7
+ define_method(method) do |*args, &block|
8
+ client.send(method, *args, &block)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def client
15
+ @client ||= Statsd.new(Seismograph.config.statsd_host,
16
+ Seismograph.config.statsd_port,
17
+ namespace: namespace)
18
+ end
19
+
20
+ def namespace
21
+ [
22
+ Seismograph.config.app_name,
23
+ Seismograph.config.env
24
+ ].compact.join('.')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module Seismograph
2
+ module Log
3
+ class << self
4
+ [:info, :error, :warning, :success].each do |alert_type|
5
+ define_method alert_type do |message, params = {}|
6
+ description = params.delete(:description) || ''
7
+ log(message, description, params.merge(alert_type: alert_type.to_s))
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def log(message, description, params)
14
+ params[:tags] = Array(params[:tags]) if params.key?(:tags)
15
+
16
+ Gateway.event(
17
+ message,
18
+ description,
19
+ params.merge(
20
+ source_type_name: Seismograph.config.app_name
21
+ )
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ require 'seismograph/gateway'
2
+
3
+ module Seismograph
4
+ class Sensor
5
+ attr_reader :namespace
6
+
7
+ def initialize(namespace)
8
+ @namespace = namespace
9
+ end
10
+
11
+ def count(description, amount, params = {}, &block)
12
+ track(description, amount, params, &block)
13
+ end
14
+
15
+ def increment(description, params = {})
16
+ Gateway.increment(stat(description), gateway_params(params))
17
+ end
18
+
19
+ def benchmark(description, params = {})
20
+ Gateway.time(stat(description), gateway_params(params)) do
21
+ yield
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def track(description, amount, params = {}, &block)
28
+ begin
29
+ block.call if block_given?
30
+ Gateway.histogram(stat(description), amount, gateway_params(params))
31
+ rescue StandardError => e
32
+ increment("#{description}.failure", gateway_params(params))
33
+ raise e
34
+ end
35
+ end
36
+
37
+ def gateway_params(params)
38
+ params.key?(:tags) ? { tags: Array(params[:tags]) } : { }
39
+ end
40
+
41
+ def stat(description)
42
+ "#{namespace}.#{description}"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Seismograph
2
+ VERSION = '0.1.3'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'seismograph/configuration'
2
+ require 'seismograph/sensor'
3
+ require 'seismograph/log'
4
+
5
+ module Seismograph
6
+ def self.config(&block)
7
+ @config ||= Configuration.new
8
+ block.call(@config) if block_given?
9
+ @config
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seismograph/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'seismograph'
8
+ spec.version = Seismograph::VERSION
9
+ spec.authors = ['Brandon Croft', 'Matt Huggins']
10
+ spec.email = ['brandon@kapost.com', 'matt.huggins@kapost.com']
11
+ spec.summary = %q{Helper library to report stats and events to datadoghq}
12
+ spec.description = %q{Wraps dogstatsd-ruby with helpful conventions}
13
+ spec.homepage = 'https://github.com/kapost/seismograph'
14
+ spec.license = 'Proprietary'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'dogstatsd-ruby', '~> 1.5'
22
+
23
+ spec.add_development_dependency 'pry-nav'
24
+ spec.add_development_dependency 'bundler', '~> 1.10.0'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.2'
27
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
28
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seismograph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Croft
8
+ - Matt Huggins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dogstatsd-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: pry-nav
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 1.10.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 1.10.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.2'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.2'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-its
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.2'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.2'
98
+ description: Wraps dogstatsd-ruby with helpful conventions
99
+ email:
100
+ - brandon@kapost.com
101
+ - matt.huggins@kapost.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - circle.yml
113
+ - lib/seismograph.rb
114
+ - lib/seismograph/configuration.rb
115
+ - lib/seismograph/gateway.rb
116
+ - lib/seismograph/log.rb
117
+ - lib/seismograph/sensor.rb
118
+ - lib/seismograph/version.rb
119
+ - seismograph.gemspec
120
+ homepage: https://github.com/kapost/seismograph
121
+ licenses:
122
+ - Proprietary
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Helper library to report stats and events to datadoghq
144
+ test_files: []