influxdb-metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +9 -0
- data/influxdb-metrics.gemspec +29 -0
- data/lib/influxdb/metrics.rb +21 -0
- data/lib/influxdb/metrics/configuration.rb +74 -0
- data/lib/influxdb/metrics/controller.rb +41 -0
- data/lib/influxdb/metrics/event.rb +40 -0
- data/lib/influxdb/metrics/model.rb +44 -0
- data/lib/influxdb/metrics/railtie.rb +13 -0
- data/lib/influxdb/metrics/version.rb +5 -0
- data/spec/influxdb/metrics/configuration_spec.rb +78 -0
- data/spec/influxdb/metrics/controller_spec.rb +79 -0
- data/spec/influxdb/metrics/model_spec.rb +64 -0
- data/spec/influxdb/metrics_spec.rb +19 -0
- data/spec/spec_helper.rb +43 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5f5d32d28c2e37cee2ba9accb613fa0ebeec9cc2
|
4
|
+
data.tar.gz: 5a5506ad3d9c8cf3f4cd8d155c9c4cb7aa3b3c7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3560a40c061378b114aab8de2e4fbb92a40a510e7128a6dddadd957603d1a7fd4af97e33f36b3e2bcf1466ea32d227aeba055f6b2c1aa42d79fa147628b04e73
|
7
|
+
data.tar.gz: 070d1bb035941c002cd92d2468aa6707804d36fa22ff679321705f67a1e9f2195a0ddc8be8f237fd60072c727a45c79854b857f821d16aa4d7321a31de18f8fc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ray Zane
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# InfluxDB::Metrics
|
2
|
+
|
3
|
+
This gem adds allow your Rails app to report performance metrics for database queries and response times to InfluxDB.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'influxdb-metrics'
|
11
|
+
```
|
12
|
+
|
13
|
+
If you're using the 8.x line of InfluxDB, you'll need this line as well:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'influxdb', '~> 0.1.9'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
## Motivation
|
24
|
+
|
25
|
+
[InfluxDB::Rails](https://github.com/influxdb/influxdb-rails) is a really great project. It allows tracking controller metrics right out of the box. It also includes exception tracking, which is really great if you don't have it setup yet. I use a different service to do exception tracking, so I just want to use InfluxDB for performance metrics.
|
26
|
+
|
27
|
+
Also, I wanted to be able to track SQL query performance. That's included.
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
InfluxDB::Metrics.configure do |config|
|
33
|
+
config.host = 'example.com'
|
34
|
+
# or
|
35
|
+
config.hosts = ['example1.com', 'example2.com']
|
36
|
+
|
37
|
+
# The following values are defaults:
|
38
|
+
|
39
|
+
# config.app_name = 'rails'
|
40
|
+
# config.username = 'root'
|
41
|
+
# config.password = 'root'
|
42
|
+
# config.database = 'rails'
|
43
|
+
# config.port = 8086
|
44
|
+
|
45
|
+
# You can customize which stats get recorded:
|
46
|
+
# config.events = :action_controller, :active_record
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( https://github.com/rzane/influxdb-metrics/fork )
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'influxdb/metrics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "influxdb-metrics"
|
8
|
+
spec.version = InfluxDB::Metrics::VERSION
|
9
|
+
spec.authors = ["Ray Zane"]
|
10
|
+
spec.email = ["raymondzane@gmail.com"]
|
11
|
+
spec.summary = %q{Track metrics for your Rails app with InfluxDB.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.7.0"
|
24
|
+
spec.add_development_dependency "simplecov"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "influxdb"
|
27
|
+
spec.add_runtime_dependency "railties"
|
28
|
+
spec.add_runtime_dependency "activesupport"
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
|
3
|
+
require 'influxdb'
|
4
|
+
require 'influxdb/metrics/version'
|
5
|
+
require 'influxdb/metrics/configuration'
|
6
|
+
require 'influxdb/metrics/railtie' if defined?(Rails)
|
7
|
+
|
8
|
+
module InfluxDB
|
9
|
+
module Metrics
|
10
|
+
class << self
|
11
|
+
def config
|
12
|
+
@config ||= Configuration.new
|
13
|
+
end
|
14
|
+
delegate :client, :subscribe, to: :config
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield config
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'influxdb/metrics/controller'
|
2
|
+
require 'influxdb/metrics/model'
|
3
|
+
|
4
|
+
module InfluxDB
|
5
|
+
module Metrics
|
6
|
+
class Configuration
|
7
|
+
EVENTS = {
|
8
|
+
action_controller: Controller,
|
9
|
+
active_record: Model
|
10
|
+
}
|
11
|
+
|
12
|
+
attr_accessor :hosts
|
13
|
+
attr_accessor :username
|
14
|
+
attr_accessor :password
|
15
|
+
attr_accessor :database
|
16
|
+
attr_accessor :app_name
|
17
|
+
attr_accessor :port
|
18
|
+
attr_accessor :debug
|
19
|
+
attr_accessor :async
|
20
|
+
|
21
|
+
attr_writer :client
|
22
|
+
|
23
|
+
attr_reader :logger
|
24
|
+
attr_reader :events
|
25
|
+
attr_reader :subscribed
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@hosts = []
|
29
|
+
@app_name = 'rails'
|
30
|
+
@username = 'root'
|
31
|
+
@password = 'root'
|
32
|
+
@database = 'rails'
|
33
|
+
@port = 8086
|
34
|
+
@async = true
|
35
|
+
@debug = false
|
36
|
+
@events = EVENTS.values
|
37
|
+
@subscribed = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def host=(value)
|
41
|
+
hosts << value
|
42
|
+
end
|
43
|
+
|
44
|
+
# Configure specific subscriptions
|
45
|
+
def events=(names)
|
46
|
+
@events = [*names].map do |name|
|
47
|
+
EVENTS.fetch(name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def subscribe
|
52
|
+
@subscribed = events.map do |event|
|
53
|
+
event.new.tap(&:subscribe)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def client
|
58
|
+
@client ||= InfluxDB::Client.new(database,
|
59
|
+
hosts: hosts,
|
60
|
+
username: username,
|
61
|
+
password: password,
|
62
|
+
port: port,
|
63
|
+
async: async,
|
64
|
+
debug: debug
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def logger=(value)
|
69
|
+
InfluxDB::Logging.logger = value if debug
|
70
|
+
@logger = value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'influxdb/metrics/event'
|
3
|
+
|
4
|
+
module InfluxDB
|
5
|
+
module Metrics
|
6
|
+
class Controller < Event
|
7
|
+
def subscribe_to
|
8
|
+
'process_action.action_controller'
|
9
|
+
end
|
10
|
+
|
11
|
+
def handle(_name, start, finish, _id, payload)
|
12
|
+
metric = shared_info(start, finish, payload)
|
13
|
+
timing = duration(start, finish)
|
14
|
+
|
15
|
+
view = (payload[:view_runtime] || 0).ceil
|
16
|
+
db = (payload[:db_runtime] || 0).ceil
|
17
|
+
|
18
|
+
write_point 'controller', metric.merge(value: timing)
|
19
|
+
write_point 'view', metric.merge(value: view)
|
20
|
+
write_point 'db', metric.merge(value: db)
|
21
|
+
rescue => e
|
22
|
+
log :debug, "Unable to process action: #{e.message}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def shared_info(start, finish, payload)
|
28
|
+
{
|
29
|
+
hostname: Socket.gethostname,
|
30
|
+
action: "#{payload[:controller]}##{payload[:action]}",
|
31
|
+
format: request_format(payload[:format]),
|
32
|
+
status: payload[:status]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def request_format(fmt)
|
37
|
+
(fmt.nil? || fmt == '*/*') ? 'all' : fmt
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'active_support/notifications'
|
2
|
+
|
3
|
+
module InfluxDB
|
4
|
+
module Metrics
|
5
|
+
class Event
|
6
|
+
def subscribe
|
7
|
+
ActiveSupport::Notifications.subscribe(subscribe_to) do |*args|
|
8
|
+
handle(*args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def subscribe_to
|
13
|
+
fail NotImplementedError, 'Must implement #subscribe_to'
|
14
|
+
end
|
15
|
+
|
16
|
+
def handle(name, id, start, finish, payload)
|
17
|
+
fail NotImplementedError, 'Must implment #handle'
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
delegate :config, to: InfluxDB::Metrics
|
23
|
+
delegate :client, :logger, to: :config
|
24
|
+
|
25
|
+
def write_point(name, data = {})
|
26
|
+
client.write_point("#{config.app_name}.#{name}", data)
|
27
|
+
rescue => e
|
28
|
+
log :debug, "Unable to write point: #{e.message}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def log(level, message)
|
32
|
+
logger.send(level, '[InfluxDB::Metrics] ' + message) if logger
|
33
|
+
end
|
34
|
+
|
35
|
+
def duration(start, finish)
|
36
|
+
((finish - start) * 1000).ceil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'influxdb/metrics/event'
|
2
|
+
|
3
|
+
module InfluxDB
|
4
|
+
module Metrics
|
5
|
+
class Model < Event
|
6
|
+
SELECT_DELETE = / FROM "(\w+)"/i
|
7
|
+
INSERT = /^INSERT INTO "(\w+)"/i
|
8
|
+
UPDATE = /^UPDATE "(\w+)"/i
|
9
|
+
|
10
|
+
def subscribe_to
|
11
|
+
'sql.active_record'
|
12
|
+
end
|
13
|
+
|
14
|
+
def handle(_name, start, finish, _id, payload)
|
15
|
+
metric = info(start, finish, payload)
|
16
|
+
write_point 'sql', metric if metric
|
17
|
+
rescue => e
|
18
|
+
log :debug, "Unable to process sql: #{e.message}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def info(start, finish, payload)
|
24
|
+
action, table = extract(payload[:sql])
|
25
|
+
return if action.nil? || table.nil?
|
26
|
+
|
27
|
+
{
|
28
|
+
action: action,
|
29
|
+
table: (table && table.downcase),
|
30
|
+
duration: duration(start, finish)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def extract(sql)
|
35
|
+
case sql
|
36
|
+
when /^SELECT/i then ['select', sql[SELECT_DELETE, 1]]
|
37
|
+
when /^INSERT/i then ['insert', sql[INSERT, 1]]
|
38
|
+
when /^UPDATE/i then ['update', sql[UPDATE, 1]]
|
39
|
+
when /^DELETE/i then ['delete', sql[SELECT_DELETE, 1]]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
module InfluxDB::Metrics
|
4
|
+
describe Configuration do
|
5
|
+
def self.its_default(meth, &block)
|
6
|
+
describe "##{meth}" do
|
7
|
+
it 'has a reasonable default' do
|
8
|
+
subject.send(meth).instance_eval(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject {
|
14
|
+
Configuration.new
|
15
|
+
}
|
16
|
+
|
17
|
+
its_default(:app_name) { must_equal 'rails' }
|
18
|
+
its_default(:username) { must_equal 'root' }
|
19
|
+
its_default(:password) { must_equal 'root' }
|
20
|
+
its_default(:database) { must_equal 'rails' }
|
21
|
+
its_default(:port) { must_equal 8086 }
|
22
|
+
its_default(:async) { must_equal true }
|
23
|
+
its_default(:debug) { must_equal false }
|
24
|
+
|
25
|
+
its_default(:events) do
|
26
|
+
must_equal Configuration::EVENTS.values
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#hosts' do
|
30
|
+
it 'is empty by default' do
|
31
|
+
subject.hosts.must_equal []
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'includes host' do
|
35
|
+
subject.host = 'example.com'
|
36
|
+
subject.hosts.must_equal ['example.com']
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'merges host and hosts' do
|
40
|
+
both_hosts = ['example.com', 'example2.com']
|
41
|
+
subject.host = 'example.com'
|
42
|
+
subject.hosts = both_hosts
|
43
|
+
subject.hosts.must_equal both_hosts
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#events=' do
|
48
|
+
it 'accepts a symbol' do
|
49
|
+
subject.events = :active_record
|
50
|
+
subject.events.must_equal [Model]
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'accepts an array' do
|
54
|
+
subject.events = :active_record, :action_controller
|
55
|
+
subject.events.must_equal [Model, Controller]
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'raises error for invalid event' do
|
59
|
+
-> { subject.events = :blah }.must_raise KeyError
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#subscribe' do
|
64
|
+
before do
|
65
|
+
subject.events = :action_controller
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns subscribed' do
|
69
|
+
subject.subscribe.must_equal subject.subscribed
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'assigns subscribed' do
|
73
|
+
subject.subscribe
|
74
|
+
subject.subscribed.first.must_be_instance_of Controller
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
module InfluxDB::Metrics
|
4
|
+
describe Controller do
|
5
|
+
include EventHelpers
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Controller.new
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:payload) {
|
12
|
+
{
|
13
|
+
controller: 'UsersController',
|
14
|
+
action: 'index',
|
15
|
+
format: 'html',
|
16
|
+
status: 200,
|
17
|
+
db_runtime: 232.232,
|
18
|
+
view_runtime: 434.23
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
describe '#subscribe' do
|
23
|
+
it 'subscribes to ActiveSupport::Notifications' do
|
24
|
+
subject.subscribe
|
25
|
+
instrument channel, payload
|
26
|
+
client.points.last.wont_be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#handle' do
|
31
|
+
before do
|
32
|
+
id, now = 'fa8bd2a588bac4060673', Time.now
|
33
|
+
subject.handle channel, now - 0.7, now, id, payload
|
34
|
+
|
35
|
+
@controller, @view, @db = points.last(3)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'writes three points' do
|
39
|
+
points.length.must_equal 3
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'names the controller series correctly' do
|
43
|
+
@controller.series.must_equal 'rails.controller'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'names the view series correctly' do
|
47
|
+
@view.series.must_equal 'rails.view'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'names the db series correctly' do
|
51
|
+
@db.series.must_equal 'rails.db'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'tracks the action' do
|
55
|
+
@controller.data[:action].must_equal 'UsersController#index'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'tracks the request format' do
|
59
|
+
@controller.data[:format].must_equal 'html'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'tracks the status' do
|
63
|
+
@controller.data[:status].must_equal 200
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'tracks the request duration' do
|
67
|
+
@controller.data[:value].must_equal 700
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'tracks the db runtime' do
|
71
|
+
@db.data[:value].must_equal 233
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'tracks the view runtime' do
|
75
|
+
@view.data[:value].must_equal 435
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
module InfluxDB::Metrics
|
4
|
+
describe Model do
|
5
|
+
include EventHelpers
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Model.new
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:payload) {
|
12
|
+
{ sql: 'SELECT "dogs"."*" FROM "dogs"' }
|
13
|
+
}
|
14
|
+
|
15
|
+
describe '#subscribe' do
|
16
|
+
it 'subscribes to ActiveSupport::Notifications' do
|
17
|
+
subject.subscribe
|
18
|
+
instrument channel, payload
|
19
|
+
points.last.wont_be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#handle' do
|
24
|
+
before do
|
25
|
+
id, now = 'fa8bd2a588bac4060673', Time.now
|
26
|
+
subject.handle channel, now - 0.4, now, id, payload
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'names the series correctly' do
|
30
|
+
points.last.series.must_equal 'rails.sql'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'tracks table name' do
|
34
|
+
points.last.data[:table].must_equal 'dogs'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'tracks sql action' do
|
38
|
+
points.last.data[:action].must_equal 'select'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'tracks the duration' do
|
42
|
+
points.last.data[:duration].must_equal 400
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: Don't test a private method
|
47
|
+
describe '#extract' do
|
48
|
+
def self.it_extracts(action, sql, table = 'dogs')
|
49
|
+
it "parses table name for #{action}" do
|
50
|
+
parsed = subject.send(:extract, sql)
|
51
|
+
parsed.first.must_equal(action.to_s)
|
52
|
+
parsed.last.downcase.must_equal(table)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it_extracts :select, %{SELECT "dogs"."*" FROM "dogs"}
|
57
|
+
it_extracts :select, %{SELECT * FROM "DOGS" WHERE "dogs"."name" = 'Fido'}
|
58
|
+
|
59
|
+
it_extracts :insert, %{INSERT INTO "dogs" ("id", "name") VALUES (1, 'Fido')}
|
60
|
+
it_extracts :update, %{UPDATE "dogs" SET "name" = 'Fido'}
|
61
|
+
it_extracts :delete, %{DELETE FROM "dogs" WHERE "id" > 0}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module InfluxDB
|
4
|
+
describe Metrics do
|
5
|
+
describe 'config' do
|
6
|
+
it 'is a Configuration' do
|
7
|
+
Metrics.config.must_be_instance_of Metrics::Configuration
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'configure' do
|
12
|
+
it 'yields Configuration' do
|
13
|
+
Metrics.configure do |config|
|
14
|
+
config.must_be_instance_of Metrics::Configuration
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start { add_filter 'spec' }
|
4
|
+
|
5
|
+
require 'influxdb/metrics'
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
|
9
|
+
InfluxDB::Metrics.configure do |config|
|
10
|
+
config.logger = Logger.new(STDOUT)
|
11
|
+
end
|
12
|
+
|
13
|
+
module InfluxDB::Metrics
|
14
|
+
class TestClient
|
15
|
+
attr_reader :points
|
16
|
+
|
17
|
+
Point = Struct.new(:series, :data)
|
18
|
+
|
19
|
+
def write_point(series, data = {})
|
20
|
+
(@points ||= []) << Point.new(series, data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module EventHelpers
|
25
|
+
def before_setup
|
26
|
+
InfluxDB::Metrics.configure { |c| c.client = client }
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def channel
|
31
|
+
subject.subscribe_to
|
32
|
+
end
|
33
|
+
|
34
|
+
def client
|
35
|
+
@client ||= InfluxDB::Metrics::TestClient.new
|
36
|
+
end
|
37
|
+
delegate :points, to: :client
|
38
|
+
|
39
|
+
def instrument(*args, &block)
|
40
|
+
ActiveSupport::Notifications.instrument(*args, &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: influxdb-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ray Zane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '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'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: influxdb
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: railties
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Track metrics for your Rails app with InfluxDB.
|
112
|
+
email:
|
113
|
+
- raymondzane@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- influxdb-metrics.gemspec
|
124
|
+
- lib/influxdb/metrics.rb
|
125
|
+
- lib/influxdb/metrics/configuration.rb
|
126
|
+
- lib/influxdb/metrics/controller.rb
|
127
|
+
- lib/influxdb/metrics/event.rb
|
128
|
+
- lib/influxdb/metrics/model.rb
|
129
|
+
- lib/influxdb/metrics/railtie.rb
|
130
|
+
- lib/influxdb/metrics/version.rb
|
131
|
+
- spec/influxdb/metrics/configuration_spec.rb
|
132
|
+
- spec/influxdb/metrics/controller_spec.rb
|
133
|
+
- spec/influxdb/metrics/model_spec.rb
|
134
|
+
- spec/influxdb/metrics_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
homepage: ''
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.5.1
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Track metrics for your Rails app with InfluxDB.
|
160
|
+
test_files:
|
161
|
+
- spec/influxdb/metrics/configuration_spec.rb
|
162
|
+
- spec/influxdb/metrics/controller_spec.rb
|
163
|
+
- spec/influxdb/metrics/model_spec.rb
|
164
|
+
- spec/influxdb/metrics_spec.rb
|
165
|
+
- spec/spec_helper.rb
|