sidekiq-influxdb 0.4.0 → 1.0.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
  SHA1:
3
- metadata.gz: 692630f32205c66fd6e128130b5287f683e5d4da
4
- data.tar.gz: 413d701195b97631f683d6c1706fca6436a49218
3
+ metadata.gz: 94d367f4606ba44ae8492818c3fc276c2de1e514
4
+ data.tar.gz: 5da84f0c6189a1827b8c8ad8a62348eccb1b6dcb
5
5
  SHA512:
6
- metadata.gz: a8097a92929fc14d7eaecbb93d3695cbe2a0b39ad20c710167e13b14a2868248f6eddabaee7b5efd2c4b449096b3a3574bf9d17849911d28d3eec964220b9615
7
- data.tar.gz: 479455da95330526bf9116cf942502bd02dd8c6a6e54309fe393c4f7aefbdfd41c525edc7bc9460180332f06e9c4b4734c216b3b28bc48f959beffcfdd3913c7
6
+ metadata.gz: 0e205ff73a6f9d598fb9d3bd86dca34af5087256dbae23f0ff40b861e51a4b11f7db0b10398ea5ce81fb2fb82dc0c77b30e1ecb1a5402877aad1b6cff5b78e6f
7
+ data.tar.gz: 84236d2ee7522b8b3f67e4c587d80c53e31ef6fb496186b26ca551607d9b8a6e87a3d441f5c08954a765ec7cf704036d768a5230ecb05804fbadeb272dcc5833
data/README.md CHANGED
@@ -27,7 +27,7 @@ require "sidekiq/influxdb/server_middleware"
27
27
 
28
28
  Sidekiq.configure_server do |config|
29
29
  config.server_middleware do |chain|
30
- chain.add Sidekiq::InfluxDB::ServerMiddleware,
30
+ chain.add Sidekiq::Middleware::Server::InfluxDB,
31
31
  influxdb_client: InfluxDB::Client.new(options), # REQUIRED
32
32
  series_name: 'sidekiq_jobs', # optional, default shown
33
33
  retention_policy: nil, # optional, default nil
@@ -1,2 +1,2 @@
1
1
  require "sidekiq/influxdb/version"
2
- require "sidekiq/influxdb/server_middleware"
2
+ require "sidekiq/middleware/server/influxdb"
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module InfluxDB
3
- VERSION = "0.4.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,82 @@
1
+ require 'set'
2
+ require 'influxdb'
3
+
4
+ module Sidekiq
5
+ module Middleware
6
+ module Server
7
+ class InfluxDB
8
+
9
+ def initialize(
10
+ influxdb_client:,
11
+ series_name: 'sidekiq_jobs',
12
+ retention_policy: nil,
13
+ start_events: true,
14
+ tags: {},
15
+ except: []
16
+ )
17
+ @influxdb = influxdb_client
18
+ @series = series_name
19
+ @retention = retention_policy
20
+ @start_events = start_events
21
+ @tags = tags
22
+ @secret_agents = Set.new(except)
23
+ end
24
+
25
+ def call(worker, msg, queue)
26
+ if @secret_agents.include?(worker.class)
27
+ yield
28
+ return
29
+ end
30
+ t = Time.now.to_f
31
+ data = {
32
+ tags: {
33
+ class: worker.class.name,
34
+ queue: queue,
35
+ event: 'start',
36
+ }.merge(@tags),
37
+ values: {
38
+ jid: msg['jid'],
39
+ creation_time: msg['created_at'],
40
+ waited: t - msg['created_at'],
41
+ },
42
+ timestamp: in_correct_precision(t)
43
+ }
44
+ save(data) if @start_events
45
+ begin
46
+ yield
47
+ data[:tags][:event] = 'finish'
48
+ rescue => e
49
+ data[:tags][:event] = 'error'
50
+ data[:tags][:error] = e.class.name
51
+ end
52
+ tt = Time.now.to_f
53
+ data[:values][:worked] = tt - t
54
+ data[:values][:total] = tt - msg['created_at']
55
+ data[:timestamp] = in_correct_precision(tt)
56
+ save(data)
57
+ raise e if e
58
+ end
59
+
60
+ private
61
+
62
+ def save(data)
63
+ @influxdb.write_point(@series, data, precision, @retention)
64
+ end
65
+
66
+ def precision
67
+ @influxdb.config.time_precision
68
+ end
69
+
70
+ def in_correct_precision(t)
71
+ case precision
72
+ # In order of probability in real-world setups
73
+ when 'ms' then (t * 1000).to_i
74
+ when 's' then t.to_i
75
+ when 'u' then (t * 1000000).to_i
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Vassilevsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-27 00:00:00.000000000 Z
11
+ date: 2018-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb
@@ -81,8 +81,8 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/sidekiq/influxdb.rb
84
- - lib/sidekiq/influxdb/server_middleware.rb
85
84
  - lib/sidekiq/influxdb/version.rb
85
+ - lib/sidekiq/middleware/server/influxdb.rb
86
86
  - sidekiq-influxdb.gemspec
87
87
  homepage: https://github.com/vassilevsky/sidekiq-influxdb
88
88
  licenses: []
@@ -1,78 +0,0 @@
1
- require 'set'
2
- require 'influxdb'
3
-
4
- module Sidekiq
5
- module InfluxDB
6
- class ServerMiddleware
7
- def initialize(
8
- influxdb_client:,
9
- series_name: 'sidekiq_jobs',
10
- retention_policy: nil,
11
- start_events: true,
12
- tags: {},
13
- except: []
14
- )
15
- @influxdb = influxdb_client
16
- @series = series_name
17
- @retention = retention_policy
18
- @start_events = start_events
19
- @tags = tags
20
- @secret_agents = Set.new(except)
21
- end
22
-
23
- def call(worker, msg, queue)
24
- if @secret_agents.include?(worker.class)
25
- yield
26
- return
27
- end
28
- t = Time.now.to_f
29
- data = {
30
- tags: {
31
- class: worker.class.name,
32
- queue: queue,
33
- event: 'start',
34
- }.merge(@tags),
35
- values: {
36
- jid: msg['jid'],
37
- creation_time: msg['created_at'],
38
- waited: t - msg['created_at'],
39
- },
40
- timestamp: in_correct_precision(t)
41
- }
42
- save(data) if @start_events
43
- begin
44
- yield
45
- data[:tags][:event] = 'finish'
46
- rescue => e
47
- data[:tags][:event] = 'error'
48
- data[:tags][:error] = e.class.name
49
- end
50
- tt = Time.now.to_f
51
- data[:values][:worked] = tt - t
52
- data[:values][:total] = tt - msg['created_at']
53
- data[:timestamp] = in_correct_precision(tt)
54
- save(data)
55
- raise e if e
56
- end
57
-
58
- private
59
-
60
- def save(data)
61
- @influxdb.write_point(@series, data, precision, @retention)
62
- end
63
-
64
- def precision
65
- @influxdb.config.time_precision
66
- end
67
-
68
- def in_correct_precision(t)
69
- case precision
70
- # In order of probability in real-world setups
71
- when 'ms' then (t * 1000).to_i
72
- when 's' then t.to_i
73
- when 'u' then (t * 1000000).to_i
74
- end
75
- end
76
- end
77
- end
78
- end