io_monitor 0.1.0 → 0.2.0

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: 55da4008002fc3ddd2846fda47f10c76910a29b370754f02772e33635c73d156
4
- data.tar.gz: be06ae7bf31a7051a7e0e113cf16f1c2a55300bf4519d083d400e948e2b4a760
3
+ metadata.gz: c6e067b726ccf26c1f0b71c6ee209c910f2ee0f7004d5aa552dfdc04276e7b89
4
+ data.tar.gz: 595c2ef011ddae63f5ec7e470065f163477dadbe187648fcdd9960661018972e
5
5
  SHA512:
6
- metadata.gz: 4120f7fad9b19fe8ef2be71a5c14fd54fca42141ed205cdd468086956b4232bb401fca94d47c906fa2fc371df3288f16b6b46ee2a520ef023d9fdf9fbe61a7d2
7
- data.tar.gz: 5eab6fe8f0e5eb4072d8c9e092259896cadb8034dbf4baf8ec99460febbc0fe3bb592f7e0f120e14fdf6f1ed0e4f2684df54b2cd27830281b37eabe36c31a3d4
6
+ metadata.gz: 69d47ffff8807be7991ccaa82471b085252634e7ac4db064ece0ec87ef02f3ae9d18a6ee833619d47912f8c0fc712d1b8762a86196a23a251724c20d5cd2bf6e
7
+ data.tar.gz: d57e63f51f61c9f86aa0683525f134cfb9be1670e95cab651b68dbbefff9af6e4b5b3486bafd0e607700ef110acb37bb95e9ba0dbb2af9cfe436204ea866f5fc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## main
4
4
 
5
+ ## 0.2.0 (2022-05-29)
6
+
7
+ - [PR#8](https://github.com/DmitryTsepelev/io_monitor/pull/8) Add Redis adapter ([@DmitryTsepelev])
8
+
5
9
  ## 0.1.0 (2022-05-24)
6
10
 
7
11
  - [PR#7](https://github.com/DmitryTsepelev/io_monitor/pull/7) Add HTTP adapter ([@maxshend])
@@ -12,3 +16,4 @@
12
16
  [@baygeldin]: https://github.com/baygeldin
13
17
  [@prog-supdex]: https://github.com/prog-supdex
14
18
  [@maxshend]: https://github.com/maxshend
19
+ [@DmitryTsepelev]: https://github.com/DmitryTsepelev
data/README.md CHANGED
@@ -22,13 +22,15 @@ Add this line to your application's Gemfile:
22
22
  gem 'io_monitor'
23
23
  ```
24
24
 
25
+ Currently gem can collect the data from `ActiveRecord`, `Net::HTTP` and `Redis`.
26
+
25
27
  Change configuration in an initializer if you need:
26
28
 
27
29
  ```ruby
28
30
  IoMonitor.configure do |config|
29
31
  config.publish = :notifications # defaults to :logs
30
32
  config.warn_threshold = 0.8 # defaults to 0
31
- config.adapters = [:active_record, :net_http] # defaults to [:active_record]
33
+ config.adapters = [:active_record, :net_http, :redis] # defaults to [:active_record]
32
34
  end
33
35
  ```
34
36
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "io_monitor/patches/redis_patch"
4
+
5
+ module IoMonitor
6
+ class RedisAdapter < BaseAdapter
7
+ def self.kind
8
+ :redis
9
+ end
10
+
11
+ def initialize!
12
+ ActiveSupport.on_load(:after_initialize) do
13
+ Redis.prepend(RedisPatch)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IoMonitor
4
+ module RedisPatch
5
+ def send_command(command, &block)
6
+ super(command, &block).tap do |reply|
7
+ # we need to check QUEUED because of https://github.com/redis/redis-rb/blob/cbdb53e8c2f0be53c91404cb7ff566a36fc8ebf5/lib/redis/client.rb#L164
8
+ if reply != "QUEUED" && !reply.is_a?(Redis::CommandError) && IoMonitor.aggregator.active?
9
+ IoMonitor.aggregator.increment(RedisAdapter.kind, reply.bytesize)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IoMonitor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/io_monitor.rb CHANGED
@@ -17,7 +17,15 @@ require "io_monitor/railtie"
17
17
 
18
18
  module IoMonitor
19
19
  NAMESPACE = :io_monitor
20
- ADAPTERS = [ActiveRecordAdapter, NetHttpAdapter].freeze
20
+
21
+ adapters = [ActiveRecordAdapter, NetHttpAdapter]
22
+
23
+ if defined? Redis
24
+ require "io_monitor/adapters/redis_adapter"
25
+ adapters << RedisAdapter
26
+ end
27
+ ADAPTERS = adapters.freeze
28
+
21
29
  PUBLISHERS = [LogsPublisher, NotificationsPublisher].freeze
22
30
 
23
31
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - baygeldin
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-05-23 00:00:00.000000000 Z
14
+ date: 2022-05-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -27,6 +27,20 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '6.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '4.0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.0'
30
44
  description:
31
45
  email:
32
46
  - dmitry.a.tsepelev@gmail.com
@@ -41,6 +55,7 @@ files:
41
55
  - lib/io_monitor/adapters/active_record_adapter.rb
42
56
  - lib/io_monitor/adapters/base_adapter.rb
43
57
  - lib/io_monitor/adapters/net_http_adapter.rb
58
+ - lib/io_monitor/adapters/redis_adapter.rb
44
59
  - lib/io_monitor/aggregator.rb
45
60
  - lib/io_monitor/configuration.rb
46
61
  - lib/io_monitor/controller.rb
@@ -48,6 +63,7 @@ files:
48
63
  - lib/io_monitor/patches/action_controller_base_patch.rb
49
64
  - lib/io_monitor/patches/future_result_patch.rb
50
65
  - lib/io_monitor/patches/net_http_adapter_patch.rb
66
+ - lib/io_monitor/patches/redis_patch.rb
51
67
  - lib/io_monitor/publishers/base_publisher.rb
52
68
  - lib/io_monitor/publishers/logs_publisher.rb
53
69
  - lib/io_monitor/publishers/notifications_publisher.rb