telltale 0.1.0

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: 1b7021ce6b44df68ba8aac0c3072106ac3a73ffd
4
+ data.tar.gz: c95c0a9856f51a4e5c017662a85917f45bac8432
5
+ SHA512:
6
+ metadata.gz: d67a8ddc2d486db0321163d20d8b24eb916a22ce5f0621be0ede7bf28c4428b26ca84212775fda4bad94587f2159c34816d5aac209d402bc6a6e5fab164f12a6
7
+ data.tar.gz: e9b646fda19c3a43404062c080f37bf06c983b75a7955a125c34feae903a3f198d73217776ba85ecc3dbc64548b257dd94944254b806342c5743ead4c613a465
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Telltale Changelog
2
+
3
+ ## master
4
+
5
+ ## v0.1
6
+
7
+ * Initial implementation
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Telltale
2
+
3
+ Report Rails application metrics to OpenTSDB.
4
+
5
+ ## Metrics
6
+
7
+ These numbers are currently reported:
8
+
9
+ * `<prefix>.rails.total_time`: Total request time in seconds
10
+
11
+ The default `prefix` is "telltale" and can be configured with the environment variable `TELLTALE_PREFIX`.
12
+
13
+ ## Tags
14
+
15
+ The following tags are available for all metrics:
16
+
17
+ * `http_status`: HTTP Status code
18
+ * `controller`: Name of the controller
19
+ * `action`: Name of the action in the form `controller_name.action_name`
20
+ * `host`: Name of the host the Rails app is running on
21
+ * `environment`: The Rails app environment
22
+ * `app`: The application's name
23
+
24
+ ## Configuration
25
+
26
+ Telltale uses the following environment variables for configuration:
27
+
28
+ * `TELLTALE_OPENTSDB_HOST`: The host to report to
29
+ * `TELLTALE_OPENTSDB_PORT`: The port opentsdb listens on. Default is 4242
30
+ * `TELLTALE_PREFIX`: Some prefix for the metric name. Default is `telltale`
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/telltale.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'opentsdb'
2
+
3
+ module Telltale
4
+ class << self
5
+ def setup!
6
+ if report?
7
+ configure_request_instrumentation
8
+ Rails.logger.info "Telltale started, will report to #{opentsdb_host} on port #{opentsdb_port}"
9
+ else
10
+ Rails.logger.error 'TELLTALE_OPENTSDB_HOST not set. Telltale will not report to OpenTSDB.'
11
+ end
12
+ end
13
+
14
+ def configure_request_instrumentation
15
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |_name, started, finished, _unique_id, payload|
16
+ next unless report?
17
+ data = {
18
+ metric: "#{metric_prefix}.rails.total_time",
19
+ value: ((finished - started) * 1000).ceil,
20
+ timestamp: Time.now.to_i,
21
+ tags: tags(payload),
22
+ }
23
+ client.put(data)
24
+ end
25
+ end
26
+
27
+ def report?
28
+ opentsdb_host.present?
29
+ end
30
+
31
+ def tags(payload)
32
+ {
33
+ http_status: http_status_from_payload(payload),
34
+ controller: payload[:controller],
35
+ action: [payload[:controller], payload[:action]].join('.'),
36
+ host: Socket.gethostname,
37
+ environment: Rails.env,
38
+ app: Rails.application.class.parent_name.downcase,
39
+ }
40
+ end
41
+
42
+ def opentsdb_port
43
+ ENV['TELLTALE_OPENTSDB_PORT'] || 4242
44
+ end
45
+
46
+ def opentsdb_host
47
+ ENV['TELLTALE_OPENTSDB_HOST']
48
+ end
49
+
50
+ def metric_prefix
51
+ ENV['TELLTALE_PREFIX'] || 'telltale'
52
+ end
53
+
54
+ def client
55
+ OpenTSDB::Client.new(hostname: opentsdb_host, port: opentsdb_port)
56
+ end
57
+
58
+ def http_status_from_payload(payload)
59
+ return payload[:status] if payload[:status]
60
+ return 500 if payload[:exception].present?
61
+ end
62
+ end
63
+ end
64
+
65
+ require 'telltale/railtie'
@@ -0,0 +1,7 @@
1
+ module Telltale
2
+ class Railtie < Rails::Railtie
3
+ initializer 'telltale.initialize' do
4
+ Telltale.setup!
5
+ end
6
+ end
7
+ end
data/telltale.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'telltale'
7
+ s.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
8
+ s.authors = ['Philippe Hassig']
9
+ s.email = ['phil@nine.ch']
10
+ s.homepage = 'http://github.com/ninech/'
11
+ s.license = 'MIT'
12
+ s.summary = 'Report Rails application metrics to OpenTSDB'
13
+ s.description = 'Report Rails application metrics to OpenTSDB'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_runtime_dependency 'opentsdb', '~> 0.2.0'
21
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: telltale
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Philippe Hassig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentsdb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ description: Report Rails application metrics to OpenTSDB
28
+ email:
29
+ - phil@nine.ch
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - README.md
36
+ - VERSION
37
+ - lib/telltale.rb
38
+ - lib/telltale/railtie.rb
39
+ - telltale.gemspec
40
+ homepage: http://github.com/ninech/
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.4.5.1
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Report Rails application metrics to OpenTSDB
64
+ test_files: []