telegraf 0.7.0 → 2.1.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: 7c8831d93642d86138aba55b26bfcb5d676bf8d223702f74361716dd2bdbf315
4
- data.tar.gz: be3e3b368dbfde682bd1ade3650277119a0302e9d604ebdd920ede401858487c
3
+ metadata.gz: b2ee7281b9a2894ca1b68ad84e14cf0ddaf1668d6203df4173438d8c137048c4
4
+ data.tar.gz: 87b415ca608c3c6d70495f1c7cc013a5720361d68d1baaf86b5366180891d92a
5
5
  SHA512:
6
- metadata.gz: 22d42f69c60e4c75c32e76f01113bc1077cc1111deb12d2949ca21c44d04273d84807632f082d0759aba7ce90659ac8d68fcf4a70ad8e5e7bf7879a727dd31df
7
- data.tar.gz: e4be9374228b344550962c463ae26283404c2f7701876c785c3b5063d937f6e037f7603e387ec5daf6781c799d2715b415ae899213f8eee0c6ce1da8743407e9
6
+ metadata.gz: b5fb0d9e6572edee60f78b3ff9ed6e4345be20fd3440dfdcc5b7b983caaa74ef087014d10395aac65034aac071e7d65e886d3f49ac58e5bb50e69352e1e9199d
7
+ data.tar.gz: c38898a38963a56f148a43a05e9a29ae42072e434ed48c3e741ef2c834940cb2524ede03734ec66078b3c036b52a37f2dfc4059994fc29416e333bc943f14d63
@@ -0,0 +1,68 @@
1
+ # vim: ft=yaml
2
+ name: test
3
+ on: [push, pull_request]
4
+ jobs:
5
+ rspec:
6
+ name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }}
7
+ runs-on: ubuntu-20.04
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby:
12
+ - "3.1"
13
+ - "3.0"
14
+ - "2.7"
15
+ - "2.6"
16
+ - "2.5"
17
+ gemfile:
18
+ - rails_5.2.gemfile
19
+ - rails_6.0.gemfile
20
+ - rails_6.1.gemfile
21
+ - rails_7.0.gemfile
22
+ - rack_2.0.gemfile
23
+ - rack_2.1.gemfile
24
+ - rack_2.2.gemfile
25
+ exclude:
26
+ - ruby: "3.1"
27
+ gemfile: rails_5.2.gemfile
28
+ - ruby: "3.0"
29
+ gemfile: rails_5.2.gemfile
30
+ - ruby: "2.6"
31
+ gemfile: rails_7.0.gemfile
32
+ - ruby: "2.5"
33
+ gemfile: rails_7.0.gemfile
34
+ fail-fast: false
35
+
36
+ env:
37
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
38
+ BUNDLE_WITHOUT: development
39
+ BUNDLE_JOBS: 4
40
+ BUNDLE_RETRY: 3
41
+
42
+ steps:
43
+ - uses: actions/checkout@master
44
+
45
+ - uses: ruby/setup-ruby@v1
46
+ with:
47
+ ruby-version: ${{ matrix.ruby }}
48
+ bundler-cache: true
49
+
50
+ - run: bundle exec rspec --color --format documentation
51
+
52
+ rubocop:
53
+ name: rubocop
54
+ runs-on: ubuntu-20.04
55
+
56
+ env:
57
+ BUNDLE_WITHOUT: development
58
+ BUNDLE_JOBS: 4
59
+ BUNDLE_RETRY: 3
60
+
61
+ steps:
62
+ - uses: actions/checkout@master
63
+ - uses: ruby/setup-ruby@v1
64
+ with:
65
+ ruby-version: 3.0
66
+ bundler-cache: true
67
+
68
+ - run: bundle exec rubocop --parallel --color
data/.rubocop.yml CHANGED
@@ -1,70 +1,11 @@
1
- AllCops:
2
- Include:
3
- - '**/*.rb'
4
- TargetRubyVersion: 2.5
5
-
6
-
7
- Layout/ArgumentAlignment:
8
- EnforcedStyle: with_fixed_indentation
9
-
10
- Layout/CaseIndentation:
11
- EnforcedStyle: end
12
- IndentOneStep: true
13
- SupportedStyles:
14
- - case
15
- - end
16
-
17
- Layout/FirstHashElementIndentation:
18
- EnforcedStyle: consistent
19
-
20
- Layout/LineLength:
21
- Exclude:
22
- - spec/**/*_spec.rb
23
-
24
- Layout/SpaceInsideBlockBraces:
25
- EnforcedStyle: space
26
- EnforcedStyleForEmptyBraces: no_space
27
- SpaceBeforeBlockParameters: false
28
-
29
- Layout/SpaceInsideHashLiteralBraces:
30
- EnforcedStyle: no_space
31
-
32
-
33
- Metrics/AbcSize:
34
- Enabled: false
1
+ # vim: ft=yaml
35
2
 
36
- Metrics/BlockLength:
37
- Exclude:
38
- - spec/**/*_spec.rb
3
+ inherit_gem:
4
+ my-rubocop: default.yml
39
5
 
40
- Metrics/MethodLength:
41
- Enabled: false
42
-
43
-
44
- Naming/FileName:
45
- Exclude:
46
- - Rakefile
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
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+ SuggestExtensions: False
68
9
 
69
- Style/TrivialAccessors:
70
- AllowPredicates: true
10
+ RSpec/FilePath:
11
+ Enabled: False
data/Appraisals CHANGED
@@ -1,29 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "rails-5.0" do
4
- gem "railties", "~> 5.0.0"
3
+ appraise 'rails-5.2' do
4
+ group :test do
5
+ gem 'rails', '~> 5.2.0'
6
+ end
5
7
  end
6
8
 
7
- appraise "rails-5.1" do
8
- gem "railties", "~> 5.1.0"
9
+ appraise 'rails-6.0' do
10
+ group :test do
11
+ gem 'rails', '~> 6.0.0'
12
+ end
9
13
  end
10
14
 
11
- appraise "rails-5.2" do
12
- gem "railties", "~> 5.2.0"
15
+ appraise 'rails-6.1' do
16
+ group :test do
17
+ gem 'rails', '~> 6.1.0'
18
+ end
13
19
  end
14
20
 
15
- appraise "rails-6.0" do
16
- gem "railties", "~> 6.0.0"
21
+ appraise 'rails-7.0' do
22
+ group :test do
23
+ gem 'rails', '~> 7.0.0'
24
+ end
17
25
  end
18
26
 
19
- appraise "rack-2.0" do
20
- gem "rack", "~> 2.0.0"
27
+ appraise 'rack-2.0' do
28
+ group :test do
29
+ gem 'rack', '~> 2.0.0'
30
+ end
21
31
  end
22
32
 
23
- appraise "rack-2.1" do
24
- gem "rack", "~> 2.1.0"
33
+ appraise 'rack-2.1' do
34
+ group :test do
35
+ gem 'rack', '~> 2.1.0'
36
+ end
25
37
  end
26
38
 
27
- appraise "rack-2.2" do
28
- gem "rack", "~> 2.2.0"
39
+ appraise 'rack-2.2' do
40
+ group :test do
41
+ gem 'rack', '~> 2.2.0'
42
+ end
29
43
  end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [2.1.0] - 2022-01-24
10
+ ### Added
11
+ - Support for Rails 7.0 and Ruby 3.1
12
+ - Grape API instrumentation (#17)
13
+
14
+ ## [2.0.0] - 2021-09-30
15
+ ### Changed
16
+ - The sidekiq middleware does not use keyword arguments as sidekiq does not handle them correctly on Ruby 3.0 (#14)
17
+
18
+ ## [1.0.0] - 2021-01-26
19
+ ### Added
20
+ - Global tags (#6)
21
+
22
+ ## [0.8.0] - 2020-12-02
23
+ ### Added
24
+ - ActiveJob instrumentation (#10)
25
+
7
26
  ## [0.7.0] - 2020-05-07
8
27
  ### Added
9
28
  - Sidekiq middleware (#8)
@@ -16,10 +35,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
16
35
  ### Added
17
36
  - New Rack middleware and Rails plugin to collect request events (#5)
18
37
 
19
- ## 0.5.0
38
+ ## 0.5.0 - undefined
20
39
  ### Changed
21
40
  - Remove `influxdb` not unnecessarily restrict users needing a specific influxdb client.
22
41
 
23
- [0.7.0]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.6.1...v0.7.0
24
- [0.6.1]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.6.0...v0.6.1
25
- [0.6.0]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.5.0...v0.6.0
42
+ [Unreleased]: https://github.com/jgraichen/telegraf-ruby/compare/v2.1.0...HEAD
43
+ [2.1.0]: https://github.com/jgraichen/telegraf-ruby/compare/v2.0.0...v2.1.0
44
+ [2.0.0]: https://github.com/jgraichen/telegraf-ruby/compare/v1.0.0...v2.0.0
45
+ [1.0.0]: https://github.com/jgraichen/telegraf-ruby/compare/v0.8.0...v1.0.0
46
+ [0.8.0]: https://github.com/jgraichen/telegraf-ruby/compare/v0.7.0...v0.8.0
47
+ [0.7.0]: https://github.com/jgraichen/telegraf-ruby/compare/v0.6.1...v0.7.0
48
+ [0.6.1]: https://github.com/jgraichen/telegraf-ruby/compare/v0.6.0...v0.6.1
49
+ [0.6.0]: https://github.com/jgraichen/telegraf-ruby/compare/v0.5.0...v0.6.0
data/Gemfile CHANGED
@@ -2,15 +2,20 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'appraisal'
6
- gem 'rake-release', '~> 1.2'
5
+ # Specify your gem's dependencies in telegraf.gemspec
6
+ gemspec
7
+
8
+ gem 'my-rubocop', github: 'jgraichen/my-rubocop', ref: 'v6'
7
9
  gem 'rake'
8
10
  gem 'rspec', '~> 3.8'
9
- gem 'rubocop', '~> 0.80.0'
10
11
 
11
- gem 'rack'
12
- gem 'railties'
13
- gem 'sidekiq', '~> 6.0'
12
+ group :test do
13
+ gem 'rack'
14
+ gem 'rails'
15
+ gem 'sidekiq', '~> 6.0'
16
+ end
14
17
 
15
- # Specify your gem's dependencies in telegraf.gemspec
16
- gemspec
18
+ group :development do
19
+ gem 'appraisal'
20
+ gem 'rake-release', '~> 1.2'
21
+ end
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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
- It further includes plugins for Rack, Rails and Sidekiq to collect request events. See plugin usage details below.
5
+ It further includes plugins for Rack, Rails, ActiveJob and Sidekiq to collect request events. See plugin usage details below.
6
6
 
7
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.
8
8
 
@@ -51,7 +51,7 @@ There is no exception handling.
51
51
 
52
52
  ## Using the Rack and Rails plugins
53
53
 
54
- This gem include a Rails plugin and middlewares for Rack and Sidekiq to collect request events. They need to be explicitly required to be used:
54
+ This gem include a Rails plugin and middlewares / adapters for Rack, ActiveJob and Sidekiq to collect request and background worker events. They need to be explicitly required to be used:
55
55
 
56
56
  ### Rack
57
57
 
@@ -68,22 +68,32 @@ The Rack middleware supports parsing the `X-Request-Start: t=<timestamp>` header
68
68
 
69
69
  ### Rails
70
70
 
71
- The Rails plugin needs to required, too, but by default automatically installs required components (Rack, Sidekiq and Rails-specific instrumentation).
71
+ The Rails plugin needs to be required, too, but will automatically install additional components (Rack, ActiveJob, Sidekiq and Rails-specific instrumentation).
72
72
 
73
73
  ```ruby
74
74
  # e.g. in application.rb
75
75
 
76
+ # Load rails plugin (!) or add `require: 'telegraf/rails'` to Gemfile
76
77
  require "telegraf/rails"
77
78
 
78
79
  class MyApplication > ::Rails::Application
79
80
  # Configure receiver
80
- config.telegraf.connect = "udp://localhost:9084"
81
+ config.telegraf.connect = "udp://localhost:8094"
82
+
83
+ # Global tags added to all events. These will override
84
+ # any local tag with the same name.
85
+ config.telegraf.tags = {}
81
86
 
82
87
  # By default the Rack middleware to collect events is installed
83
88
  config.telegraf.rack.enabled = true
84
89
  config.telegraf.rack.series = "requests"
85
90
  config.telegraf.rack.tags = {}
86
91
 
92
+ # These are the default settings when ActiveJob is detected
93
+ config.telegraf.active_job.enabled = true
94
+ config.telegraf.active_job.series = "active_job"
95
+ config.telegraf.active_job.tags = {}
96
+
87
97
  # These are the default settings when Sidekiq is detected
88
98
  config.telegraf.sidekiq.enabled = true
89
99
  config.telegraf.sidekiq.series = "sidekiq"
@@ -104,8 +114,23 @@ requests,action=index,controller=TestController,instance=TestController#index,me
104
114
  See the various classes' documentation for more details on the collected tags and values:
105
115
  - [Rack middleware](lib/telegraf/rack.rb)
106
116
  - [Rails plugin](lib/telegraf/railtie.rb)
117
+ - [ActiveJob plugin](lib/telegraf/active_job.rb)
107
118
  - [Sidekiq middleware](lib/telegraf/sidekiq.rb)
108
119
 
120
+ ### ActiveJob
121
+
122
+ ```ruby
123
+ require "telegraf/active_job"
124
+
125
+ agent = ::Telegraf::Agent.new
126
+ ActiveSupport::Notifications.subscribe(
127
+ 'perform.active_job',
128
+ Telegraf::ActiveJob.new(agent: agent, series: 'active_job', tags: {global: 'tag'})
129
+ )
130
+ ```
131
+
132
+ See plugin [class documentation](lib/telegraf/active_job.rb) for more details.
133
+
109
134
  ### Sidekiq
110
135
 
111
136
  ```ruby
@@ -114,7 +139,7 @@ require "telegraf/sidekiq"
114
139
  agent = ::Telegraf::Agent.new
115
140
  Sidekiq.configure_server do |config|
116
141
  config.server_middleware do |chain|
117
- chain.add ::Telegraf::Sidekiq::Middleware, agent: agent, series: 'background', tags: {global: 'tag'}
142
+ chain.add ::Telegraf::Sidekiq::Middleware, agent: agent, series: 'sidekiq', tags: {global: 'tag'}
118
143
  end
119
144
  end
120
145
  ```
@@ -2,13 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rake-release", "~> 1.2"
7
5
  gem "rake"
8
6
  gem "rspec", "~> 3.8"
9
- gem "rubocop", "~> 0.80.0"
10
- gem "rack", "~> 2.0.0"
11
- gem "railties"
12
- gem "sidekiq", "~> 6.0"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack", "~> 2.0.0"
12
+ gem "rails"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
13
20
 
14
21
  gemspec path: "../"
@@ -2,13 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rake-release", "~> 1.2"
7
5
  gem "rake"
8
6
  gem "rspec", "~> 3.8"
9
- gem "rubocop", "~> 0.80.0"
10
- gem "rack", "~> 2.1.0"
11
- gem "railties"
12
- gem "sidekiq", "~> 6.0"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack", "~> 2.1.0"
12
+ gem "rails"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
13
20
 
14
21
  gemspec path: "../"
@@ -2,13 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rake-release", "~> 1.2"
7
5
  gem "rake"
8
6
  gem "rspec", "~> 3.8"
9
- gem "rubocop", "~> 0.80.0"
10
- gem "rack", "~> 2.2.0"
11
- gem "railties"
12
- gem "sidekiq", "~> 6.0"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack", "~> 2.2.0"
12
+ gem "rails"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
13
20
 
14
21
  gemspec path: "../"
@@ -2,13 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rake-release", "~> 1.2"
7
5
  gem "rake"
8
6
  gem "rspec", "~> 3.8"
9
- gem "rubocop", "~> 0.80.0"
10
- gem "rack"
11
- gem "railties", "~> 5.2.0"
12
- gem "sidekiq", "~> 6.0"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack"
12
+ gem "rails", "~> 5.2.0"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
13
20
 
14
21
  gemspec path: "../"
@@ -2,13 +2,20 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rake-release", "~> 1.2"
7
5
  gem "rake"
8
6
  gem "rspec", "~> 3.8"
9
- gem "rubocop", "~> 0.80.0"
10
- gem "rack"
11
- gem "railties", "~> 6.0.0"
12
- gem "sidekiq", "~> 6.0"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack"
12
+ gem "rails", "~> 6.0.0"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
13
20
 
14
21
  gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "rspec", "~> 3.8"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack"
12
+ gem "rails", "~> 6.1.0"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "rspec", "~> 3.8"
7
+ gem "rubocop", "~> 1.7"
8
+ gem "rubocop-rspec", "~> 1.41"
9
+
10
+ group :test do
11
+ gem "rack"
12
+ gem "rails", "~> 7.0.0"
13
+ gem "sidekiq", "~> 6.0"
14
+ end
15
+
16
+ group :development do
17
+ gem "appraisal"
18
+ gem "rake-release", "~> 1.2"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegraf
4
+ # Telegraf::ActiveJob
5
+ #
6
+ # This class collects ActiveJob queue metrics and sends them to telegraf.
7
+ #
8
+ #
9
+ # Tags:
10
+ #
11
+ # * `queue`:
12
+ # The queue this job landed on.
13
+ #
14
+ # * `job`:
15
+ # The name of the job class that was executed.
16
+ #
17
+ # * `errors`:
18
+ # Whether or not this job errored.
19
+ #
20
+ #
21
+ # Values:
22
+ #
23
+ # * `app_ms`:
24
+ # Total job processing time.
25
+ #
26
+ class ActiveJob
27
+ def initialize(agent:, series: 'active_job', tags: {})
28
+ @agent = agent
29
+ @series = series.to_s.freeze
30
+ @tags = tags.freeze
31
+ end
32
+
33
+ def call(_name, start, finish, _id, payload)
34
+ job = payload[:job]
35
+
36
+ @agent.write(
37
+ @series,
38
+ tags: {
39
+ **@tags,
40
+ job: job.class.name,
41
+ queue: job.queue_name,
42
+ errors: payload.key?(:exception_object),
43
+ },
44
+ values: {
45
+ app_ms: ((finish - start) * 1000.0), # milliseconds
46
+ },
47
+ )
48
+ end
49
+ end
50
+ end
@@ -4,11 +4,11 @@ module Telegraf
4
4
  class Agent
5
5
  DEFAULT_CONNECTION = 'udp://localhost:8094'
6
6
 
7
- attr_reader :uri
8
- attr_reader :logger
7
+ attr_reader :uri, :logger, :tags
9
8
 
10
- def initialize(uri = nil, logger: nil)
9
+ def initialize(uri = nil, logger: nil, tags: {})
11
10
  @uri = URI.parse(uri || DEFAULT_CONNECTION)
11
+ @tags = tags
12
12
  @logger = logger
13
13
  end
14
14
 
@@ -21,6 +21,8 @@ module Telegraf
21
21
  end
22
22
 
23
23
  def write!(data, series: nil, tags: nil, values: nil)
24
+ tags = tags.merge(@tags) unless @tags.empty?
25
+
24
26
  if values
25
27
  data = [{series: series || data.to_s, tags: tags, values: values}]
26
28
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegraf
4
+ # Telegraf::Grape
5
+ #
6
+ # This class extends requests metrics with details for Grape API endpoints.
7
+ #
8
+ #
9
+ # Tags:
10
+ #
11
+ # * `controller`:
12
+ # The Grape endpoint class.
13
+ #
14
+ # * `instance`:
15
+ # The Grape endpoint class.
16
+ #
17
+ # * `format`:
18
+ # Grape's internal identifier for the response format.
19
+ #
20
+ class Grape
21
+ def call(_name, _start, _finish, _id, payload)
22
+ point = payload[:env][::Telegraf::Rack::FIELD_NAME]
23
+ return unless point
24
+
25
+ endpoint = payload[:endpoint]
26
+ return unless endpoint
27
+
28
+ point.tags[:controller] = endpoint.options[:for].to_s
29
+ point.tags[:instance] = point.tags[:controller]
30
+ point.tags[:format] = payload[:env]['api.format']
31
+ end
32
+ end
33
+ end
data/lib/telegraf/rack.rb CHANGED
@@ -44,7 +44,13 @@ module Telegraf
44
44
  FIELD_NAME = 'telegraf.rack.point'
45
45
  HEADER_REGEX = /t=(\d+(\.\d+)?)/.freeze
46
46
 
47
+ # Warning: `:values` member overrides `Struct#values` and it may be
48
+ # unexpected, but nothing we can change here as this is an import public API
49
+ # right now.
50
+ #
51
+ # rubocop:disable Lint/StructNewOverride
47
52
  Point = Struct.new(:tags, :values)
53
+ # rubocop:enable Lint/StructNewOverride
48
54
 
49
55
  def initialize(app, agent:, series: 'rack', tags: {}, logger: nil)
50
56
  @app = app
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails'
4
+ require 'telegraf'
5
+ require 'telegraf/active_job'
6
+ require 'telegraf/grape'
4
7
  require 'telegraf/rack'
5
8
  require 'telegraf/sidekiq'
6
9
 
@@ -44,6 +47,7 @@ module Telegraf
44
47
 
45
48
  # Connect URI or tuple
46
49
  config.telegraf.connect = ::Telegraf::Agent::DEFAULT_CONNECTION
50
+ config.telegraf.tags = {}
47
51
 
48
52
  # Install Rack middlewares
49
53
  config.telegraf.rack = ::ActiveSupport::OrderedOptions.new
@@ -54,6 +58,16 @@ module Telegraf
54
58
  # Install request instrumentation
55
59
  config.telegraf.instrumentation = true
56
60
 
61
+ # Install Grape instrumentation
62
+ config.telegraf.grape = ::ActiveSupport::OrderedOptions.new
63
+ config.telegraf.grape.enabled = defined?(::Grape)
64
+
65
+ # Install ActiveJob instrumentation
66
+ config.telegraf.active_job = ::ActiveSupport::OrderedOptions.new
67
+ config.telegraf.active_job.enabled = defined?(::ActiveJob)
68
+ config.telegraf.active_job.series = 'active_job'
69
+ config.telegraf.active_job.tags = {}
70
+
57
71
  # Install Sidekiq middleware
58
72
  config.telegraf.sidekiq = ::ActiveSupport::OrderedOptions.new
59
73
  config.telegraf.sidekiq.enabled = defined?(::Sidekiq)
@@ -61,11 +75,11 @@ module Telegraf
61
75
  config.telegraf.sidekiq.tags = {}
62
76
 
63
77
  initializer 'telegraf.agent' do |app|
64
- app.config.telegraf.agent ||= begin
78
+ app.config.telegraf.agent ||= \
65
79
  ::Telegraf::Agent.new \
66
80
  app.config.telegraf.connect,
67
- logger: Rails.logger
68
- end
81
+ logger: Rails.logger,
82
+ tags: app.config.telegraf.tags
69
83
  end
70
84
 
71
85
  initializer 'telegraf.rack' do |app|
@@ -82,7 +96,7 @@ module Telegraf
82
96
  next unless app.config.telegraf.instrumentation
83
97
 
84
98
  ActiveSupport::Notifications.subscribe(
85
- 'process_action.action_controller'
99
+ 'process_action.action_controller',
86
100
  ) do |_name, start, finish, _id, payload|
87
101
  point = payload[:headers].env[::Telegraf::Rack::FIELD_NAME]
88
102
  next unless point
@@ -98,15 +112,39 @@ module Telegraf
98
112
  end
99
113
  end
100
114
 
115
+ initializer 'telegraf.grape' do |app|
116
+ next unless app.config.telegraf.grape.enabled
117
+
118
+ ActiveSupport::Notifications.subscribe(
119
+ 'endpoint_run.grape',
120
+ Telegraf::Grape.new,
121
+ )
122
+ end
123
+
124
+ initializer 'telegraf.active_job' do |app|
125
+ next unless app.config.telegraf.active_job.enabled
126
+
127
+ ActiveSupport::Notifications.subscribe(
128
+ 'perform.active_job',
129
+ Telegraf::ActiveJob.new(
130
+ agent: app.config.telegraf.agent,
131
+ series: app.config.telegraf.active_job.series,
132
+ tags: app.config.telegraf.active_job.tags,
133
+ ),
134
+ )
135
+ end
136
+
101
137
  initializer 'telegraf.sidekiq' do |app|
102
138
  next unless app.config.telegraf.sidekiq.enabled
103
139
 
104
140
  ::Sidekiq.configure_server do |config|
105
141
  config.server_middleware do |chain|
106
142
  chain.add Telegraf::Sidekiq::Middleware, \
107
- agent: app.config.telegraf.agent,
108
- series: app.config.telegraf.sidekiq.series,
109
- tags: app.config.telegraf.sidekiq.tags
143
+ app.config.telegraf.agent,
144
+ {
145
+ series: app.config.telegraf.sidekiq.series,
146
+ tags: app.config.telegraf.sidekiq.tags,
147
+ }
110
148
  end
111
149
  end
112
150
  end
@@ -37,10 +37,10 @@ module Telegraf
37
37
  # Only present for "normal" (async) jobs (with tag `type` of "job").
38
38
  #
39
39
  class Middleware
40
- def initialize(agent:, series: 'sidekiq', tags: {})
40
+ def initialize(agent, options = {})
41
41
  @agent = agent
42
- @series = series.to_s.freeze
43
- @tags = tags.freeze
42
+ @series = options.fetch(:series, 'sidekiq').to_str.freeze
43
+ @tags = options.fetch(:tags, {}).to_hash.freeze
44
44
  end
45
45
 
46
46
  def call(worker, job, queue)
@@ -52,11 +52,11 @@ module Telegraf
52
52
  errors: true,
53
53
  retry: job.key?('retried_at'),
54
54
  queue: queue,
55
- worker: worker.class.name
55
+ worker: worker.class.name,
56
56
  }
57
57
 
58
58
  values = {
59
- retry_count: job['retry_count']
59
+ retry_count: job['retry_count'],
60
60
  }.compact
61
61
 
62
62
  # The "enqueued_at" key is not present for scheduled jobs.
@@ -80,7 +80,7 @@ module Telegraf
80
80
  values[:app_ms] = (job_stop - job_start) * 1000 # milliseconds
81
81
 
82
82
  @agent.write(
83
- @series, tags: tags, values: values
83
+ @series, tags: tags, values: values,
84
84
  )
85
85
  end
86
86
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Telegraf
4
4
  module VERSION
5
- MAJOR = 0
6
- MINOR = 7
5
+ MAJOR = 2
6
+ MINOR = 1
7
7
  PATCH = 0
8
8
  STAGE = nil
9
- STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
9
+ STRING = [MAJOR, MINOR, PATCH, STAGE].compact.join('.').freeze
10
10
 
11
11
  def self.to_s
12
12
  STRING
data/telegraf.gemspec CHANGED
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'telegraf/version'
7
6
 
@@ -13,9 +12,13 @@ Gem::Specification.new do |spec|
13
12
 
14
13
  spec.summary = 'Metric Reporter to local telegraf agent'
15
14
  spec.description = 'Metric Reporter to local telegraf agent'
16
- spec.homepage = 'https://github.com/jgraichen/ruby-telegraf'
15
+ spec.homepage = 'https://github.com/jgraichen/telegraf-ruby'
17
16
  spec.license = 'LGPLv3'
18
17
 
18
+ spec.metadata = {
19
+ 'rubygems_mfa_required' => 'true',
20
+ }
21
+
19
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
23
  f.match(%r{^(test|spec|features)/})
21
24
  end
@@ -24,7 +27,7 @@ Gem::Specification.new do |spec|
24
27
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
25
28
  spec.require_paths = ['lib']
26
29
 
30
+ spec.required_ruby_version = '>= 2.5'
27
31
  spec.add_dependency 'influxdb'
28
-
29
32
  spec.add_development_dependency 'bundler'
30
33
  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.7.0
4
+ version: 2.1.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: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb
@@ -46,10 +46,10 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".editorconfig"
49
+ - ".github/workflows/test.yml"
49
50
  - ".gitignore"
50
51
  - ".rspec"
51
52
  - ".rubocop.yml"
52
- - ".travis.yml"
53
53
  - Appraisals
54
54
  - CHANGELOG.md
55
55
  - Gemfile
@@ -61,22 +61,25 @@ files:
61
61
  - gemfiles/rack_2.0.gemfile
62
62
  - gemfiles/rack_2.1.gemfile
63
63
  - gemfiles/rack_2.2.gemfile
64
- - gemfiles/rails_5.0.gemfile
65
- - gemfiles/rails_5.1.gemfile
66
64
  - gemfiles/rails_5.2.gemfile
67
65
  - gemfiles/rails_6.0.gemfile
66
+ - gemfiles/rails_6.1.gemfile
67
+ - gemfiles/rails_7.0.gemfile
68
68
  - lib/telegraf.rb
69
+ - lib/telegraf/active_job.rb
69
70
  - lib/telegraf/agent.rb
71
+ - lib/telegraf/grape.rb
70
72
  - lib/telegraf/rack.rb
71
73
  - lib/telegraf/rails.rb
72
74
  - lib/telegraf/railtie.rb
73
75
  - lib/telegraf/sidekiq.rb
74
76
  - lib/telegraf/version.rb
75
77
  - telegraf.gemspec
76
- homepage: https://github.com/jgraichen/ruby-telegraf
78
+ homepage: https://github.com/jgraichen/telegraf-ruby
77
79
  licenses:
78
80
  - LGPLv3
79
- metadata: {}
81
+ metadata:
82
+ rubygems_mfa_required: 'true'
80
83
  post_install_message:
81
84
  rdoc_options: []
82
85
  require_paths:
@@ -85,14 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
88
  requirements:
86
89
  - - ">="
87
90
  - !ruby/object:Gem::Version
88
- version: '0'
91
+ version: '2.5'
89
92
  required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  requirements:
91
94
  - - ">="
92
95
  - !ruby/object:Gem::Version
93
96
  version: '0'
94
97
  requirements: []
95
- rubygems_version: 3.0.8
98
+ rubygems_version: 3.1.6
96
99
  signing_key:
97
100
  specification_version: 4
98
101
  summary: Metric Reporter to local telegraf agent
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- sudo: false
2
- dist: bionic
3
- language: ruby
4
- rvm:
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
@@ -1,14 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
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
- gem "rack"
11
- gem "railties", "~> 5.0.0"
12
- gem "sidekiq", "~> 6.0"
13
-
14
- gemspec path: "../"
@@ -1,14 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
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
- gem "rack"
11
- gem "railties", "~> 5.1.0"
12
- gem "sidekiq", "~> 6.0"
13
-
14
- gemspec path: "../"