sidekiq-datadog-monitor 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d84d08e0320ca9b9e399bb8eff1efd74af038a534fe9936c8cfcfb3e169dc40
4
- data.tar.gz: f7cedc8a2816f04c886a2a0c8f841d7cd2819bbb916cd59737208ceff35043c1
3
+ metadata.gz: 3fbb4c43b56e16ca4c1114a9a708fd0f45900493acdb6efab3ce90af4a704ef7
4
+ data.tar.gz: 022d9d4b5aa3a1ca5ac86efc890a6f6a074d28a3e5f5eae2f2dead5da571c90b
5
5
  SHA512:
6
- metadata.gz: 6f1384e84c750d8510cc1102c9f4286276c8a6fdefa050e2576ce0baebde5da806859c8d4e34e316921260814fd4a251d8f20bd652073bb5bdee9a0af6fdbbda
7
- data.tar.gz: 489cf5542ec468a81eb8e0c218b5f34babb3a23699e444e1702cf65cd105e8326f4667d01ab5765a599564600dba8c9e4a6564dd0a4a838766f9ece447b9e707
6
+ metadata.gz: 4b032a07e6380d5bec063d42dbf8c7b016ec2b67516b2411738f4aba49073ff0b5d3cd79b9bb562169ae02c9dccdfd41194341ad345aec45c9944ae9dc0dd94d
7
+ data.tar.gz: 606c4c763f38b5972809292b94fabd89ea28587f0a043845e237b36a74ffce141c55b6a71d1032b128f8a5858c0760e28400111662b5f72bf7dff0a6c98f532c
data/README.md CHANGED
@@ -1,15 +1,14 @@
1
1
  # Sidekiq::Datadog::Monitor
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sidekiq/datadog/monitor`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Library that gather sidekiq jobs metrics (currently, only size and latency)
4
+ and send it to datadog
6
5
 
7
6
  ## Installation
8
7
 
9
8
  Add this line to your application's Gemfile:
10
9
 
11
10
  ```ruby
12
- gem 'sidekiq-datadog-monitor'
11
+ gem 'sidekiq-datadog-monitor', '0.0.1'
13
12
  ```
14
13
 
15
14
  And then execute:
@@ -22,7 +21,31 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ To start sending metrics
25
+
26
+ ```ruby
27
+ # Import the library
28
+ require 'sidekiq/datadog/monitor/data'
29
+
30
+ # Initiate a Sidekiq::Datadog::Monitor client instance.
31
+ Sidekiq::Datadog::Monitor::Data.initialize!(
32
+ {agent_host: 'localhost',
33
+ agent_port: 8125,
34
+ env: 'production', # optional
35
+ tag: 'tag', # optional
36
+ queue: 'queue name', # optional
37
+ cron: "*/30 * * * *" # default: "*/1 * * * *"
38
+ }
39
+ )
40
+
41
+ ```
42
+ `agent_host` and `agent_port` instantiate DogStatsD client
43
+
44
+ `env`, `tag`, `queue` settings for background job that will gather and send Sidekiq metrics
45
+
46
+ `cron` - schedule settings for background job that will gather and send Sidekiq metrics
47
+
48
+
26
49
 
27
50
  ## Development
28
51
 
@@ -1,4 +1,7 @@
1
- require "sidekiq/datadog/monitor/version"
1
+ require 'sidekiq/api'
2
+ require 'sidekiq-scheduler'
3
+ require "sidekiq/datadog/monitor/data"
4
+ require 'sidekiq/datadog/monitor/metrics_worker'
2
5
 
3
6
  module Sidekiq
4
7
  module Datadog
@@ -1,5 +1,3 @@
1
- require 'datadog/statsd'
2
- require 'sidekiq/datadog/monitor/metrics_worker'
3
1
  module Sidekiq
4
2
  module Datadog
5
3
  module Monitor
@@ -8,16 +6,26 @@ module Sidekiq
8
6
  attr_reader :agent_port, :agent_host, :tag, :env, :queue, :cron
9
7
 
10
8
  def initialize!(options)
11
- @agent_port = options[:agent_port]
12
- @agent_host = options[:agent_host]
9
+ @agent_port, @agent_host = options.fetch_values(:agent_port, :agent_host)
13
10
  @tag = options[:tag] || ''
14
11
  @env = options[:env] || ''
15
12
  @queue = options[:queue] || ''
16
13
  @cron = options[:cron] || "*/1 * * * *"
17
14
 
18
- start
15
+ Sidekiq.configure_server do |config|
16
+ SidekiqScheduler::Scheduler.dynamic = true
17
+
18
+ config.on(:startup) do
19
+ start
20
+ end
21
+ end
22
+
23
+ rescue StandardError => e
24
+ raise Sidekiq::Datadog::Monitor::Error.new(e.message)
19
25
  end
20
26
 
27
+ private
28
+
21
29
  def start
22
30
  Sidekiq.set_schedule('send_metrics',
23
31
  { "cron"=> cron, 'class' => 'Sidekiq::Datadog::Monitor::MetricsWorker', 'queue' => queue })
@@ -1,5 +1,5 @@
1
+ require "sidekiq/datadog/monitor/data"
1
2
  require 'datadog/statsd'
2
- require 'sidekiq'
3
3
 
4
4
  module Sidekiq
5
5
  module Datadog
@@ -23,13 +23,13 @@ module Sidekiq
23
23
 
24
24
  def post_queue_size(queue_name, size)
25
25
  statsd.gauge('sidekiq.queue.size', size,
26
- tags: ["queue_name:#{queue_name}", "environment:#{Data.env}", Data.tag])
26
+ tags: ["queue_name:#{queue_name}", "env:#{Data.env}", Data.tag])
27
27
  end
28
28
 
29
29
  def post_queue_latency(queue_name)
30
30
  latency = Sidekiq::Queue.new(queue_name).latency
31
31
  statsd.gauge('sidekiq.queue.latency', latency,
32
- tags: ["queue_name:#{queue_name}", "environment:#{Data.env}", Data.tag])
32
+ tags: ["queue_name:#{queue_name}", "env:#{Data.env}", Data.tag])
33
33
  end
34
34
  end
35
35
  end
@@ -1,7 +1,7 @@
1
1
  module Sidekiq
2
2
  module Datadog
3
3
  module Monitor
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-datadog-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aleksa_castle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.85.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.85.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: sidekiq
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: 2.2.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: sidekiq-scheduler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.1
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: dogstatsd-ruby
71
99
  requirement: !ruby/object:Gem::Requirement