active_metrics 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 82af20ffaf35ac07447725515c74159d5d6c7605
4
- data.tar.gz: 6398d51851ec95a8821e9c68343d5200a5a00197
2
+ SHA256:
3
+ metadata.gz: a99f62aed5e38e762fcaba320d21fce604fb938d6e5d88d7149c427c4e631522
4
+ data.tar.gz: 1c41b03b70bee9233f393d56928bf27a7d1ccdbc73fe15ad26463e18a30adc6a
5
5
  SHA512:
6
- metadata.gz: 9c631ce7c816a8ed6e7d57efa628d6f289c36c769b8ad7f52fd60775038137230c7fb116ec882fb106021bca5ffcf35734054e1055d649909d5c530a95e74479
7
- data.tar.gz: c98272fcde5a3783f70b96189b8e1d17ea6dbdfd80dca23ed9f3a36b3d5facbaada2b4fee48c976286b61ce61e3d88bef5b8a2cefb86f35a046ff38862836af6
6
+ metadata.gz: 819bfc8020b1a0a1a73d9bcf71a9ac6bde6221e8f5e9a59e2f209f3df04aa92a30fa8ec7ef852dee7099326cfecd29a779b9af4b0f23306e466564e2894456ae
7
+ data.tar.gz: 541ec4d9652984784e88cc474e9e495926bba7c43899d698e2e55e3d4c4fb7160278ed083dc002cf5ca8566ebf41091ce48479413897e7a08097401123f57399
data/Dockerfile CHANGED
@@ -1,50 +1,50 @@
1
- FROM ruby:2.5.0
2
-
3
- # Bundler options
4
- #
5
- # The default value is taken from Travis's build options, so they should be
6
- # good enough for most cases. For development, be sure to set a blank default
7
- # in docker-compose.override.yml.
8
- ARG BUNDLER_OPTS="--jobs=3 \
9
- --retry=3 \
10
- --deployment"
11
-
12
- # The home directory of the gem.
13
- #
14
- # During development, make sure that the APP_DIR environment variable is
15
- # identical to the variable in your docker-compose.override.yml file,
16
- # otherwise things might not work as expected.
17
- ENV APP_DIR="/opt/active_metrics"
18
-
19
- # Create a non-root user
20
- RUN groupadd -r travis \
21
- && useradd -m -r -g travis travis
22
- RUN mkdir -p ${APP_DIR} \
23
- && chown -R travis:travis ${APP_DIR}
24
-
25
- # Move the the application folder to perform all the following tasks.
26
- WORKDIR ${APP_DIR}
27
- # Use the non-root user to perform any commands from this point forward.
28
- #
29
- # NOTE: The COPY command requires the --chown flag set otherwise it will
30
- # copy things as root.
31
- USER travis
32
-
33
- # Copy the gem's gemspec file so `bundle install` can run when the
34
- # container is initialized.
35
- #
36
- # The added benefit is that Docker will cache this file and will not trigger
37
- # the bundle install unless the gemspec changed on the filesystem.
38
- #
39
- # NOTE: If the command fails because of the --chown flag, make sure you have a
40
- # recent stable version of Docker.
41
- COPY --chown=travis:travis . ./
42
-
43
-
44
- RUN bundle install ${BUNDLER_OPTS}
45
-
46
- # Copy over the files, in case the Docker Compose file does not specify a
47
- # mount point.
48
- COPY --chown=travis:travis . ./
49
-
1
+ FROM ruby:2.5.0
2
+
3
+ # Bundler options
4
+ #
5
+ # The default value is taken from Travis's build options, so they should be
6
+ # good enough for most cases. For development, be sure to set a blank default
7
+ # in docker-compose.override.yml.
8
+ ARG BUNDLER_OPTS="--jobs=3 \
9
+ --retry=3 \
10
+ --deployment"
11
+
12
+ # The home directory of the gem.
13
+ #
14
+ # During development, make sure that the APP_DIR environment variable is
15
+ # identical to the variable in your docker-compose.override.yml file,
16
+ # otherwise things might not work as expected.
17
+ ENV APP_DIR="/opt/active_metrics"
18
+
19
+ # Create a non-root user
20
+ RUN groupadd -r travis \
21
+ && useradd -m -r -g travis travis
22
+ RUN mkdir -p ${APP_DIR} \
23
+ && chown -R travis:travis ${APP_DIR}
24
+
25
+ # Move the the application folder to perform all the following tasks.
26
+ WORKDIR ${APP_DIR}
27
+ # Use the non-root user to perform any commands from this point forward.
28
+ #
29
+ # NOTE: The COPY command requires the --chown flag set otherwise it will
30
+ # copy things as root.
31
+ USER travis
32
+
33
+ # Copy the gem's gemspec file so `bundle install` can run when the
34
+ # container is initialized.
35
+ #
36
+ # The added benefit is that Docker will cache this file and will not trigger
37
+ # the bundle install unless the gemspec changed on the filesystem.
38
+ #
39
+ # NOTE: If the command fails because of the --chown flag, make sure you have a
40
+ # recent stable version of Docker.
41
+ COPY --chown=travis:travis . ./
42
+
43
+
44
+ RUN bundle install ${BUNDLER_OPTS}
45
+
46
+ # Copy over the files, in case the Docker Compose file does not specify a
47
+ # mount point.
48
+ COPY --chown=travis:travis . ./
49
+
50
50
  CMD ["bash"]
@@ -23,7 +23,7 @@ GEM
23
23
  pry (0.11.1)
24
24
  coderay (~> 1.1.0)
25
25
  method_source (~> 0.9.0)
26
- rake (10.5.0)
26
+ rake (13.0.1)
27
27
  simplecov (0.15.1)
28
28
  docile (~> 1.1.0)
29
29
  json (>= 1.8, < 3)
@@ -42,8 +42,8 @@ DEPENDENCIES
42
42
  bundler (~> 1.16)
43
43
  minitest (~> 5.0)
44
44
  pry (~> 0.11)
45
- rake (~> 10.0)
45
+ rake (~> 13.0)
46
46
  simplecov (~> 0.15)
47
47
 
48
48
  BUNDLED WITH
49
- 1.16.1
49
+ 1.17.2
data/README.md CHANGED
@@ -28,7 +28,7 @@ require 'active_metrics'
28
28
  class Foo
29
29
 
30
30
  include ActiveMetrics::Instrumentable
31
-
31
+
32
32
  def bar
33
33
  count 'method.bar'
34
34
  end
@@ -44,6 +44,12 @@ Available methods:
44
44
 
45
45
  Be mindful of any kind of conflicts when including the module in your class.
46
46
 
47
+ ### Disabling the metrics
48
+
49
+ For various environments (development and QA), the metrics can be a bit too
50
+ verbose and have very little value. In those cases, the metrics can be disabled
51
+ using by using the `SILENT_METRICS=1` environment variable.
52
+
47
53
  ## Contributing
48
54
 
49
55
  Bug reports and pull requests are welcome on GitHub at [https://github.com/andreimaxim/active_metrics.]()
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'active_metrics/version'
@@ -21,7 +20,7 @@ Gem::Specification.new do |spec|
21
20
  spec.require_paths = ['lib']
22
21
 
23
22
  spec.add_development_dependency 'bundler', '~> 1.16'
24
- spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rake', '~> 13.0'
25
24
  spec.add_development_dependency 'minitest', '~> 5.0'
26
25
  spec.add_development_dependency 'simplecov', '~> 0.15'
27
26
  spec.add_development_dependency 'pry', '~> 0.11'
@@ -1,6 +1,6 @@
1
- version: '3'
2
-
3
- services:
4
-
5
- gem:
1
+ version: '3'
2
+
3
+ services:
4
+
5
+ gem:
6
6
  build: .
@@ -1,49 +1,57 @@
1
- module ActiveMetrics
2
- class Collector
3
-
4
- PREFIX = 'com.active_metrics'.freeze
5
-
6
- class << self
7
-
8
- # Start subscribing to the metrics-related events.
9
- def attach
10
- ActiveSupport::Notifications.subscribe(/#{PREFIX}/i) do |name, _, _, _, data|
11
- deliver(name, data)
12
- end
13
- end
14
-
15
- # Deliver a metric to Librato
16
- #
17
- # According to the Heroku DevCenter there is already a tight integration
18
- # between Heroku logs and Librato so simply using `$stdout.puts` will be
19
- # enough, as long as a specific format is used.
20
- #
21
- # @param name [String] The name of the event being measured
22
- # @param data [Hash] a Hash with type of metric and the value to be recorded
23
- def deliver(name, data = {})
24
- key = name.gsub(PREFIX, '')
25
- value = data[:value]
26
- metric = data[:metric]
27
-
28
- $stdout.puts "#{metric}##{key}=#{value}"
29
- end
30
-
31
- # Record an event
32
- #
33
- # @param event [String] The name of the event
34
- # @param payload [Hash] A hash that contains the event-related data.
35
- def record(event, payload = {})
36
- # Add a prefix to all events so things broadcasted using this method
37
- # will not get picked up by possibly other `ActiveSupport::Notifications`
38
- # subscribers.
39
- name = "#{PREFIX}#{event}"
40
-
41
- if block_given?
42
- ActiveSupport::Notifications.instrument(name, payload) { yield }
43
- else
44
- ActiveSupport::Notifications.instrument(name, payload)
45
- end
46
- end
47
- end
48
- end
49
- end
1
+ module ActiveMetrics
2
+ class Collector
3
+
4
+ PREFIX = 'com.active_metrics'.freeze
5
+
6
+ class << self
7
+
8
+ # Should the metrics be silent?
9
+ #
10
+ # Useful especially in QA or development environments, where you'll
11
+ # might not want your logs to be filled with various metrics.
12
+ def silent?
13
+ [1, '1', 'true'].include?(ENV['SILENT_METRICS'])
14
+ end
15
+
16
+ # Start subscribing to the metrics-related events.
17
+ def attach
18
+ ActiveSupport::Notifications.subscribe(/#{PREFIX}/i) do |name, _, _, _, data|
19
+ deliver(name, data)
20
+ end
21
+ end
22
+
23
+ # Deliver a metric to Librato
24
+ #
25
+ # According to the Heroku DevCenter there is already a tight integration
26
+ # between Heroku logs and Librato so simply using `$stdout.puts` will be
27
+ # enough, as long as a specific format is used.
28
+ #
29
+ # @param name [String] The name of the event being measured
30
+ # @param data [Hash] a Hash with type of metric and the value to be recorded
31
+ def deliver(name, data = {})
32
+ key = name.gsub(PREFIX, '')
33
+ value = data[:value]
34
+ metric = data[:metric]
35
+
36
+ $stdout.puts "#{metric}##{key}=#{value}" unless silent?
37
+ end
38
+
39
+ # Record an event
40
+ #
41
+ # @param event [String] The name of the event
42
+ # @param payload [Hash] A hash that contains the event-related data.
43
+ def record(event, payload = {})
44
+ # Add a prefix to all events so things broadcasted using this method
45
+ # will not get picked up by possibly other `ActiveSupport::Notifications`
46
+ # subscribers.
47
+ name = "#{PREFIX}#{event}"
48
+
49
+ if block_given?
50
+ ActiveSupport::Notifications.instrument(name, payload) { yield }
51
+ else
52
+ ActiveSupport::Notifications.instrument(name, payload)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,67 +1,67 @@
1
- module ActiveMetrics
2
- ##
3
- # Custom metrics for Librato
4
- module Instrumentable
5
-
6
- # Count log lines are used to submit increments to Librato.
7
- #
8
- # You can submit increments as frequently as desired and every minute the
9
- # current total will be flushed to Librato and reset to zero.
10
- #
11
- # @param event [String] The name of the event
12
- # @param number [Integer] The number to increment the current count (defaults to 1)
13
- def count(event, number = 1)
14
- ActiveMetrics::Collector.record(event, { metric: 'count', value: number })
15
- end
16
-
17
- # Measure log lines are used to submit individual measurements that comprise
18
- # a statistical distribution. The most common use case are timings i.e.
19
- # latency measurements, but it can also be used to represent non-temporal
20
- # distributions such as counts.
21
- #
22
- # You can submit as many measures as you’d like (typically they are
23
- # submitted per-request) and every minute Librato will calculate/record a
24
- # complete set of summary statistics over the measures submitted in that
25
- # interval.
26
- #
27
- # The `measure` method also accepts a block of code which will automatically
28
- # measure the amount of time spent running that block:
29
- #
30
- # measure 'foo.bar.baz' do
31
- # Foo.bar #=> 'baz'
32
- # end
33
- #
34
- # For convenience, when `measure` is used with a block it will return the
35
- # value returned by the block.
36
- #
37
- # @param event [String] The name of the event
38
- # @param value [Integer, String] The value measured.
39
- def measure(event, value = 0)
40
- if block_given?
41
- time = Time.now
42
- # Store the value returned by the block for future reference
43
- value = yield
44
- delta = Time.now - time
45
-
46
- ActiveMetrics::Collector.record(event, { metric: 'measure', value: delta })
47
-
48
- value
49
- else
50
- ActiveMetrics::Collector.record(event, { metric: 'measure', value: value })
51
- end
52
- end
53
-
54
- # Sample metrics are used to convey simple key/numerical value pairs when
55
- # you are already calculating some kind of summary statistic in your app and
56
- # merely need a simple transport mechanism to Librato.
57
- #
58
- # Typically you would submit sample metrics on some periodic tick and set
59
- # said period on the metric in Librato.
60
- #
61
- # @param key [String] The name of the sample
62
- # @param value [Object] The value of the sample
63
- def sample(key, value)
64
- ActiveMetrics::Collector.record(key, { metric: 'sample', value: value })
65
- end
66
- end
1
+ module ActiveMetrics
2
+ ##
3
+ # Custom metrics for Librato
4
+ module Instrumentable
5
+
6
+ # Count log lines are used to submit increments to Librato.
7
+ #
8
+ # You can submit increments as frequently as desired and every minute the
9
+ # current total will be flushed to Librato and reset to zero.
10
+ #
11
+ # @param event [String] The name of the event
12
+ # @param number [Integer] The number to increment the current count (defaults to 1)
13
+ def count(event, number = 1)
14
+ ActiveMetrics::Collector.record(event, { metric: 'count', value: number })
15
+ end
16
+
17
+ # Measure log lines are used to submit individual measurements that comprise
18
+ # a statistical distribution. The most common use case are timings i.e.
19
+ # latency measurements, but it can also be used to represent non-temporal
20
+ # distributions such as counts.
21
+ #
22
+ # You can submit as many measures as you’d like (typically they are
23
+ # submitted per-request) and every minute Librato will calculate/record a
24
+ # complete set of summary statistics over the measures submitted in that
25
+ # interval.
26
+ #
27
+ # The `measure` method also accepts a block of code which will automatically
28
+ # measure the amount of time spent running that block:
29
+ #
30
+ # measure 'foo.bar.baz' do
31
+ # Foo.bar #=> 'baz'
32
+ # end
33
+ #
34
+ # For convenience, when `measure` is used with a block it will return the
35
+ # value returned by the block.
36
+ #
37
+ # @param event [String] The name of the event
38
+ # @param value [Integer, String] The value measured.
39
+ def measure(event, value = 0)
40
+ if block_given?
41
+ time = Time.now
42
+ # Store the value returned by the block for future reference
43
+ value = yield
44
+ delta = Time.now - time
45
+
46
+ ActiveMetrics::Collector.record(event, { metric: 'measure', value: delta })
47
+
48
+ value
49
+ else
50
+ ActiveMetrics::Collector.record(event, { metric: 'measure', value: value })
51
+ end
52
+ end
53
+
54
+ # Sample metrics are used to convey simple key/numerical value pairs when
55
+ # you are already calculating some kind of summary statistic in your app and
56
+ # merely need a simple transport mechanism to Librato.
57
+ #
58
+ # Typically you would submit sample metrics on some periodic tick and set
59
+ # said period on the metric in Librato.
60
+ #
61
+ # @param key [String] The name of the sample
62
+ # @param value [Object] The value of the sample
63
+ def sample(key, value)
64
+ ActiveMetrics::Collector.record(key, { metric: 'sample', value: value })
65
+ end
66
+ end
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMetrics
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,100 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Maxim
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-24 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.16'
19
- name: bundler
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rake
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: '10.0'
33
- name: rake
34
- prerelease: false
33
+ version: '13.0'
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: minitest
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '5.0'
47
- name: minitest
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: simplecov
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0.15'
61
- name: simplecov
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.15'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: pry
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - "~>"
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0.11'
75
- name: pry
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.11'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: activesupport
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: 3.0.0
89
- name: activesupport
90
- prerelease: false
91
90
  type: :runtime
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.0.0
97
- description:
97
+ description:
98
98
  email:
99
99
  - andrei@andreimaxim.ro
100
100
  executables: []
@@ -122,7 +122,7 @@ homepage: https://github.com/andreimaxim/active_metrics
122
122
  licenses:
123
123
  - MIT
124
124
  metadata: {}
125
- post_install_message:
125
+ post_install_message:
126
126
  rdoc_options: []
127
127
  require_paths:
128
128
  - lib
@@ -137,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.6.14.1
142
- signing_key:
140
+ rubygems_version: 3.0.3
141
+ signing_key:
143
142
  specification_version: 4
144
143
  summary: Metrics based on ActiveSupport::Notifications
145
144
  test_files: []