metrician 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 +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +65 -0
- data/.rubocop_todo.yml +24 -0
- data/.ruby-version +1 -0
- data/.travis.yml +36 -0
- data/Gemfile +1 -0
- data/METRICS.MD +48 -0
- data/README.md +77 -0
- data/Rakefile +12 -0
- data/config/metrician.yaml +136 -0
- data/gemfiles/Gemfile.4.2.sidekiq-4 +24 -0
- data/gemfiles/Gemfile.4.2.sidekiq-4.lock +173 -0
- data/gemfiles/Gemfile.5.0.pg +24 -0
- data/gemfiles/Gemfile.5.0.pg.lock +182 -0
- data/lib/metrician.rb +80 -0
- data/lib/metrician/configuration.rb +33 -0
- data/lib/metrician/jobs.rb +32 -0
- data/lib/metrician/jobs/delayed_job_callbacks.rb +33 -0
- data/lib/metrician/jobs/resque_plugin.rb +36 -0
- data/lib/metrician/jobs/sidekiq_middleware.rb +28 -0
- data/lib/metrician/middleware.rb +64 -0
- data/lib/metrician/middleware/application_timing.rb +29 -0
- data/lib/metrician/middleware/request_timing.rb +152 -0
- data/lib/metrician/reporter.rb +41 -0
- data/lib/metrician/reporters/active_record.rb +63 -0
- data/lib/metrician/reporters/delayed_job.rb +17 -0
- data/lib/metrician/reporters/honeybadger.rb +26 -0
- data/lib/metrician/reporters/memcache.rb +49 -0
- data/lib/metrician/reporters/method_tracer.rb +70 -0
- data/lib/metrician/reporters/middleware.rb +22 -0
- data/lib/metrician/reporters/net_http.rb +28 -0
- data/lib/metrician/reporters/redis.rb +31 -0
- data/lib/metrician/reporters/resque.rb +17 -0
- data/lib/metrician/reporters/sidekiq.rb +19 -0
- data/lib/metrician/version.rb +5 -0
- data/metrician.gemspec +25 -0
- data/script/setup +72 -0
- data/script/test +36 -0
- data/spec/metrician_spec.rb +372 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/database.rb +33 -0
- data/spec/support/database.sample.yml +10 -0
- data/spec/support/database.travis.yml +9 -0
- data/spec/support/models.rb +2 -0
- data/spec/support/test_delayed_job.rb +12 -0
- data/spec/support/test_resque_job.rb +8 -0
- data/spec/support/test_sidekiq_worker.rb +8 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f701346245b51fe548783e261ce5008a756a91d2
|
4
|
+
data.tar.gz: a56ba24445cd0d7f966d5c7550669d89b262da39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8619514f46e56e53a3839615eb779f156ec48a28e4ec318dd4e85b679977f1226cf834cd633b8e932921c7f2f0ecb8bf9f13ca141f83a09240c7a1c90cd4928
|
7
|
+
data.tar.gz: 43d19679b4ff15db9c5000f3157290390d57fd2a7c16f87673c55e92b0924cbdf41284039796afdea81ab3dba8be5e02f0017279574148d629b56966d10496d5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- vendor/**/*
|
6
|
+
- gemfiles/**/*
|
7
|
+
|
8
|
+
|
9
|
+
################
|
10
|
+
# Code Metrics #
|
11
|
+
################
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Exclude:
|
14
|
+
- 'test/schema.rb'
|
15
|
+
- '*.gemspec'
|
16
|
+
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Max: 25
|
19
|
+
|
20
|
+
Metrics/LineLength:
|
21
|
+
Max: 140
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Max: 10
|
25
|
+
CountComments: false
|
26
|
+
|
27
|
+
|
28
|
+
###############
|
29
|
+
# Style Rules #
|
30
|
+
###############
|
31
|
+
Style/Alias:
|
32
|
+
EnforcedStyle: prefer_alias_method
|
33
|
+
|
34
|
+
# ¯\_(ツ)_/¯
|
35
|
+
# ʕノ•ᴥ•ʔノ ︵ ┻━┻
|
36
|
+
# ( ͡° ͜ʖ ͡°)
|
37
|
+
Style/AsciiComments:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/Documentation:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/DoubleNegation:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/EmptyLinesAroundClassBody:
|
47
|
+
EnforcedStyle: empty_lines_except_namespace
|
48
|
+
|
49
|
+
Style/EmptyLinesAroundModuleBody:
|
50
|
+
EnforcedStyle: empty_lines_except_namespace
|
51
|
+
|
52
|
+
Style/FrozenStringLiteralComment:
|
53
|
+
EnforcedStyle: never
|
54
|
+
|
55
|
+
Style/HashSyntax:
|
56
|
+
EnforcedStyle: ruby19
|
57
|
+
|
58
|
+
Style/RaiseArgs:
|
59
|
+
EnforcedStyle: compact
|
60
|
+
|
61
|
+
Style/SpaceInsideHashLiteralBraces:
|
62
|
+
EnforcedStyle: space
|
63
|
+
|
64
|
+
Style/StringLiterals:
|
65
|
+
EnforcedStyle: double_quotes
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-06-05 17:04:34 -0400 using RuboCop version 0.48.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 35
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Max: 14
|
16
|
+
|
17
|
+
# Offense count: 5
|
18
|
+
# Configuration parameters: CountComments.
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 27
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Max: 13
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
before_install: gem install bundler -v 1.14.1
|
4
|
+
|
5
|
+
rvm:
|
6
|
+
- 2.1.5
|
7
|
+
- 2.2.3
|
8
|
+
- 2.3.0
|
9
|
+
- 2.4.0
|
10
|
+
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/Gemfile.4.2.sidekiq-4
|
13
|
+
- gemfiles/Gemfile.5.0.pg
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
exclude:
|
17
|
+
- gemfile: gemfiles/Gemfile.5.0.pg
|
18
|
+
rvm: 2.1.5
|
19
|
+
|
20
|
+
before_script:
|
21
|
+
- psql -c 'create database metrician_test;' -U postgres
|
22
|
+
- mysql -e 'create database IF NOT EXISTS metrician_test;'
|
23
|
+
|
24
|
+
cache: bundler
|
25
|
+
|
26
|
+
notifications:
|
27
|
+
email:
|
28
|
+
- developers@expectedbehavior.com
|
29
|
+
|
30
|
+
script: bundle exec rake current_rspec
|
31
|
+
|
32
|
+
services:
|
33
|
+
- mysql
|
34
|
+
- postgresql
|
35
|
+
- redis-server
|
36
|
+
- memcached
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemfiles/Gemfile.4.2.sidekiq-4
|
data/METRICS.MD
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Metrics you can expect to report in a vanilla Rails app
|
2
|
+
|
3
|
+
### `GET /users`
|
4
|
+
|
5
|
+
* `active_record.users.find`
|
6
|
+
* `database.sql`
|
7
|
+
* `database.sql.select`
|
8
|
+
* `web.request`
|
9
|
+
* `web.request.users_controller.index.get`
|
10
|
+
* `web.request.middleware`
|
11
|
+
* `web.request.idle`
|
12
|
+
* `web.response_size`
|
13
|
+
* `web.response_size.users_controller.index.get`
|
14
|
+
|
15
|
+
*You may also see another instance of `database.sql` and an instance of `database.sql.other` if the table schema is loaded.*
|
16
|
+
|
17
|
+
*In development mode, you can expect to record one each of the following **per asset** on the page because they are served by Rack*
|
18
|
+
|
19
|
+
* `web.request`
|
20
|
+
* `web.request.assets`
|
21
|
+
* `web.request.middleware`
|
22
|
+
* `web.request.idle`
|
23
|
+
* `web.response_size`
|
24
|
+
* `web.response_size.assets`
|
25
|
+
|
26
|
+
|
27
|
+
### `PATCH /redis`
|
28
|
+
|
29
|
+
Assuming we have a form for setting a redis value, and a controller that looks like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class RedisController < ApplicationController
|
33
|
+
def show
|
34
|
+
@value = $redis.get("foo")
|
35
|
+
end
|
36
|
+
|
37
|
+
def update
|
38
|
+
$redis.set("foo", params[:value])
|
39
|
+
redirect_to(redis_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
In addition to request metrics similar to those described above, we can expect the following redis-specific metrics to be recorded:
|
45
|
+
|
46
|
+
* `redis.set` - during the update
|
47
|
+
* `redis.get` - during the redirect/show
|
48
|
+
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Metrician
|
2
|
+
|
3
|
+
Automatically get metrics for [Instrumental](https://instrumentalapp.com) from your Ruby on Rails (RoR) application.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/Instrumental/metrician.svg?branch=master)](https://travis-ci.org/Instrumental/metrician)
|
6
|
+
|
7
|
+
## Automatic Metrics For Ruby
|
8
|
+
|
9
|
+
Automatic metrics for commonly used Ruby gems:
|
10
|
+
|
11
|
+
* ActiveRecord
|
12
|
+
* Redis
|
13
|
+
* Memcached
|
14
|
+
* Dalli
|
15
|
+
* Delayed Job
|
16
|
+
* Sidekiq
|
17
|
+
* Resque
|
18
|
+
* Honeybadger
|
19
|
+
|
20
|
+
Request Metrics:
|
21
|
+
|
22
|
+
* apdex metrics
|
23
|
+
* request time, broken down by controller and action
|
24
|
+
* middleware execution time
|
25
|
+
* idle time
|
26
|
+
* content length
|
27
|
+
* web server queue time (for servers that set HTTP_X_QUEUE_START like nginx)
|
28
|
+
|
29
|
+
And also you can do generic method tracing.
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
```
|
34
|
+
gem install metrician instrumental_agent
|
35
|
+
```
|
36
|
+
|
37
|
+
Grab your project token from [https://instrumentalapp.com/docs/tokens](https://instrumentalapp.com/docs/tokens) and activate metrician with:
|
38
|
+
|
39
|
+
```
|
40
|
+
I = Instrumental::Agent.new(PROJECT_TOKEN)
|
41
|
+
Metrician.activate(I)
|
42
|
+
```
|
43
|
+
|
44
|
+
## Configuration
|
45
|
+
|
46
|
+
### Rack Middleware
|
47
|
+
|
48
|
+
In rails, the middleware will be inserted into your middleware stack automatically. If you control your middleware stack manually in rails, you can load the functionality using the following manual instructions:
|
49
|
+
|
50
|
+
In your application.rb file:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
# request timing should be first so we get the correct queue time and start the
|
54
|
+
# middleware timer
|
55
|
+
config.middleware.insert_before("ActionDispatch::Static", "RequestTiming")
|
56
|
+
|
57
|
+
# if you want to track content length add the rack middleware
|
58
|
+
config.middleware.insert_before("ActionDispatch::Static", "Rack::ContentLength")
|
59
|
+
|
60
|
+
# application timing should be last/just before the request is processed
|
61
|
+
config.middleware.use("ApplicationTiming")
|
62
|
+
```
|
63
|
+
|
64
|
+
If you run `rake middleware`, you should see something like:
|
65
|
+
|
66
|
+
```shell
|
67
|
+
use RequestTiming
|
68
|
+
use Rack::ContentLength
|
69
|
+
use ActionDispatch::Static
|
70
|
+
# etc.
|
71
|
+
use ActionDispatch::BestStandardsSupport
|
72
|
+
use ApplicationTiming
|
73
|
+
run YOUR_APP::Application.routes
|
74
|
+
```
|
75
|
+
|
76
|
+
Your exception tracking middleware may try to get in first (hey, Honeybadger), so you will have to change the load order in an initializer, because we want to track that as middleware time, too.
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# A configuration for Metrician that controls the features of our
|
2
|
+
# automated metric reporting
|
3
|
+
|
4
|
+
---
|
5
|
+
|
6
|
+
# "request_timing" settings control the features of the Request Timing Rack Middleware
|
7
|
+
:request_timing:
|
8
|
+
# hook into Rack middleware for request timing
|
9
|
+
:enabled: true
|
10
|
+
|
11
|
+
# collect basic request timing for every request
|
12
|
+
:request:
|
13
|
+
:enabled: true
|
14
|
+
|
15
|
+
# report 5xx codes as errors
|
16
|
+
:error:
|
17
|
+
:enabled: true
|
18
|
+
|
19
|
+
# report time between requests in a server process as idle time
|
20
|
+
:idle:
|
21
|
+
:enabled: false
|
22
|
+
|
23
|
+
# report the payload size of requests
|
24
|
+
:response_size:
|
25
|
+
:enabled: false
|
26
|
+
|
27
|
+
# report the amount of time spent on middleware per request
|
28
|
+
:middleware:
|
29
|
+
:enabled: false
|
30
|
+
|
31
|
+
# report the amount of time a request spent queued at the web layer
|
32
|
+
# before hitting Rack
|
33
|
+
:queue_time:
|
34
|
+
:enabled: false
|
35
|
+
|
36
|
+
# report the controller, action, and verb for every request
|
37
|
+
:route_tracking:
|
38
|
+
:enabled: false
|
39
|
+
|
40
|
+
# "apdex" controls the recording of metrics to measure apdex
|
41
|
+
# More here: https://en.wikipedia.org/wiki/Apdex
|
42
|
+
# Note this requires "request" tracking to be enabled
|
43
|
+
:apdex:
|
44
|
+
:enabled: true
|
45
|
+
|
46
|
+
# set the threshold (seconds), above which a request is no longer
|
47
|
+
# considered "sasifactory". The "tolerates" threshold will be
|
48
|
+
# 4x this number.
|
49
|
+
:satisfied_threshold: 2.5
|
50
|
+
|
51
|
+
# "database" settings control ActiveRecord metric reporting features
|
52
|
+
:database:
|
53
|
+
# hook into ActiveRecord for db call timing
|
54
|
+
:enabled: true
|
55
|
+
|
56
|
+
# collect basic query tracking for every query
|
57
|
+
:query:
|
58
|
+
:enabled: true
|
59
|
+
|
60
|
+
# collect generic sql query information (select, update, insert, etc.)
|
61
|
+
:command:
|
62
|
+
:enabled: false
|
63
|
+
|
64
|
+
# collect query information for specific tables
|
65
|
+
:table:
|
66
|
+
:enabled: false
|
67
|
+
|
68
|
+
|
69
|
+
# "external_service" settings control reporting metrics when Net::HTTP
|
70
|
+
# is used to make requests
|
71
|
+
:external_service:
|
72
|
+
# hook into Net::HTTP to record timing metrics
|
73
|
+
:enabled: true
|
74
|
+
|
75
|
+
# collect basic external request timing information
|
76
|
+
:request:
|
77
|
+
:enabled: true
|
78
|
+
|
79
|
+
|
80
|
+
# "jobs" settings control reporting metrics when ruby job systems
|
81
|
+
# work through their queues
|
82
|
+
:jobs:
|
83
|
+
|
84
|
+
# hook into job system middleware when presence detected
|
85
|
+
:enabled: true
|
86
|
+
|
87
|
+
# record the basic timing of every job
|
88
|
+
:run:
|
89
|
+
:enabled: true
|
90
|
+
|
91
|
+
# record when an error occurs in the a job
|
92
|
+
:error:
|
93
|
+
:enabled: true
|
94
|
+
|
95
|
+
# record metrics for each kind of job that is worked from the queue
|
96
|
+
:job_specific:
|
97
|
+
:enabled: false
|
98
|
+
|
99
|
+
# "cache" settings control timing of commands to services often used as
|
100
|
+
# application caches like memcached and redis
|
101
|
+
:cache:
|
102
|
+
|
103
|
+
# hook into caching libraries
|
104
|
+
:enabled: true
|
105
|
+
|
106
|
+
# record aggregate timing information for all cache commands
|
107
|
+
:command:
|
108
|
+
:enabled: true
|
109
|
+
|
110
|
+
# record the timing of each command as its own metric
|
111
|
+
:command_specific:
|
112
|
+
:enabled: false
|
113
|
+
|
114
|
+
|
115
|
+
# "exception" settings control reporting when exceptions are caught
|
116
|
+
# by an exception tracker in your application
|
117
|
+
:exception:
|
118
|
+
|
119
|
+
# hook into exception tracking libraries
|
120
|
+
:enabled: false
|
121
|
+
|
122
|
+
# report when an exception is raised and caught by an exception tracker
|
123
|
+
:raise:
|
124
|
+
:enabled: true
|
125
|
+
|
126
|
+
# report a metric per exception type raised
|
127
|
+
:exception_specific:
|
128
|
+
:enabled: false
|
129
|
+
|
130
|
+
# "method_tracing" settings control hooking into Module and allowing
|
131
|
+
# ruby methods to be timed
|
132
|
+
:method_tracer:
|
133
|
+
|
134
|
+
# hook into Module with add_metrician_method_tracer added as a base
|
135
|
+
# feature of every ruby object
|
136
|
+
:enabled: true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Runtime dependencies
|
4
|
+
gem 'rails', '~>4.2.0'
|
5
|
+
|
6
|
+
# Differentiated development dependencies
|
7
|
+
gem 'mysql2', '= 0.3.17'
|
8
|
+
gem 'sidekiq', '~>4.0', require: 'sidekiq/testing'
|
9
|
+
gem 'rspec', '~> 3.4'
|
10
|
+
|
11
|
+
# Development dependencies
|
12
|
+
gem 'instrumental_agent'
|
13
|
+
gem 'rake'
|
14
|
+
gem 'byebug'
|
15
|
+
gem 'gemika'
|
16
|
+
gem 'database_cleaner'
|
17
|
+
gem 'delayed_job_active_record'
|
18
|
+
gem 'resque'
|
19
|
+
gem 'redis'
|
20
|
+
gem 'memcached'
|
21
|
+
gem 'rack-test'
|
22
|
+
|
23
|
+
# Gem under test
|
24
|
+
gem 'metrician', :path => '..'
|