telegraf 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -2
- data/Gemfile +1 -0
- data/README.md +28 -4
- data/gemfiles/rack_2.0.gemfile +4 -2
- data/gemfiles/rack_2.1.gemfile +4 -2
- data/gemfiles/rack_2.2.gemfile +4 -2
- data/gemfiles/rails_5.0.gemfile +4 -2
- data/gemfiles/rails_5.1.gemfile +4 -2
- data/gemfiles/rails_5.2.gemfile +4 -2
- data/gemfiles/rails_6.0.gemfile +4 -2
- data/lib/telegraf/railtie.rb +21 -1
- data/lib/telegraf/sidekiq.rb +89 -0
- data/lib/telegraf/version.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c8831d93642d86138aba55b26bfcb5d676bf8d223702f74361716dd2bdbf315
|
4
|
+
data.tar.gz: be3e3b368dbfde682bd1ade3650277119a0302e9d604ebdd920ede401858487c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d42f69c60e4c75c32e76f01113bc1077cc1111deb12d2949ca21c44d04273d84807632f082d0759aba7ce90659ac8d68fcf4a70ad8e5e7bf7879a727dd31df
|
7
|
+
data.tar.gz: e4be9374228b344550962c463ae26283404c2f7701876c785c3b5063d937f6e037f7603e387ec5daf6781c799d2715b415ae899213f8eee0c6ce1da8743407e9
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,9 @@ 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
|
-
## [
|
7
|
+
## [0.7.0] - 2020-05-07
|
8
|
+
### Added
|
9
|
+
- Sidekiq middleware (#8)
|
8
10
|
|
9
11
|
## [0.6.1] - 2020-04-01
|
10
12
|
### Fixed
|
@@ -18,6 +20,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
18
20
|
### Changed
|
19
21
|
- Remove `influxdb` not unnecessarily restrict users needing a specific influxdb client.
|
20
22
|
|
21
|
-
[
|
23
|
+
[0.7.0]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.6.1...v0.7.0
|
22
24
|
[0.6.1]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.6.0...v0.6.1
|
23
25
|
[0.6.0]: https://github.com/:jgraichen/telegraf-ruby/compare/v0.5.0...v0.6.0
|
data/Gemfile
CHANGED
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 and
|
5
|
+
It further includes plugins for Rack, Rails 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
|
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:
|
55
55
|
|
56
56
|
### Rack
|
57
57
|
|
@@ -68,7 +68,7 @@ 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.
|
71
|
+
The Rails plugin needs to required, too, but by default automatically installs required components (Rack, Sidekiq and Rails-specific instrumentation).
|
72
72
|
|
73
73
|
```ruby
|
74
74
|
# e.g. in application.rb
|
@@ -84,6 +84,11 @@ class MyApplication > ::Rails::Application
|
|
84
84
|
config.telegraf.rack.series = "requests"
|
85
85
|
config.telegraf.rack.tags = {}
|
86
86
|
|
87
|
+
# These are the default settings when Sidekiq is detected
|
88
|
+
config.telegraf.sidekiq.enabled = true
|
89
|
+
config.telegraf.sidekiq.series = "sidekiq"
|
90
|
+
config.telegraf.sidekiq.tags = {}
|
91
|
+
|
87
92
|
# Additionally the application is instrumented to tag events with
|
88
93
|
# controller and action as well as to collect app, database and view timings
|
89
94
|
config.telegraf.instrumentation = true
|
@@ -96,7 +101,26 @@ Received event example:
|
|
96
101
|
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
102
|
```
|
98
103
|
|
99
|
-
See the
|
104
|
+
See the various classes' documentation for more details on the collected tags and values:
|
105
|
+
- [Rack middleware](lib/telegraf/rack.rb)
|
106
|
+
- [Rails plugin](lib/telegraf/railtie.rb)
|
107
|
+
- [Sidekiq middleware](lib/telegraf/sidekiq.rb)
|
108
|
+
|
109
|
+
### Sidekiq
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
require "telegraf/sidekiq"
|
113
|
+
|
114
|
+
agent = ::Telegraf::Agent.new
|
115
|
+
Sidekiq.configure_server do |config|
|
116
|
+
config.server_middleware do |chain|
|
117
|
+
chain.add ::Telegraf::Sidekiq::Middleware, agent: agent, series: 'background', tags: {global: 'tag'}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
See middleware [class documentation](lib/telegraf/sidekiq.rb) for more details.
|
123
|
+
|
100
124
|
|
101
125
|
## License
|
102
126
|
|
data/gemfiles/rack_2.0.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack", "~> 2.0.0"
|
10
11
|
gem "railties"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/gemfiles/rack_2.1.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack", "~> 2.1.0"
|
10
11
|
gem "railties"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/gemfiles/rack_2.2.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack", "~> 2.2.0"
|
10
11
|
gem "railties"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/gemfiles/rails_5.0.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack"
|
10
11
|
gem "railties", "~> 5.0.0"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/gemfiles/rails_5.1.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack"
|
10
11
|
gem "railties", "~> 5.1.0"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/gemfiles/rails_5.2.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack"
|
10
11
|
gem "railties", "~> 5.2.0"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/gemfiles/rails_6.0.gemfile
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
5
|
+
gem "appraisal"
|
6
|
+
gem "rake-release", "~> 1.2"
|
6
7
|
gem "rake"
|
7
8
|
gem "rspec", "~> 3.8"
|
8
|
-
gem "
|
9
|
+
gem "rubocop", "~> 0.80.0"
|
9
10
|
gem "rack"
|
10
11
|
gem "railties", "~> 6.0.0"
|
12
|
+
gem "sidekiq", "~> 6.0"
|
11
13
|
|
12
14
|
gemspec path: "../"
|
data/lib/telegraf/railtie.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rails'
|
4
4
|
require 'telegraf/rack'
|
5
|
+
require 'telegraf/sidekiq'
|
5
6
|
|
6
7
|
module Telegraf
|
7
8
|
# Telegraf::Railtie
|
@@ -44,7 +45,7 @@ module Telegraf
|
|
44
45
|
# Connect URI or tuple
|
45
46
|
config.telegraf.connect = ::Telegraf::Agent::DEFAULT_CONNECTION
|
46
47
|
|
47
|
-
# Install
|
48
|
+
# Install Rack middlewares
|
48
49
|
config.telegraf.rack = ::ActiveSupport::OrderedOptions.new
|
49
50
|
config.telegraf.rack.enabled = true
|
50
51
|
config.telegraf.rack.series = 'requests'
|
@@ -53,6 +54,12 @@ module Telegraf
|
|
53
54
|
# Install request instrumentation
|
54
55
|
config.telegraf.instrumentation = true
|
55
56
|
|
57
|
+
# Install Sidekiq middleware
|
58
|
+
config.telegraf.sidekiq = ::ActiveSupport::OrderedOptions.new
|
59
|
+
config.telegraf.sidekiq.enabled = defined?(::Sidekiq)
|
60
|
+
config.telegraf.sidekiq.series = 'sidekiq'
|
61
|
+
config.telegraf.sidekiq.tags = {}
|
62
|
+
|
56
63
|
initializer 'telegraf.agent' do |app|
|
57
64
|
app.config.telegraf.agent ||= begin
|
58
65
|
::Telegraf::Agent.new \
|
@@ -90,5 +97,18 @@ module Telegraf
|
|
90
97
|
point.values[:action_ms] = ((finish - start) * 1000.0) # milliseconds
|
91
98
|
end
|
92
99
|
end
|
100
|
+
|
101
|
+
initializer 'telegraf.sidekiq' do |app|
|
102
|
+
next unless app.config.telegraf.sidekiq.enabled
|
103
|
+
|
104
|
+
::Sidekiq.configure_server do |config|
|
105
|
+
config.server_middleware do |chain|
|
106
|
+
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
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
93
113
|
end
|
94
114
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
|
5
|
+
module Telegraf
|
6
|
+
module Sidekiq
|
7
|
+
# Telegraf::Sidekiq::Middleware
|
8
|
+
#
|
9
|
+
# This Sidekiq middleware collects queue metrics and sends them to telegraf.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# Tags:
|
13
|
+
#
|
14
|
+
# * `type`:
|
15
|
+
# One of "job" or "scheduled_job".
|
16
|
+
#
|
17
|
+
# * `queue`:
|
18
|
+
# The queue this job landed on.
|
19
|
+
#
|
20
|
+
# * `worker`:
|
21
|
+
# The name of the worker class that was executed.
|
22
|
+
#
|
23
|
+
# * `errors`:
|
24
|
+
# Whether or not this job errored.
|
25
|
+
#
|
26
|
+
# * `retry`:
|
27
|
+
# Whether or not this execution was a retry of a previously failed one.
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# Values:
|
31
|
+
#
|
32
|
+
# * `app_ms`:
|
33
|
+
# Total worker processing time.
|
34
|
+
#
|
35
|
+
# * `queue_ms`:
|
36
|
+
# How long did this job wait in the queue before being processed?
|
37
|
+
# Only present for "normal" (async) jobs (with tag `type` of "job").
|
38
|
+
#
|
39
|
+
class Middleware
|
40
|
+
def initialize(agent:, series: 'sidekiq', tags: {})
|
41
|
+
@agent = agent
|
42
|
+
@series = series.to_s.freeze
|
43
|
+
@tags = tags.freeze
|
44
|
+
end
|
45
|
+
|
46
|
+
def call(worker, job, queue)
|
47
|
+
job_start = ::Time.now.utc
|
48
|
+
|
49
|
+
tags = {
|
50
|
+
**@tags,
|
51
|
+
type: 'job',
|
52
|
+
errors: true,
|
53
|
+
retry: job.key?('retried_at'),
|
54
|
+
queue: queue,
|
55
|
+
worker: worker.class.name
|
56
|
+
}
|
57
|
+
|
58
|
+
values = {
|
59
|
+
retry_count: job['retry_count']
|
60
|
+
}.compact
|
61
|
+
|
62
|
+
# The "enqueued_at" key is not present for scheduled jobs.
|
63
|
+
# See https://github.com/mperham/sidekiq/wiki/Job-Format.
|
64
|
+
if job.key?('enqueued_at')
|
65
|
+
enqueued_at = ::Time.at(job['enqueued_at'].to_f).utc
|
66
|
+
values[:queue_ms] = (job_start - enqueued_at) * 1000 # milliseconds
|
67
|
+
end
|
68
|
+
|
69
|
+
# The "at" key is only present for scheduled jobs.
|
70
|
+
tags[:type] = 'scheduled_job' if job.key?('at')
|
71
|
+
|
72
|
+
begin
|
73
|
+
yield
|
74
|
+
|
75
|
+
# If we get here, this was a successful execution
|
76
|
+
tags[:errors] = false
|
77
|
+
ensure
|
78
|
+
job_stop = ::Time.now.utc
|
79
|
+
|
80
|
+
values[:app_ms] = (job_stop - job_start) * 1000 # milliseconds
|
81
|
+
|
82
|
+
@agent.write(
|
83
|
+
@series, tags: tags, values: values
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/telegraf/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: influxdb
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/telegraf/rack.rb
|
71
71
|
- lib/telegraf/rails.rb
|
72
72
|
- lib/telegraf/railtie.rb
|
73
|
+
- lib/telegraf/sidekiq.rb
|
73
74
|
- lib/telegraf/version.rb
|
74
75
|
- telegraf.gemspec
|
75
76
|
homepage: https://github.com/jgraichen/ruby-telegraf
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.0.8
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Metric Reporter to local telegraf agent
|