telegraf 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d53dac00d7d4f119abfbc7b5f15990d60b23416da600e50044e47253c6562c58
4
- data.tar.gz: 1fc9a85ac74357802a3dbf6b46ab935022bf42d0d2956ffdbe535b31fc76f9ba
3
+ metadata.gz: d501a16edd1b0af99d19d3c0ac5c1453f0a837b77d7094d93ffcbbf07c143bf7
4
+ data.tar.gz: f7d84a788ddb2411742287c1873e959e5c663394832c0f230fe9ab026fd96425
5
5
  SHA512:
6
- metadata.gz: ec13d880ebfaa1c3373a55bafa829d443e8c449ae13f8fbab610d1dbb1d3fb1f1c8519d75a56218d7306b5e9cd64ae6b9f2f8c0be26fbc5ae0aac61e510da145
7
- data.tar.gz: 4bdab197198995e62ae1f144c0aa663895b05cb5e695d7620dc642c3500dce0af23b8278d694a7fa124af2f3f11a08bd94ac1bb7182bd9ab3bfefc949b4a8ba2
6
+ metadata.gz: 298872956e93bd707e1e0912f96447aaab0c211a855d5ed56367b085754c99dafe1a3c4562e25867c3c527a09e4c77d23f91e055cba37abbbcc7f24d46d09be8
7
+ data.tar.gz: 0ed1a9016a9fca1e6f478de124896ce633c6ff07de54510626ce609e266c1b87c348ff8ff1db80599e07f6fb199aaaa2d13a4b181a384e69dd303d871a730d24
@@ -0,0 +1,8 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
data/.gitignore CHANGED
@@ -1,9 +1,12 @@
1
+ /_yardoc/
1
2
  /.bundle/
2
3
  /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
4
  /coverage/
6
5
  /doc/
6
+ /Gemfile.lock
7
+ /gemfiles/.bundle/
8
+ /gemfiles/*.lock
9
+ /log/
7
10
  /pkg/
8
11
  /spec/reports/
9
12
  /tmp/
@@ -1,53 +1,70 @@
1
1
  AllCops:
2
2
  Include:
3
3
  - '**/*.rb'
4
- TargetRubyVersion: 2.4
4
+ TargetRubyVersion: 2.5
5
5
 
6
- Metrics/BlockLength:
7
- Exclude:
8
- - 'spec/**/*_spec.rb'
9
-
10
- Metrics/LineLength:
11
- Exclude:
12
- - 'spec/**/*_spec.rb'
13
6
 
14
- Style/AlignParameters:
7
+ Layout/ArgumentAlignment:
15
8
  EnforcedStyle: with_fixed_indentation
16
9
 
17
- Style/BracesAroundHashParameters:
18
- EnforcedStyle: context_dependent
19
-
20
- Style/SpaceInsideHashLiteralBraces:
21
- EnforcedStyle: no_space
10
+ Layout/CaseIndentation:
11
+ EnforcedStyle: end
12
+ IndentOneStep: true
13
+ SupportedStyles:
14
+ - case
15
+ - end
22
16
 
23
- Style/RaiseArgs:
24
- EnforcedStyle: compact
17
+ Layout/FirstHashElementIndentation:
18
+ EnforcedStyle: consistent
25
19
 
26
- Style/Documentation:
27
- Enabled: false
20
+ Layout/LineLength:
21
+ Exclude:
22
+ - spec/**/*_spec.rb
28
23
 
29
- Style/SpaceInsideBlockBraces:
24
+ Layout/SpaceInsideBlockBraces:
30
25
  EnforcedStyle: space
31
26
  EnforcedStyleForEmptyBraces: no_space
32
27
  SpaceBeforeBlockParameters: false
33
28
 
34
- Style/SignalException:
35
- EnforcedStyle: only_raise
29
+ Layout/SpaceInsideHashLiteralBraces:
30
+ EnforcedStyle: no_space
36
31
 
37
- Style/CaseIndentation:
38
- EnforcedStyle: end
39
- SupportedStyles:
40
- - case
41
- - end
42
- IndentOneStep: true
43
32
 
44
- Style/ClassAndModuleChildren:
33
+ Metrics/AbcSize:
34
+ Enabled: false
35
+
36
+ Metrics/BlockLength:
37
+ Exclude:
38
+ - spec/**/*_spec.rb
39
+
40
+ Metrics/MethodLength:
45
41
  Enabled: false
46
42
 
47
- Style/TrivialAccessors:
48
- AllowPredicates: true
49
43
 
50
- Style/FileName:
44
+ Naming/FileName:
51
45
  Exclude:
52
46
  - Rakefile
53
47
  - Gemfile
48
+
49
+
50
+ Style/ClassAndModuleChildren:
51
+ Enabled: false
52
+
53
+ Style/Documentation:
54
+ Enabled: false
55
+
56
+ Style/HashEachMethods:
57
+ Enabled: false
58
+
59
+ Style/HashTransformKeys:
60
+ Enabled: false
61
+
62
+ Style/HashTransformValues:
63
+ Enabled: false
64
+
65
+ Style/RescueModifier:
66
+ Exclude:
67
+ - spec/**/*_spec.rb
68
+
69
+ Style/TrivialAccessors:
70
+ AllowPredicates: true
@@ -1,24 +1,15 @@
1
1
  sudo: false
2
- dist: trusty
2
+ dist: bionic
3
3
  language: ruby
4
4
  rvm:
5
- - 2.5.1
6
- - 2.4.4
7
- - 2.3.7
8
- before_install:
9
- - gem install bundler
10
-
11
- jobs:
12
- include:
13
- - stage: Release
14
- rvm: 2.5.1
15
- script: skip
16
- install: skip
17
- deploy:
18
- provider: rubygems
19
- api_key:
20
- secure: CcUafYaGbfw8OqiCGEr2vqcGeb16FtpUsL8y6jTz4rWKJbWpt5HZL9GBw5vr+bhS8b4vOySVfWhR9GkHB0Z8q36GDh5Y1Rmh6OZKdN3PQs/ACH9pP0BL9jxrNcZWdsEttGaUjrZzgCNwZKs21BUiTpWUSuUMhQuSU03GmPqpTaX8NZyBrIIX8UpqHjtJ1+y3BfJkuUPc07JDPLfQVvz7/Np/5UdMJ7DEec7lipGXXA/R8VbOL6f+NP6kf6EHunEH0BWbWWmonIybdvYX0T9lSa6ajr+SQx1oD29HUdQUwspDAlsUKkNm4nfpp6Wwznt11SYMJFLKOH6RycNtENTakXaG3C7RH5XFkHACSs/c0LQdCmdkJCv27PC0rYUrnyfYv+5p6kCh0GJoM/e5eTlyborhdOF97GlVcHe/vmTfSjOW2UaXRwpaM9b2s7SMkURiGVoYnXlq0GM+98Tp1qR7c/AFjzrpfSXxyFXQRiycILaRt2bdA9ySbkfxD3gz0hkjrjuclSa+Oxn/ufsDt56FklDftZpQUI4+ydhhxh6VdG3Hr8mQezuc+3u+z6HYPjoVbccHkQb3YjuIj2wUF6tICaO9voYIRsxtMaG1R0pDBMTjfmWzbJF6nhtZrigwC31e0fqen3LmXuWK8I6pk/TgCEdYXn8aaDqEC+WsRWGZkMY=
21
- gem: telegraf
22
- on:
23
- tags: true
24
- repo: jgraichen/telegraf-ruby
5
+ - 2.7.0
6
+ - 2.6.5
7
+ - 2.5.7
8
+ gemfile:
9
+ - gemfiles/rails_5.0.gemfile
10
+ - gemfiles/rails_5.1.gemfile
11
+ - gemfiles/rails_5.2.gemfile
12
+ - gemfiles/rails_6.0.gemfile
13
+ - gemfiles/rack_2.0.gemfile
14
+ - gemfiles/rack_2.1.gemfile
15
+ - gemfiles/rack_2.2.gemfile
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "rails-5.0" do
4
+ gem "railties", "~> 5.0.0"
5
+ end
6
+
7
+ appraise "rails-5.1" do
8
+ gem "railties", "~> 5.1.0"
9
+ end
10
+
11
+ appraise "rails-5.2" do
12
+ gem "railties", "~> 5.2.0"
13
+ end
14
+
15
+ appraise "rails-6.0" do
16
+ gem "railties", "~> 6.0.0"
17
+ end
18
+
19
+ appraise "rack-2.0" do
20
+ gem "rack", "~> 2.0.0"
21
+ end
22
+
23
+ appraise "rack-2.1" do
24
+ gem "rack", "~> 2.1.0"
25
+ end
26
+
27
+ appraise "rack-2.2" do
28
+ gem "rack", "~> 2.2.0"
29
+ end
@@ -1,6 +1,18 @@
1
1
  # Changelog
2
+ All notable changes to this project will be documented in this file.
2
3
 
3
- ## 0.5.0
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
4
8
 
5
- * Remove `influxdb` not unnecessarily restrict users needing a specific influxdb client.
9
+ ## [0.6.0] - 2020-03-31
10
+ ### Added
11
+ - New Rack middleware and Rails plugin to collect request events (#5)
12
+
13
+ ## 0.5.0
14
+ ### Changed
15
+ - Remove `influxdb` not unnecessarily restrict users needing a specific influxdb client.
6
16
 
17
+ [unreleased]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.6.0...HEAD
18
+ [0.6.0]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.5.0...v0.6.0
data/Gemfile CHANGED
@@ -2,5 +2,14 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ gem 'appraisal'
6
+ gem 'rake-release', '~> 1.2'
7
+ gem 'rake'
8
+ gem 'rspec', '~> 3.8'
9
+ gem 'rubocop', '~> 0.80.0'
10
+
11
+ gem 'rack'
12
+ gem 'railties'
13
+
5
14
  # Specify your gem's dependencies in telegraf.gemspec
6
15
  gemspec
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Telegraf
2
2
 
3
- Minimal gem to send metrics to a local telegraf agent.
3
+ Send events to a local [Telegraf](https://github.com/influxdata/telegraf) agent or anything that can receive the InfluxDB line protocol.
4
4
 
5
- This gem only uses the line protocol from the `influxdb` gem and does not depend on a specific version. This may break in the future but does not restrict you in using a your preferred `influxdb` version.
5
+ It further includes plugins for Rack and Rails to collect request events. See plugin usage details below.
6
+
7
+ This gem only uses the line protocol from the `influxdb` gem and does not depend on any specific version. This may break in the future but does not restrict you in using a your preferred `influxdb` gem version.
6
8
 
7
9
  ## Installation
8
10
 
@@ -18,7 +20,7 @@ Or install it yourself as:
18
20
 
19
21
  $ gem install telegraf
20
22
 
21
- ## Usage
23
+ ## Usage as a library
22
24
 
23
25
  Configure telegraf socket listener e.g.:
24
26
 
@@ -47,9 +49,58 @@ There is not buffer or batch handling, nor connection pooling or keep alive. Eac
47
49
 
48
50
  There is no exception handling.
49
51
 
52
+ ## Using the Rack and Rails plugins
53
+
54
+ This gem include a Rails plugin and a rack middleware to collect request events. They need to be explicitly required to be used:
55
+
56
+ ### Rack
57
+
58
+ ```ruby
59
+ require "telegraf/rack"
60
+
61
+ agent = ::Telegraf::Agent.new
62
+ use ::Telegraf::Rack.new(series: 'rack', agent: agent, tags: {global: 'tag'})
63
+ ```
64
+
65
+ See middleware [class documentation](lib/telegraf/rack.rb) for more details.
66
+
67
+ The Rack middleware supports parsing the `X-Request-Start: t=<timestamp>` header expecting a fractional (UTC) timestamp when the request has been started or first received by e.g. a load balancer. An additional value `queue_ms` with the queue time will be included.
68
+
69
+ ### Rails
70
+
71
+ The Rails plugin needs to required too but by default automatically installs required components.
72
+
73
+ ```ruby
74
+ # e.g. in application.rb
75
+
76
+ require "telegraf/rails"
77
+
78
+ class MyApplication > ::Rails::Application
79
+ # Configure receiver
80
+ config.telegraf.connect = "udp://localhost:9084"
81
+
82
+ # By default the Rack middleware to collect events is installed
83
+ config.telegraf.rack.enabled = true
84
+ config.telegraf.rack.series = "requests"
85
+ config.telegraf.rack.tags = {}
86
+
87
+ # Additionally the application is instrumented to tag events with
88
+ # controller and action as well as to collect app, database and view timings
89
+ config.telegraf.instrumenation = true
90
+ end
91
+ ```
92
+
93
+ Received event example:
94
+
95
+ ```
96
+ requests,action=index,controller=TestController,instance=TestController#index,method=GET,status=200 db_ms=0.0,view_ms=2.6217450003969134,action_ms=2.702335,app_ms=4.603561000294576,send_ms=0.09295000018028077,request_ms=4.699011000411701,queue_ms=0.00003000028323014
97
+ ```
98
+
99
+ See the rack middleware [class documentation](lib/telegraf/rack.rb) and the Rails plugin [class documentation](lib/telegraf/railtie.rb) for more details on the collected tags and values.
100
+
50
101
  ## License
51
102
 
52
- Copyright (C) 2017 Jan Graichen
103
+ Copyright (C) 2017-2020 Jan Graichen
53
104
 
54
105
  This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
55
106
 
data/Rakefile CHANGED
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
3
+ require 'rake/release/task'
4
4
  require 'rspec/core/rake_task'
5
5
 
6
+ Rake::Release::Task.new do |spec|
7
+ spec.sign_tag = true
8
+ end
9
+
6
10
  RSpec::Core::RakeTask.new(:spec)
7
11
 
8
12
  task default: :spec
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack", "~> 2.0.0"
10
+ gem "railties"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack", "~> 2.1.0"
10
+ gem "railties"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack", "~> 2.2.0"
10
+ gem "railties"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack"
10
+ gem "railties", "~> 5.0.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack"
10
+ gem "railties", "~> 5.1.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack"
10
+ gem "railties", "~> 5.2.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "~> 0.80.0"
6
+ gem "rake"
7
+ gem "rspec", "~> 3.8"
8
+ gem "appraisal"
9
+ gem "rack"
10
+ gem "railties", "~> 6.0.0"
11
+
12
+ gemspec path: "../"
@@ -2,19 +2,19 @@
2
2
 
3
3
  module Telegraf
4
4
  class Agent
5
- DEFAULT_URI = 'udp://localhost:8094'
5
+ DEFAULT_CONNECTION = 'udp://localhost:8094'
6
6
 
7
7
  attr_reader :uri
8
8
  attr_reader :logger
9
9
 
10
- def initialize(uri = DEFAULT_CONNECTION, logger: nil)
11
- @uri = URI.parse(uri)
10
+ def initialize(uri = nil, logger: nil)
11
+ @uri = URI.parse(uri || DEFAULT_CONNECTION)
12
12
  @logger = logger
13
13
  end
14
14
 
15
- def write(*args)
16
- write!(*args)
17
- rescue => e
15
+ def write(*args, **kwargs)
16
+ write!(*args, **kwargs)
17
+ rescue StandardError => e
18
18
  logger&.error('telegraf') do
19
19
  e.to_s + e.backtrace.join("\n")
20
20
  end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module Telegraf
6
+ # Telegraf::Rack
7
+ #
8
+ # This rack middleware collects request metrics and sends them to the telegraf
9
+ # agent. A `Point` data structure is added to the Rack environment to assign
10
+ # custom tags and values. This point can be accessed using the environment key
11
+ # defined in `::Telegraf::Rack::FIELD_NAME`.
12
+ #
13
+ # Example:
14
+ #
15
+ # if (point = request.env[::Telegraf::Rack::FIELD_NAME])
16
+ # point.tags[:tag] = 'tag'
17
+ # point.values[:value] = 10
18
+ # end
19
+ #
20
+ #
21
+ # Tags:
22
+ #
23
+ # * `status`:
24
+ # Response status unless request errored
25
+ #
26
+ #
27
+ # Values:
28
+ #
29
+ # * `request_ms`:
30
+ # Total request processing time including response sending.
31
+ #
32
+ # * `app_ms`:
33
+ # Total application processing time.
34
+ #
35
+ # * `send_ms`:
36
+ # Time took to send the response body.
37
+ #
38
+ # * `queue_ms`:
39
+ # Queue time calculated from a `X-Request-Start` header if present. The
40
+ # header is expected to be formatted like this `t=<timestamp>` and
41
+ # contain a floating point timestamp in seconds.
42
+ #
43
+ class Rack
44
+ FIELD_NAME = 'telegraf.rack.point'
45
+ HEADER_REGEX = /t=(\d+(\.\d+)?)/.freeze
46
+
47
+ Point = Struct.new(:tags, :values)
48
+
49
+ def initialize(app, agent:, series: 'rack', tags: {}, logger: nil)
50
+ @app = app
51
+ @tags = tags.freeze
52
+ @agent = agent
53
+ @series = series.to_s.freeze
54
+ @logger = logger
55
+ end
56
+
57
+ def call(env)
58
+ if (request_start = extract_request_start(env))
59
+ queue_ms = (::Time.now.utc - request_start) * 1000 # milliseconds
60
+ end
61
+
62
+ rack_start = ::Rack::Utils.clock_time
63
+ point = env[FIELD_NAME] = Point.new(@tags.dup, {})
64
+ point.values[:queue_ms] = queue_ms if queue_ms
65
+
66
+ begin
67
+ begin
68
+ status, headers, body = @app.call(env)
69
+ ensure
70
+ point.tags[:status] ||= status || -1
71
+ point.values[:app_ms] = \
72
+ (::Rack::Utils.clock_time - rack_start) * 1000 # milliseconds
73
+ end
74
+
75
+ send_start = ::Rack::Utils.clock_time
76
+ proxy = ::Rack::BodyProxy.new(body) do
77
+ point.values[:send_ms] = \
78
+ (::Rack::Utils.clock_time - send_start) * 1000 # milliseconds
79
+
80
+ finish(env, point, rack_start)
81
+ end
82
+
83
+ [status, headers, proxy]
84
+ ensure
85
+ finish(env, point, rack_start) unless proxy
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def finish(env, point, rack_start)
92
+ point.values[:request_ms] = \
93
+ (::Rack::Utils.clock_time - rack_start) * 1000 # milliseconds
94
+
95
+ @agent.write(@series, tags: point.tags, values: point.values)
96
+ rescue StandardError => e
97
+ (@logger || env[::Rack::RACK_LOGGER])&.error(e)
98
+ end
99
+
100
+ def extract_request_start(env)
101
+ return unless env.key?('HTTP_X_REQUEST_START')
102
+
103
+ if (m = HEADER_REGEX.match(env['HTTP_X_REQUEST_START']))
104
+ ::Time.at(m[1].to_f).utc
105
+ end
106
+ rescue FloatDomainError
107
+ # Ignore obscure floats in Time.at (e.g. infinity)
108
+ false
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'telegraf/railtie'
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+ require 'telegraf/rack'
5
+
6
+ module Telegraf
7
+ # Telegraf::Railtie
8
+ #
9
+ # This Rails plugin installs the rack middleware and adds intrumentation to
10
+ # enrich the data point with additional tags an values.
11
+ #
12
+ # These include the following tags:
13
+ #
14
+ # * `action`
15
+ # The controller action, e.g. `index`.
16
+ #
17
+ # * `controller`
18
+ # The controller class name, e.g. `API::UsersController`.
19
+ #
20
+ # * `instance`
21
+ # A combination of the controller class and the action, e.g.
22
+ # `API::UsersController#index`.
23
+ #
24
+ # * `method`
25
+ # The request method, e.g. `GET`.
26
+ #
27
+ # Additional collected values are:
28
+ #
29
+ # * `db_ms`
30
+ # Time spend with database operations in milliseconds.
31
+ #
32
+ # * `view_ms`
33
+ # Time spend with rendering views in milliseconds.
34
+ #
35
+ # * `action_ms`
36
+ # Total time spend in a Rails action in milliseconds.
37
+ #
38
+ # These additional tags and values are collection from the
39
+ # `process_action.action_controller` events usings Rails instrumentation.
40
+ #
41
+ class Railtie < ::Rails::Railtie
42
+ config.telegraf = ::ActiveSupport::OrderedOptions.new
43
+
44
+ # Connect URI or tuple
45
+ config.telegraf.connect = ::Telegraf::Agent::DEFAULT_CONNECTION
46
+
47
+ # Install rackmiddlewares
48
+ config.telegraf.rack = ::ActiveSupport::OrderedOptions.new
49
+ config.telegraf.rack.enabled = true
50
+ config.telegraf.rack.series = 'requests'
51
+ config.telegraf.rack.tags = {}
52
+
53
+ # Install request instrumentation
54
+ config.telegraf.instrumenation = true
55
+
56
+ initializer 'telegraf.agent' do |app|
57
+ app.config.telegraf.agent ||= begin
58
+ ::Telegraf::Agent.new \
59
+ app.config.telegraf.connect,
60
+ logger: Rails.logger
61
+ end
62
+ end
63
+
64
+ initializer 'telegraf.rack' do |app|
65
+ next unless app.config.telegraf.rack.enabled
66
+
67
+ app.config.middleware.insert 0, Telegraf::Rack, \
68
+ agent: app.config.telegraf.agent,
69
+ series: app.config.telegraf.rack.series,
70
+ tags: app.config.telegraf.rack.tags,
71
+ logger: Rails.logger
72
+ end
73
+
74
+ initializer 'telegraf.instrumentation' do |app|
75
+ next unless app.config.telegraf.instrumenation
76
+
77
+ ActiveSupport::Notifications.subscribe(
78
+ 'process_action.action_controller'
79
+ ) do |_name, start, finish, _id, payload|
80
+ point = payload[:headers].env[::Telegraf::Rack::FIELD_NAME]
81
+ next unless point
82
+
83
+ point.tags[:action] = payload[:action]
84
+ point.tags[:controller] = payload[:controller]
85
+ point.tags[:instance] = "#{payload[:controller]}##{payload[:action]}"
86
+ point.tags[:method] = payload[:method]
87
+
88
+ point.values[:db_ms] = payload[:db_runtime].to_f
89
+ point.values[:view_ms] = payload[:view_runtime].to_f
90
+ point.values[:action_ms] = ((finish - start) * 1000.0) # milliseconds
91
+ end
92
+ end
93
+ end
94
+ end
@@ -3,7 +3,7 @@
3
3
  module Telegraf
4
4
  module VERSION
5
5
  MAJOR = 0
6
- MINOR = 5
6
+ MINOR = 6
7
7
  PATCH = 0
8
8
  STAGE = nil
9
9
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
@@ -26,7 +26,5 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency 'influxdb'
28
28
 
29
- spec.add_development_dependency 'bundler', '~> 1.15'
30
- spec.add_development_dependency 'rake', '~> 12.0'
31
- spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'bundler'
32
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegraf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb
@@ -28,44 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.15'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.15'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '12.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '12.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
31
+ - - ">="
60
32
  - !ruby/object:Gem::Version
61
- version: '3.0'
33
+ version: '0'
62
34
  type: :development
63
35
  prerelease: false
64
36
  version_requirements: !ruby/object:Gem::Requirement
65
37
  requirements:
66
- - - "~>"
38
+ - - ">="
67
39
  - !ruby/object:Gem::Version
68
- version: '3.0'
40
+ version: '0'
69
41
  description: Metric Reporter to local telegraf agent
70
42
  email:
71
43
  - jgraichen@altimos.de
@@ -73,10 +45,12 @@ executables: []
73
45
  extensions: []
74
46
  extra_rdoc_files: []
75
47
  files:
48
+ - ".editorconfig"
76
49
  - ".gitignore"
77
50
  - ".rspec"
78
51
  - ".rubocop.yml"
79
52
  - ".travis.yml"
53
+ - Appraisals
80
54
  - CHANGELOG.md
81
55
  - Gemfile
82
56
  - LICENSE
@@ -84,8 +58,18 @@ files:
84
58
  - Rakefile
85
59
  - bin/console
86
60
  - bin/setup
61
+ - gemfiles/rack_2.0.gemfile
62
+ - gemfiles/rack_2.1.gemfile
63
+ - gemfiles/rack_2.2.gemfile
64
+ - gemfiles/rails_5.0.gemfile
65
+ - gemfiles/rails_5.1.gemfile
66
+ - gemfiles/rails_5.2.gemfile
67
+ - gemfiles/rails_6.0.gemfile
87
68
  - lib/telegraf.rb
88
69
  - lib/telegraf/agent.rb
70
+ - lib/telegraf/rack.rb
71
+ - lib/telegraf/rails.rb
72
+ - lib/telegraf/railtie.rb
89
73
  - lib/telegraf/version.rb
90
74
  - telegraf.gemspec
91
75
  homepage: https://github.com/jgraichen/ruby-telegraf
@@ -107,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
91
  - !ruby/object:Gem::Version
108
92
  version: '0'
109
93
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.7.7
94
+ rubygems_version: 3.1.2
112
95
  signing_key:
113
96
  specification_version: 4
114
97
  summary: Metric Reporter to local telegraf agent