sneakers-influxdb 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +11 -0
- data/lib/sneakers/influxdb_metrics/version.rb +7 -0
- data/lib/sneakers/influxdb_metrics.rb +92 -0
- data/lib/sneakers-influxdb.rb +2 -0
- data/sneakers-influxdb.gemspec +38 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ec0d503d7f4dfef766bfec6ec3f4d0fedf10ff3
|
4
|
+
data.tar.gz: 6220b43cfcb167867d287985aafd7653eefc3cb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8afd3a5ef900647998549fccca1128ee07eeb299bf7edc29212f684d8b89cbd5ec412848b5dc9e3dd37a816205ed229712beb6027150da20a886a643d51cd96b
|
7
|
+
data.tar.gz: 904bf08e18bf7c6081381cced5859ad5429d94f9b6b5a68768a5ba77e8f3517848e209ba40aad8265cf68753a6f444753edb3347d6e15be3ed1811829776002d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p648
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Guilherme Moreira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Sneakers::InfluxDB
|
2
|
+
|
3
|
+
This gem collect metrics from Sneakers workers and insert them in InfluxDB. Those metrics can be useful so you know how many works you are doing, how many started and ended, as well the time each work takes to execute.
|
4
|
+
|
5
|
+
This gem depends on `influxdb` gem 0.3.x. This branch supports Ruby 2.1 and less, so it shouldn't break current compatibility while using Sneakers and Bunny gems.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sneakers-influxdb'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```shell
|
24
|
+
$ gem install sneakers-influxdb
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Where you configure the Sneakers gem, pass the object Sneakers::InfluxDBMetrics to the metrics option.
|
30
|
+
|
31
|
+
Example:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'sneakers-influxdb'
|
35
|
+
|
36
|
+
influxdb_metrics = Sneakers::InfluxDBMetrics.new('sneakers', host: 'localhost',
|
37
|
+
port: 8086,
|
38
|
+
username: 'admin',
|
39
|
+
password: 'admin')
|
40
|
+
|
41
|
+
Sneakers.configure(workers: 8,
|
42
|
+
threads: 1,
|
43
|
+
timeout_job_after: 2,
|
44
|
+
log: Rails.logger,
|
45
|
+
metrics: influxdb_metrics)
|
46
|
+
```
|
47
|
+
|
48
|
+
The InfluxDBMetrics initializer receives the same params as the InfluxDB::Client class. You can also pass an instance of InfluxDB::Client if you already uses the client in other parts of your project.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gmmoreira/sneakers-influxdb.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sneakers/metrics/influxdb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'influxdb'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
module Sneakers
|
7
|
+
class InfluxDBMetrics
|
8
|
+
INCREMENT_SERIES = 'sneakers_increment'
|
9
|
+
TIMING_SERIES = 'sneakers_timing'
|
10
|
+
|
11
|
+
attr_reader :client
|
12
|
+
|
13
|
+
def initialize(db_or_client, opts = {})
|
14
|
+
if db_or_client.is_a? ::InfluxDB::Client
|
15
|
+
@client = db_or_client
|
16
|
+
else
|
17
|
+
@client = ::InfluxDB::Client.new(db_or_client, opts)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def increment(metric)
|
22
|
+
raise RuntimeError, 'Metric must be a String type' unless metric.is_a?(String)
|
23
|
+
|
24
|
+
client.write_point(
|
25
|
+
INCREMENT_SERIES,
|
26
|
+
values: { value: 1 },
|
27
|
+
tags: increment_tags(metric)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def timing(metric, &block)
|
32
|
+
raise RuntimeError, 'Metric must be a String type' unless metric.is_a?(String)
|
33
|
+
raise RuntimeError, 'Timing must receive a block parameter' unless block_given?
|
34
|
+
|
35
|
+
elapsed = Benchmark.realtime(&block)
|
36
|
+
|
37
|
+
client.write_point(
|
38
|
+
TIMING_SERIES,
|
39
|
+
values: { value: elapsed },
|
40
|
+
tags: timing_tags(metric)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
private_constant :INCREMENT_SERIES
|
47
|
+
private_constant :TIMING_SERIES
|
48
|
+
|
49
|
+
def increment_tags(metric)
|
50
|
+
if /\A #match start of string
|
51
|
+
work\. #match work
|
52
|
+
(?<worker>[^\.]+?)\. #match worker name
|
53
|
+
(?<status>[^\.]+?) #match worker status
|
54
|
+
\z #match end of string
|
55
|
+
/x =~ metric
|
56
|
+
{
|
57
|
+
worker: worker,
|
58
|
+
status: status
|
59
|
+
}
|
60
|
+
elsif /\A #match start of string
|
61
|
+
work\. #match work
|
62
|
+
(?<worker>[^\.]+?)\. #match worker name
|
63
|
+
handled\. #match message handled
|
64
|
+
(?<type>[^\.]+?) #match message handled type
|
65
|
+
\z #match end of string
|
66
|
+
/x =~ metric
|
67
|
+
{
|
68
|
+
worker: worker,
|
69
|
+
status: 'handled',
|
70
|
+
type: type
|
71
|
+
}
|
72
|
+
else
|
73
|
+
raise RuntimeError, "Increment metric cannot be matched. Metric: #{metric}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def timing_tags(metric)
|
78
|
+
if /\A #match start of string
|
79
|
+
work\. #match work
|
80
|
+
(?<worker>[^\.]+?)\. #match worker name
|
81
|
+
time #match time type
|
82
|
+
/x =~ metric
|
83
|
+
{
|
84
|
+
worker: worker,
|
85
|
+
status: 'timing'
|
86
|
+
}
|
87
|
+
else
|
88
|
+
raise RuntimeError, "Timing metric cannot be matched. Metric: #{metric}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sneakers-influxdb"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sneakers-influxdb"
|
8
|
+
spec.version = Sneakers::InfluxDBMetrics::VERSION
|
9
|
+
spec.authors = ["Guilherme Moreira"]
|
10
|
+
spec.email = ["guilhermerx7@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{InfluxDB metrics for Sneakers workers}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/gmmoreira/sneakers-influxdb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "influxdb", "~> 0.3.0"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sneakers-influxdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guilherme Moreira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-18 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.3.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.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- guilhermerx7@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .ruby-version
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- docker-compose.yml
|
87
|
+
- lib/sneakers-influxdb.rb
|
88
|
+
- lib/sneakers/influxdb_metrics.rb
|
89
|
+
- lib/sneakers/influxdb_metrics/version.rb
|
90
|
+
- sneakers-influxdb.gemspec
|
91
|
+
homepage: https://github.com/gmmoreira/sneakers-influxdb
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata:
|
95
|
+
allowed_push_host: https://rubygems.org
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.6.13
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: InfluxDB metrics for Sneakers workers
|
116
|
+
test_files: []
|