sidekiq-influxdb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +34 -0
- data/Makefile +2 -0
- data/README.md +96 -0
- data/Rakefile +2 -0
- data/lib/sidekiq/influxdb.rb +2 -0
- data/lib/sidekiq/influxdb/server_middleware.rb +67 -0
- data/lib/sidekiq/influxdb/version.rb +5 -0
- data/sidekiq-influxdb.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d76699cb80bb321047c37c5549fe38a5b4d22e2e
|
4
|
+
data.tar.gz: 11b159df26e9104c1c8f994c215acc64c594f7b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51bd0670bd6325e9ef2219c0506da5e21e4c2a0d9580c344ad3c74170cd531729985db274889e56aed1cb0de4f5e49a47ca133be59e0470981448a8b1cf21ada
|
7
|
+
data.tar.gz: 112651d4277dc77a77f5cff8523fca3ab66c9bdcf3987252ec4eb0bf49daaeaab3c87a850cad8a3e57755ae0758f0f4f660ed11036c66ad2f0ab81910c45fe50
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at vassilevsky@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sidekiq-influxdb (0.1.0)
|
5
|
+
influxdb (~> 0.0)
|
6
|
+
sidekiq (~> 5.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
concurrent-ruby (1.0.5)
|
12
|
+
connection_pool (2.2.1)
|
13
|
+
influxdb (0.5.1)
|
14
|
+
rack (2.0.3)
|
15
|
+
rack-protection (2.0.0)
|
16
|
+
rack
|
17
|
+
rake (10.5.0)
|
18
|
+
redis (4.0.1)
|
19
|
+
sidekiq (5.0.5)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
connection_pool (~> 2.2, >= 2.2.0)
|
22
|
+
rack-protection (>= 1.5.0)
|
23
|
+
redis (>= 3.3.4, < 5)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
rake (~> 10.0)
|
31
|
+
sidekiq-influxdb!
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.16.0
|
data/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Sidekiq::InfluxDB
|
2
|
+
|
3
|
+
[Sidekiq](https://github.com/mperham/sidekiq/wiki) middleware that writes job lifecycle events as points to an [InfluxDB](http://docs.influxdata.com/influxdb/v1.3/) database.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this gem to your application's `Gemfile`:
|
8
|
+
|
9
|
+
bundle add sidekiq-influxdb
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Sidekiq middleware description:
|
14
|
+
|
15
|
+
https://github.com/mperham/sidekiq/wiki/Middleware
|
16
|
+
|
17
|
+
InfluxDB client description:
|
18
|
+
|
19
|
+
https://github.com/influxdata/influxdb-ruby/blob/master/README.md
|
20
|
+
|
21
|
+
Add included middleware to your application's Sidekiq middleware stack:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/initializers/sidekiq.rb
|
25
|
+
|
26
|
+
require "sidekiq/influxdb/server_middleware"
|
27
|
+
|
28
|
+
Sidekiq.configure_server do |config|
|
29
|
+
config.server_middleware do |chain|
|
30
|
+
chain.add Sidekiq::InfluxDB::ServerMiddleware,
|
31
|
+
influxdb_client: InfluxDB::Client.new(options), # REQUIRED
|
32
|
+
series_name: 'sidekiq_jobs', # optional, default shown
|
33
|
+
retention_policy: nil # optional, default nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
When you deploy this code, you will start getting the following series in your InfluxDB database:
|
39
|
+
|
40
|
+
> select * from sidekiq_jobs
|
41
|
+
name: sidekiq_jobs
|
42
|
+
time class creation_time error event jid queue total waited worked
|
43
|
+
---- ----- ------------- ----- ----- --- ----- ----- ------ ------
|
44
|
+
1511707465061000000 FooJob 1511707459.0186539 start 51cc82fe75fbeba37b1ff18f default 6.042410135269165
|
45
|
+
1511707465061000000 FooJob 1511707459.0186539 finish 51cc82fe75fbeba37b1ff18f default 8.046684265136719 6.042410135269165 2.0042741298675537
|
46
|
+
1511707467068000000 BarJob 1511707461.019835 start 3891f241ab84d3aba728822e default 6.049134016036987
|
47
|
+
1511707467068000000 BarJob 1511707461.019835 NoMethodError error 3891f241ab84d3aba728822e default 8.056788206100464 6.049134016036987 2.0076541900634766
|
48
|
+
|
49
|
+
Tags (repetitive, indexed data — for filtering and grouping by):
|
50
|
+
|
51
|
+
* `time` — Standard InfluxDB timestamp. Precision of the supplied client is respected. Only `s`, `ms`, and `u` precisions are supported.
|
52
|
+
* `queue` — Queue name.
|
53
|
+
* `class` — Job class name.
|
54
|
+
* `event` — What happened to the job at the specified `time`: `start`, `finish`, or `error`.
|
55
|
+
* `error` — If `event=error`, this tag contains the exception class name.
|
56
|
+
|
57
|
+
Values (unique, non-indexed data — for aggregation):
|
58
|
+
|
59
|
+
* `jid` — Unique job ID.
|
60
|
+
* `creation_time` — Job creation time.
|
61
|
+
|
62
|
+
_The following timings are calculated by this gem (in seconds):_
|
63
|
+
|
64
|
+
* `waited` — How long the job waited in the `queue` until Sidekiq got around to starting it.
|
65
|
+
* `worked` — How long it took to perform the job from start to finish or to an exception.
|
66
|
+
* `total` — How much time passed from job creation to finish. How long it took to do the job, in total.
|
67
|
+
|
68
|
+
This schema allows querying various job metrics effectively.
|
69
|
+
|
70
|
+
For example, how many reports have been generated in the last day:
|
71
|
+
|
72
|
+
```sql
|
73
|
+
SELECT COUNT(jid) FROM sidekiq_jobs WHERE class = 'ReportGeneration' AND time > now() - 1d
|
74
|
+
```
|
75
|
+
|
76
|
+
How many different jobs were executed with errors in the last day:
|
77
|
+
|
78
|
+
```sql
|
79
|
+
SELECT COUNT(jid) FROM sidekiq_jobs WHERE event = 'error' AND time > now() - 1d GROUP BY class
|
80
|
+
```
|
81
|
+
|
82
|
+
Et cetera.
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
87
|
+
|
88
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vassilevsky/sidekiq-influxdb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the Sidekiq::InfluxDB project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vassilevsky/sidekiq-influxdb/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'influxdb'
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module InfluxDB
|
5
|
+
class ServerMiddleware
|
6
|
+
def initialize(
|
7
|
+
influxdb_client:,
|
8
|
+
series_name: 'sidekiq_jobs',
|
9
|
+
retention_policy: nil
|
10
|
+
)
|
11
|
+
@influxdb = influxdb_client
|
12
|
+
@series = series_name
|
13
|
+
@retention = retention_policy
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(worker, msg, queue)
|
17
|
+
t = Time.now.to_f
|
18
|
+
data = {
|
19
|
+
tags: {
|
20
|
+
class: worker.class.name,
|
21
|
+
queue: queue,
|
22
|
+
event: 'start',
|
23
|
+
},
|
24
|
+
values: {
|
25
|
+
jid: msg['jid'],
|
26
|
+
creation_time: msg['created_at'],
|
27
|
+
waited: t - msg['created_at'],
|
28
|
+
},
|
29
|
+
timestamp: in_correct_precision(t)
|
30
|
+
}
|
31
|
+
save(data)
|
32
|
+
begin
|
33
|
+
yield
|
34
|
+
data[:tags][:event] = 'finish'
|
35
|
+
rescue => e
|
36
|
+
data[:tags][:event] = 'error'
|
37
|
+
data[:tags][:error] = e.class.name
|
38
|
+
end
|
39
|
+
tt = Time.now.to_f
|
40
|
+
data[:values][:worked] = tt - t
|
41
|
+
data[:values][:total] = tt - msg['created_at']
|
42
|
+
data[:timestamp] = in_correct_precision(tt)
|
43
|
+
save(data)
|
44
|
+
raise e if e
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def save(data)
|
50
|
+
@influxdb.write_point(@series, data, precision, @retention)
|
51
|
+
end
|
52
|
+
|
53
|
+
def precision
|
54
|
+
@influxdb.config.time_precision
|
55
|
+
end
|
56
|
+
|
57
|
+
def in_correct_precision(t)
|
58
|
+
case precision
|
59
|
+
# In order of probability in real-world setups
|
60
|
+
when 'ms' then (t * 1000).to_i
|
61
|
+
when 's' then t.to_i
|
62
|
+
when 'u' then (t * 1000000).to_i
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "sidekiq/influxdb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sidekiq-influxdb"
|
7
|
+
spec.version = Sidekiq::InfluxDB::VERSION
|
8
|
+
spec.authors = ["Ilya Vassilevsky"]
|
9
|
+
spec.email = ["vassilevsky@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Writes Sidekiq job metrics to InfluxDB"
|
12
|
+
spec.homepage = "https://github.com/vassilevsky/sidekiq-influxdb"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "influxdb", "~> 0.0"
|
22
|
+
spec.add_runtime_dependency "sidekiq", "~> 5.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-influxdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Vassilevsky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: influxdb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.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.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- vassilevsky@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- Makefile
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/sidekiq/influxdb.rb
|
85
|
+
- lib/sidekiq/influxdb/server_middleware.rb
|
86
|
+
- lib/sidekiq/influxdb/version.rb
|
87
|
+
- sidekiq-influxdb.gemspec
|
88
|
+
homepage: https://github.com/vassilevsky/sidekiq-influxdb
|
89
|
+
licenses: []
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.6.13
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Writes Sidekiq job metrics to InfluxDB
|
111
|
+
test_files: []
|