sidekiq-influxdb 1.4.0 → 1.4.1
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 -0
- data/CONTRIBUTING.md +6 -0
- data/README.md +45 -30
- data/lib/sidekiq/influxdb/version.rb +1 -1
- data/lib/sidekiq/middleware/server/influxdb.rb +8 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16e8eb281a6977df828e98ca93c15c554c7cbb3cee209f8e1f0c708f41eeae0f
|
4
|
+
data.tar.gz: 781c1656c3f3ff13965ca34160c30e0647bfaba79a0568f1072c8947e92b05ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb6e296fc06c64045795560a9c9c0f06a79f0f1a8df7992cff4212086e54115cc6131e3dc9490c17c95ad8dfe46230ac15f4197aad88302b372b1cb9d963c6b7
|
7
|
+
data.tar.gz: e33436ebba2864a2bb58d8411af97ba1e382682fd746d6da7b48b88d8c2ccc24b071a29b9de1365979300a68a3f07e0c27f8404860b7705c199a35de4e2ffceb
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# Sidekiq-InfluxDB
|
2
2
|
|
3
|
+
## Reference documentation
|
4
|
+
|
5
|
+
* [Sidekiq middleware](https://github.com/mperham/sidekiq/wiki/Middleware)
|
6
|
+
* [InfluxDB client](https://github.com/influxdata/influxdb-ruby)
|
7
|
+
|
3
8
|
## Contributing Guidelines
|
4
9
|
|
10
|
+
1. We welcome addition of useful Sidekiq metrics and optimisations of the existing ones.
|
5
11
|
1. All code should be covered by tests. This library is used in high load Sidekiq deployments. Failures are unacceptable.
|
6
12
|
1. Code should be easy for an average Rubyist to understand.
|
7
13
|
1. Each pull request should contain changes for a single goal.
|
data/README.md
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
[![Travis CI](https://img.shields.io/travis/com/funbox/sidekiq-influxdb)](https://travis-ci.com/github/funbox/sidekiq-influxdb)
|
5
5
|
[![Coveralls](https://img.shields.io/coveralls/funbox/sidekiq-influxdb.svg)](https://coveralls.io/github/funbox/sidekiq-influxdb)
|
6
6
|
|
7
|
-
[Sidekiq](https://github.com/mperham/sidekiq/wiki) middleware
|
7
|
+
[Sidekiq](https://github.com/mperham/sidekiq/wiki) server middleware
|
8
|
+
that writes job lifecycle events as points to an [InfluxDB](http://docs.influxdata.com/influxdb/v1.3/) database.
|
9
|
+
Also includes classes that write global Sidekiq metrics and queue metrics.
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -16,7 +18,24 @@ bundle add sidekiq-influxdb
|
|
16
18
|
|
17
19
|
## Usage
|
18
20
|
|
19
|
-
Add included middleware to your application's Sidekiq middleware stack
|
21
|
+
Add included middleware to your application's Sidekiq middleware stack.
|
22
|
+
The following examples assume that you already have an InfluxDB client object
|
23
|
+
in the `influxdb` variable.
|
24
|
+
This will create a middleware with all defaults (suitable for most deployments):
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# config/initializers/sidekiq.rb
|
28
|
+
|
29
|
+
require "sidekiq/middleware/server/influxdb"
|
30
|
+
|
31
|
+
Sidekiq.configure_server do |config|
|
32
|
+
config.server_middleware do |chain|
|
33
|
+
chain.add Sidekiq::Middleware::Server::InfluxDB, influxdb_client: influxdb
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
You can customize the middleware by passing more options:
|
20
39
|
|
21
40
|
```ruby
|
22
41
|
# config/initializers/sidekiq.rb
|
@@ -26,17 +45,20 @@ require "sidekiq/middleware/server/influxdb"
|
|
26
45
|
Sidekiq.configure_server do |config|
|
27
46
|
config.server_middleware do |chain|
|
28
47
|
chain.add Sidekiq::Middleware::Server::InfluxDB,
|
29
|
-
influxdb_client:
|
30
|
-
series_name: 'sidekiq_jobs',
|
31
|
-
retention_policy:
|
32
|
-
start_events: true,
|
33
|
-
tags: {
|
34
|
-
except: [
|
48
|
+
influxdb_client: influxdb,
|
49
|
+
series_name: 'sidekiq_jobs', # This is the default one.
|
50
|
+
retention_policy: 'rp_name', # In case you want to write metrics to a non-default RP.
|
51
|
+
start_events: true, # Whether or not you want to know when jobs started. See `event` tag description below.
|
52
|
+
tags: {application: 'MyApp'}, # Anything you need on top. **Make sure that tag values have low cardinality!**
|
53
|
+
except: [UnimportantJob] # These job classes will be executed without sending any metrics.
|
35
54
|
end
|
36
55
|
end
|
37
56
|
```
|
38
57
|
|
39
|
-
|
58
|
+
This library assumes that you already have an InfluxDB client object set up the way you like.
|
59
|
+
It does not try to create one for you.
|
60
|
+
If that is not the case, you can learn how to create a client
|
61
|
+
in [InfluxDB client documentation](https://github.com/influxdata/influxdb-ruby#creating-a-client).
|
40
62
|
|
41
63
|
**Warning:** This middleware is going to write _a lot_ of metrics.
|
42
64
|
Set up your InfluxDB client accordingly:
|
@@ -44,7 +66,7 @@ Set up your InfluxDB client accordingly:
|
|
44
66
|
* or install Telegraf, set up aggregation inside it, and set up InfluxDB client to send metrics to it,
|
45
67
|
* or both.
|
46
68
|
|
47
|
-
When you deploy this code, you will
|
69
|
+
When you deploy this code, you will have the following series in your InfluxDB database:
|
48
70
|
|
49
71
|
```
|
50
72
|
> select * from sidekiq_jobs
|
@@ -95,15 +117,22 @@ Et cetera.
|
|
95
117
|
|
96
118
|
### Stats and Queues metrics
|
97
119
|
|
98
|
-
To collect metrics for task stats and queues, you need to run the following code periodically.
|
120
|
+
To collect metrics for task stats and queues, you need to run the following code periodically.
|
121
|
+
For example, you can use [Clockwork](https://rubygems.org/gems/clockwork) for that.
|
122
|
+
You can add settings like this to `clock.rb`:
|
99
123
|
|
100
124
|
```ruby
|
101
125
|
require "sidekiq/metrics/stats"
|
102
126
|
require "sidekiq/metrics/queues"
|
103
127
|
|
128
|
+
influx = InfluxDB::Client.new(options)
|
129
|
+
|
130
|
+
sidekiq_global_metrics = Sidekiq::Metrics::Stats.new(influxdb_client: influx)
|
131
|
+
sidekiq_queues_metrics = Sidekiq::Metrics::Queues.new(influxdb_client: influx)
|
132
|
+
|
104
133
|
every(1.minute, 'sidekiq_metrics') do
|
105
|
-
|
106
|
-
|
134
|
+
sidekiq_global_metrics.publish
|
135
|
+
sidekiq_queues_metrics.publish
|
107
136
|
end
|
108
137
|
```
|
109
138
|
|
@@ -133,7 +162,7 @@ Sidekiq::Metrics::Queues.new(
|
|
133
162
|
).publish
|
134
163
|
```
|
135
164
|
|
136
|
-
When you run the
|
165
|
+
When you run the code, you will have the following series in your InfluxDB database:
|
137
166
|
|
138
167
|
```
|
139
168
|
> select * from sidekiq_stats
|
@@ -159,24 +188,10 @@ time queue size
|
|
159
188
|
|
160
189
|
### Grafana
|
161
190
|
|
162
|
-
You can import
|
191
|
+
You can import a ready-made dashboard from [grafana_dashboard.json](grafana_dashboard.json).
|
163
192
|
|
164
193
|
## Development
|
165
194
|
|
166
|
-
|
167
|
-
* [InfluxDB client](https://github.com/influxdata/influxdb-ruby)
|
168
|
-
|
169
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
170
|
-
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
171
|
-
|
172
|
-
## Contributing
|
173
|
-
|
174
|
-
Bug reports and pull requests are welcome on GitHub at [github.com/funbox/sidekiq-influxdb](https://github.com/funbox/sidekiq-influxdb).
|
175
|
-
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.
|
176
|
-
|
177
|
-
## Code of Conduct
|
178
|
-
|
179
|
-
Everyone interacting in the `Sidekiq::InfluxDB` project’s codebases, issue trackers,
|
180
|
-
chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/funbox/sidekiq-influxdb/blob/master/CODE_OF_CONDUCT.md).
|
195
|
+
See [Contributing Guidelines](CONTRIBUTING.md).
|
181
196
|
|
182
197
|
[![Sponsored by FunBox](https://funbox.ru/badges/sponsored_by_funbox_centered.svg)](https://funbox.ru)
|
@@ -5,22 +5,14 @@ module Sidekiq
|
|
5
5
|
module Server
|
6
6
|
class InfluxDB
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
influxdb_client
|
10
|
-
series_name
|
11
|
-
retention_policy
|
12
|
-
start_events: true
|
13
|
-
tags: {}
|
14
|
-
except
|
15
|
-
clock: -> { Time.now.to_f }
|
16
|
-
)
|
17
|
-
@influxdb = influxdb_client
|
18
|
-
@series = series_name
|
19
|
-
@retention = retention_policy
|
20
|
-
@start_events = start_events
|
21
|
-
@tags = tags
|
22
|
-
@secret_agents = class_names(except)
|
23
|
-
@clock = clock
|
8
|
+
def initialize(options = {})
|
9
|
+
@influxdb = options.fetch(:influxdb_client)
|
10
|
+
@series = options.fetch(:series_name, 'sidekiq_jobs')
|
11
|
+
@retention = options.fetch(:retention_policy, nil)
|
12
|
+
@start_events = options.fetch(:start_events, true)
|
13
|
+
@tags = options.fetch(:tags, {})
|
14
|
+
@secret_agents = class_names(options.fetch(:except, []))
|
15
|
+
@clock = options.fetch(:clock, -> { Time.now.to_f })
|
24
16
|
end
|
25
17
|
|
26
18
|
def call(_worker, msg, _queue)
|
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: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Vassilevsky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: influxdb
|