octave 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/.rubocop.yml +13 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +147 -0
- data/Rakefile +6 -0
- data/bin/console +12 -0
- data/lib/octave.rb +80 -0
- data/lib/octave/agent.rb +78 -0
- data/lib/octave/configuration.rb +39 -0
- data/lib/octave/dispatcher/base.rb +15 -0
- data/lib/octave/dispatcher/logger.rb +19 -0
- data/lib/octave/helpers/controller.rb +29 -0
- data/lib/octave/payload.rb +35 -0
- data/lib/octave/railtie.rb +7 -0
- data/lib/octave/version.rb +3 -0
- data/octave.gemspec +38 -0
- metadata +136 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 11bb2ac77dc3104221e59d1dbf43bb046a5ff5779d5374fb907fc4597cb0bf00
|
|
4
|
+
data.tar.gz: 6d43e61eb77e332a3b9bb48e3687c0008407ee2b0cf58e714c34f08aa2cbd6ea
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dbfe57def821bd550cccece8f6869be2b2fbc6e91c2f9dc4f748ee17989bd08023bd32ff9f48220732811bad604646bd5425151c757eef0f1ff5a43543ac615e
|
|
7
|
+
data.tar.gz: 11a7a13924d3fbd3653d1830c0e31a7e66e9197efffa7dc362224413a98dbeb30cb31ec6bc5cdf7ecc3b495770061f071087fc2e2b6820562b39f64af3689efd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at drewtempelmeyer@users.noreply.github.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
octave (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ast (2.4.0)
|
|
10
|
+
coderay (1.1.2)
|
|
11
|
+
diff-lcs (1.3)
|
|
12
|
+
jaro_winkler (1.5.2)
|
|
13
|
+
method_source (0.9.2)
|
|
14
|
+
parallel (1.17.0)
|
|
15
|
+
parser (2.6.3.0)
|
|
16
|
+
ast (~> 2.4.0)
|
|
17
|
+
pry (0.12.2)
|
|
18
|
+
coderay (~> 1.1.0)
|
|
19
|
+
method_source (~> 0.9.0)
|
|
20
|
+
rainbow (3.0.0)
|
|
21
|
+
rake (10.5.0)
|
|
22
|
+
rspec (3.8.0)
|
|
23
|
+
rspec-core (~> 3.8.0)
|
|
24
|
+
rspec-expectations (~> 3.8.0)
|
|
25
|
+
rspec-mocks (~> 3.8.0)
|
|
26
|
+
rspec-core (3.8.0)
|
|
27
|
+
rspec-support (~> 3.8.0)
|
|
28
|
+
rspec-expectations (3.8.3)
|
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
30
|
+
rspec-support (~> 3.8.0)
|
|
31
|
+
rspec-mocks (3.8.0)
|
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
|
+
rspec-support (~> 3.8.0)
|
|
34
|
+
rspec-support (3.8.0)
|
|
35
|
+
rubocop (0.68.1)
|
|
36
|
+
jaro_winkler (~> 1.5.1)
|
|
37
|
+
parallel (~> 1.10)
|
|
38
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
40
|
+
ruby-progressbar (~> 1.7)
|
|
41
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
|
42
|
+
rubocop-performance (1.2.0)
|
|
43
|
+
rubocop (>= 0.68.0)
|
|
44
|
+
ruby-progressbar (1.10.0)
|
|
45
|
+
unicode-display_width (1.5.0)
|
|
46
|
+
|
|
47
|
+
PLATFORMS
|
|
48
|
+
ruby
|
|
49
|
+
|
|
50
|
+
DEPENDENCIES
|
|
51
|
+
bundler (~> 2.0)
|
|
52
|
+
octave!
|
|
53
|
+
pry
|
|
54
|
+
rake (~> 10.0)
|
|
55
|
+
rspec (~> 3.0)
|
|
56
|
+
rubocop (~> 0.68.1)
|
|
57
|
+
rubocop-performance (~> 1.2.0)
|
|
58
|
+
|
|
59
|
+
BUNDLED WITH
|
|
60
|
+
2.0.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Drew Tempelmeyer
|
|
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,147 @@
|
|
|
1
|
+
# Octave
|
|
2
|
+
|
|
3
|
+
Octave enables you to collect timing metrics on your application's performance.
|
|
4
|
+
Send your metrics to multiple sources.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem "octave", "~> 0.1.0"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install octave
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
Octave.configure do |config|
|
|
26
|
+
# Set the maximum number of objects for the queue. Default is 1500
|
|
27
|
+
config.max_queue = 2000
|
|
28
|
+
# Enable/disable the agent. Default is true
|
|
29
|
+
config.enabled = true
|
|
30
|
+
# Set the logger. Default is Logger.new(STDOUT)
|
|
31
|
+
config.logger = Logger.new(STDOUT)
|
|
32
|
+
# Define your list of dispatchers. Default is [Octave::Dispatcher::Logger.new]
|
|
33
|
+
config.dispatchers = [ Octave::Dispatcher::Logger.new ]
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If you're not using Rails, you'll need to manually start the Octave agent:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
Octave.start
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
To measure the time it takes to execute a segment of code, Octave provides the
|
|
46
|
+
`Octave.measure` method.
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
Octave.measure("metric-name") do
|
|
50
|
+
process_credit_card
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Octave will then push the measurement to each of your configured dispatchers.
|
|
55
|
+
|
|
56
|
+
### Using with Rails
|
|
57
|
+
|
|
58
|
+
Octave will automatically start the agent when integrated with a Rails
|
|
59
|
+
application (no need to call `Octave.start`).
|
|
60
|
+
|
|
61
|
+
#### Measuring actions
|
|
62
|
+
|
|
63
|
+
Include the `Octave::Helpers::Controller` module to add a method to log the time
|
|
64
|
+
it takes to execute each action. To log every action in your application:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
class ApplicationController < ActionController::Base
|
|
68
|
+
include Octave::Helpers::Controller
|
|
69
|
+
|
|
70
|
+
around_action :measure_action
|
|
71
|
+
end
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
That's it! If you want to change the metric name (controller_name.action_name,
|
|
75
|
+
by default), override the `measure_action_name` method.
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
class ApplicationController < ActionController::Base
|
|
79
|
+
include Octave::Helpers::Controller
|
|
80
|
+
|
|
81
|
+
around_action :measure_action
|
|
82
|
+
|
|
83
|
+
def measure_action_name
|
|
84
|
+
"app.#{controller_name}.#{action_name}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Dispatchers
|
|
90
|
+
|
|
91
|
+
Octave dispatchers receive the measurement payload to transform and persist the
|
|
92
|
+
data. Octave ships with an `Octave::Dispatcher::Logger` dispatcher which simply
|
|
93
|
+
sends the measurement to the configured logger (`Octave.config.logger`).
|
|
94
|
+
|
|
95
|
+
To configure your dispatchers:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
# Send the log output to a StringIO instance
|
|
99
|
+
logger_io = StringIO.new
|
|
100
|
+
|
|
101
|
+
Octave.configure do |config|
|
|
102
|
+
config.dispatchers = [
|
|
103
|
+
Octave::Dispatchers::Logger.new(Logger.new(logger_io))
|
|
104
|
+
]
|
|
105
|
+
end
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Creating a Dispatcher
|
|
109
|
+
|
|
110
|
+
Dispatchers only expect two instance methods: `call` and `close`. When a
|
|
111
|
+
measurement is dispatched, Octave sends the payload to each dispatcher's `call`
|
|
112
|
+
method.
|
|
113
|
+
|
|
114
|
+
When Octave is shutting down, `close` is used to close any open connections,
|
|
115
|
+
sockets, or perform any additional cleanup.
|
|
116
|
+
|
|
117
|
+
If we're wanting to log each measurement using puts, we can create a puts
|
|
118
|
+
dispatcher:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
class PutsDispatcher < Octave::Dispatcher::Base
|
|
122
|
+
def call(payload)
|
|
123
|
+
puts "#{payload.name} took #{payload.duration}ms to execute."
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
For Octave to use the dispatcher, we'll need to enable it by adding it to the
|
|
129
|
+
array of dispatchers:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
Octave.configure do |config|
|
|
133
|
+
config.dispatchers = [ PutsDispatcher.new ]
|
|
134
|
+
end
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Contributing
|
|
138
|
+
|
|
139
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/octaverb/octave. 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.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
144
|
+
|
|
145
|
+
## Code of Conduct
|
|
146
|
+
|
|
147
|
+
Everyone interacting in the Octave project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/octave/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/lib/octave.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require "octave/version"
|
|
2
|
+
require "octave/configuration"
|
|
3
|
+
require "octave/dispatcher/base"
|
|
4
|
+
require "octave/dispatcher/logger"
|
|
5
|
+
require "octave/payload"
|
|
6
|
+
require "octave/agent"
|
|
7
|
+
|
|
8
|
+
if defined?(Rails)
|
|
9
|
+
require "octave/helpers/controller"
|
|
10
|
+
require "octave/railtie"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Octave #:nodoc:
|
|
14
|
+
class << self
|
|
15
|
+
attr_writer :config
|
|
16
|
+
|
|
17
|
+
# Configures Octave. See <tt>Octave::Configuration</tt> for configuration
|
|
18
|
+
# options.
|
|
19
|
+
#
|
|
20
|
+
# == Example
|
|
21
|
+
# Octave.configure do |config|
|
|
22
|
+
# config.logger = Rails.logger
|
|
23
|
+
# end
|
|
24
|
+
def configure
|
|
25
|
+
self.config ||= Configuration.new
|
|
26
|
+
yield(config)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [Configuration] The current Octave configuration
|
|
30
|
+
def config
|
|
31
|
+
@config ||= Configuration.new
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Resets the configuration to the default
|
|
35
|
+
def reset_config
|
|
36
|
+
@config = nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Shortcut method to access <tt>Octave.config.logger</tt>.
|
|
40
|
+
def logger
|
|
41
|
+
Octave.config.logger
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Measure the performance of a block.
|
|
45
|
+
#
|
|
46
|
+
# == Example
|
|
47
|
+
# Octave.measure("process-card") do
|
|
48
|
+
# process_credit_card
|
|
49
|
+
# end
|
|
50
|
+
def measure(name, options = {})
|
|
51
|
+
payload = Payload.new(name, options)
|
|
52
|
+
result = yield
|
|
53
|
+
|
|
54
|
+
dispatch(payload.tap(&:done))
|
|
55
|
+
result
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Dispatches the payload to the current agent
|
|
59
|
+
def dispatch(payload)
|
|
60
|
+
agent.dispatch(payload) if agent.running?
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Starts the agent
|
|
64
|
+
def start
|
|
65
|
+
agent.start
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Stops the agent
|
|
69
|
+
def stop
|
|
70
|
+
agent.stop
|
|
71
|
+
@agent = nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def agent
|
|
77
|
+
@agent ||= Agent.new
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/lib/octave/agent.rb
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Octave
|
|
2
|
+
# The agent handles managing the queue and dispatching the payload to each
|
|
3
|
+
# configured dispatcher.
|
|
4
|
+
class Agent
|
|
5
|
+
def initialize
|
|
6
|
+
@queue = SizedQueue.new(Octave.config.max_queue)
|
|
7
|
+
@running = false
|
|
8
|
+
|
|
9
|
+
at_exit(&method(:stop))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Adds the payload to the queue.
|
|
13
|
+
#
|
|
14
|
+
# @param payload [Payload] the payload to be added to the queue.
|
|
15
|
+
def dispatch(payload)
|
|
16
|
+
queue.push(payload)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Start the agent process and begin dispatching events.
|
|
20
|
+
def start
|
|
21
|
+
unless Octave.config.enabled?
|
|
22
|
+
Octave.logger.warn do
|
|
23
|
+
"Octave agent is disabled. Metrics will not be reported."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
return
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Octave.logger.info { "Starting Octave agent..." }
|
|
30
|
+
|
|
31
|
+
@thread = Thread.new(&method(:run))
|
|
32
|
+
@running = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Loop to pass the payload to each dispatcher as the payload enters the
|
|
36
|
+
# queue.
|
|
37
|
+
def run
|
|
38
|
+
while running? || !queue.empty?
|
|
39
|
+
payload = queue.pop(false)
|
|
40
|
+
call_dispatchers(payload)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Stop the agent.
|
|
45
|
+
def stop
|
|
46
|
+
return unless running?
|
|
47
|
+
|
|
48
|
+
@queue.close
|
|
49
|
+
@thread.exit
|
|
50
|
+
dispatchers.each(&:close)
|
|
51
|
+
@running = false
|
|
52
|
+
|
|
53
|
+
true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Determines whether the agent is running.
|
|
57
|
+
#
|
|
58
|
+
# @return [Boolean]
|
|
59
|
+
def running?
|
|
60
|
+
@running
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
attr_reader :queue
|
|
66
|
+
|
|
67
|
+
# Submits the payload to each dispatcher.
|
|
68
|
+
def call_dispatchers(payload)
|
|
69
|
+
dispatchers.each do |dispatcher|
|
|
70
|
+
dispatcher.call(payload)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def dispatchers
|
|
75
|
+
Octave.config.dispatchers
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "logger"
|
|
2
|
+
|
|
3
|
+
module Octave
|
|
4
|
+
# Handle the configuration of the Octave agent.
|
|
5
|
+
class Configuration
|
|
6
|
+
# Maximum size of the queue. Default is 1500
|
|
7
|
+
# @return [Numeric]
|
|
8
|
+
attr_accessor :max_queue
|
|
9
|
+
|
|
10
|
+
# Logger to be used for logging events and debugging. Default is
|
|
11
|
+
# <tt>Logger.new(STDOUT)</tt>.
|
|
12
|
+
attr_accessor :logger
|
|
13
|
+
|
|
14
|
+
# Array of dispatchers to be used once a <tt>Payload</tt> has been
|
|
15
|
+
# completed. Default is <tt>[Octave::Dispatcher::Logger.new]</tt>.
|
|
16
|
+
# @return [Array] Array containing dispatchers
|
|
17
|
+
attr_writer :dispatchers
|
|
18
|
+
|
|
19
|
+
# Enable the agent. Default is true.
|
|
20
|
+
attr_writer :enabled
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
@max_queue = 1500
|
|
24
|
+
@logger = Logger.new(STDOUT)
|
|
25
|
+
@enabled = true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def dispatchers
|
|
29
|
+
@dispatchers ||= [
|
|
30
|
+
Octave::Dispatcher::Logger.new
|
|
31
|
+
]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [Boolean] Whether or not the agent is enabled
|
|
35
|
+
def enabled?
|
|
36
|
+
@enabled
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Octave
|
|
2
|
+
module Dispatcher
|
|
3
|
+
class Logger < Base
|
|
4
|
+
def new(logger = nil)
|
|
5
|
+
@logger = logger
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def call(payload)
|
|
9
|
+
logger.info { "#{payload.name} took #{payload.duration}ms" }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def logger
|
|
15
|
+
@logger || Octave.logger
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Octave
|
|
2
|
+
module Helpers
|
|
3
|
+
# Helpers to include in your Rails controllers to automatically collect
|
|
4
|
+
# metrics on how long it takes to complete an action.
|
|
5
|
+
#
|
|
6
|
+
# == Example
|
|
7
|
+
# class PostsController < ActionController::Base
|
|
8
|
+
# include Octave::Helpers::Controller
|
|
9
|
+
#
|
|
10
|
+
# around_action :measure_action
|
|
11
|
+
# end
|
|
12
|
+
module Controller
|
|
13
|
+
# Measures the duration of the action.
|
|
14
|
+
#
|
|
15
|
+
# == Example
|
|
16
|
+
# around_action :measure_action, only: %i[create update destroy]
|
|
17
|
+
def measure_action(&block)
|
|
18
|
+
Octave.measure(measure_action_name, &block)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The name of the metric. Default is
|
|
22
|
+
# <tt>#{controller_name}.#{action_name}</tt>. Override this method if
|
|
23
|
+
# you would like to specify your own name.
|
|
24
|
+
def measure_action_name
|
|
25
|
+
[controller_name, action_name].join(".")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Octave
|
|
2
|
+
# A Payload contains information about each metric and the time to complete.
|
|
3
|
+
# After each Payload has been completed, it will be sent to each dispatcher.
|
|
4
|
+
#
|
|
5
|
+
# To manually create a payload and send it to the dispatcher:
|
|
6
|
+
# payload = Payload.new("name-of-event")
|
|
7
|
+
# expensive_method
|
|
8
|
+
# payload.done
|
|
9
|
+
# Octave.dispatch(payload)
|
|
10
|
+
class Payload
|
|
11
|
+
attr_reader :name, :options, :start_time, :end_time
|
|
12
|
+
|
|
13
|
+
# Creates a new Payload.
|
|
14
|
+
#
|
|
15
|
+
# @param name [String] The name of the metric
|
|
16
|
+
# @param options [Hash] Hash containing options. Useful for passing to dispatchers
|
|
17
|
+
def initialize(name, options = {})
|
|
18
|
+
@start_time = Time.now
|
|
19
|
+
@name = name
|
|
20
|
+
@options = options
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Call this method immediately after the work has been completed.
|
|
24
|
+
def done
|
|
25
|
+
@end_time = Time.now
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Duration of the metric in milliseconds.
|
|
29
|
+
def duration
|
|
30
|
+
return if end_time.nil?
|
|
31
|
+
|
|
32
|
+
(end_time - start_time) * 1000.0
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/octave.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "octave/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "octave"
|
|
7
|
+
spec.version = Octave::VERSION
|
|
8
|
+
spec.authors = ["Drew Tempelmeyer"]
|
|
9
|
+
spec.email = ["drewtempelmeyer@users.noreply.github.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Collect application performance metrics."
|
|
12
|
+
spec.description = "Collect application performance metrics."
|
|
13
|
+
spec.homepage = "https://github.com/octaverb/octave"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
if spec.respond_to?(:metadata)
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/octaverb/octave"
|
|
19
|
+
else
|
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
21
|
+
"public gem pushes."
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
26
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| 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_development_dependency "bundler", "~> 2.0"
|
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
36
|
+
spec.add_development_dependency "rubocop", "~> 0.68.1"
|
|
37
|
+
spec.add_development_dependency "rubocop-performance", "~> 1.2.0"
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: octave
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Drew Tempelmeyer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-05-13 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: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
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: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rubocop
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.68.1
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.68.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop-performance
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 1.2.0
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 1.2.0
|
|
83
|
+
description: Collect application performance metrics.
|
|
84
|
+
email:
|
|
85
|
+
- drewtempelmeyer@users.noreply.github.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".rspec"
|
|
92
|
+
- ".rubocop.yml"
|
|
93
|
+
- ".travis.yml"
|
|
94
|
+
- CODE_OF_CONDUCT.md
|
|
95
|
+
- Gemfile
|
|
96
|
+
- Gemfile.lock
|
|
97
|
+
- LICENSE.txt
|
|
98
|
+
- README.md
|
|
99
|
+
- Rakefile
|
|
100
|
+
- bin/console
|
|
101
|
+
- lib/octave.rb
|
|
102
|
+
- lib/octave/agent.rb
|
|
103
|
+
- lib/octave/configuration.rb
|
|
104
|
+
- lib/octave/dispatcher/base.rb
|
|
105
|
+
- lib/octave/dispatcher/logger.rb
|
|
106
|
+
- lib/octave/helpers/controller.rb
|
|
107
|
+
- lib/octave/payload.rb
|
|
108
|
+
- lib/octave/railtie.rb
|
|
109
|
+
- lib/octave/version.rb
|
|
110
|
+
- octave.gemspec
|
|
111
|
+
homepage: https://github.com/octaverb/octave
|
|
112
|
+
licenses:
|
|
113
|
+
- MIT
|
|
114
|
+
metadata:
|
|
115
|
+
homepage_uri: https://github.com/octaverb/octave
|
|
116
|
+
source_code_uri: https://github.com/octaverb/octave
|
|
117
|
+
post_install_message:
|
|
118
|
+
rdoc_options: []
|
|
119
|
+
require_paths:
|
|
120
|
+
- lib
|
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
requirements: []
|
|
132
|
+
rubygems_version: 3.0.3
|
|
133
|
+
signing_key:
|
|
134
|
+
specification_version: 4
|
|
135
|
+
summary: Collect application performance metrics.
|
|
136
|
+
test_files: []
|