ddmetrics 1.0.0rc1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e96210a080bfe9dbf1c20f2a5f55e9eb1229e5f98387d0872525183d2425020f
4
+ data.tar.gz: 5fedbc494b37439e8fddcab62c1a204ed42f39caca85a9c0a3b40f6901e404c8
5
+ SHA512:
6
+ metadata.gz: 15e3710ac05fe1d383bc7dfcc03c95184179f5ba0888c07c7050e8d42e1588b2bab01193233df2116ed4cb58578f237472937f90afbf985ef2315d4326cfab6b
7
+ data.tar.gz: 6ec53e7fffc7cdf67cae32191f312881fa9db810f2afabcf57fdb2d82f251fccdcc91a92ab67dda70d9b27313e3d6567d96a1898f335cbb3a5bd0354d98d4cfd
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ /.vscode/
4
+ /coverage/
5
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ -r ./spec/spec_helper.rb
2
+ --format Fuubar
3
+ --color
@@ -0,0 +1,59 @@
1
+ # ----- CONFIGURED -----
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+ DisplayCopNames: true
6
+
7
+ Style/TrailingCommaInArguments:
8
+ EnforcedStyleForMultiline: comma
9
+
10
+ Style/TrailingCommaInLiteral:
11
+ EnforcedStyleForMultiline: comma
12
+
13
+ Layout/IndentArray:
14
+ EnforcedStyle: consistent
15
+
16
+ # Documentation lives elsewhere, and not everything needs to be documented.
17
+ Style/Documentation:
18
+ Enabled: false
19
+
20
+ # This doesn’t work well with RSpec.
21
+ Lint/AmbiguousBlockAssociation:
22
+ Exclude:
23
+ - spec/**/*_spec.rb
24
+
25
+
26
+
27
+ # ----- DISABLED (metrics) -----
28
+
29
+ # Cops for metrics are disabled because they should not cause tests to fail.
30
+
31
+ Metrics/AbcSize:
32
+ Enabled: false
33
+
34
+ Metrics/BlockLength:
35
+ Enabled: false
36
+
37
+ Metrics/BlockNesting:
38
+ Enabled: false
39
+
40
+ Metrics/ClassLength:
41
+ Enabled: false
42
+
43
+ Metrics/CyclomaticComplexity:
44
+ Enabled: false
45
+
46
+ Metrics/LineLength:
47
+ Enabled: false
48
+
49
+ Metrics/MethodLength:
50
+ Enabled: false
51
+
52
+ Metrics/ModuleLength:
53
+ Enabled: false
54
+
55
+ Metrics/ParameterLists:
56
+ Enabled: false
57
+
58
+ Metrics/PerceivedComplexity:
59
+ Enabled: false
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.3"
5
+ - "2.4"
6
+ - "2.5"
7
+
8
+ branches:
9
+ only:
10
+ - "master"
11
+
12
+ before_install:
13
+ - gem update --system
14
+ - gem install bundler -v 1.16.0
15
+
16
+ cache: bundler
17
+
18
+ sudo: false
19
+
20
+ git:
21
+ depth: 10
@@ -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 denis.defreyne@stoneship.org. 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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :devel do
8
+ gem 'codecov', require: false
9
+ gem 'fuubar'
10
+ gem 'rake'
11
+ gem 'rspec'
12
+ gem 'rspec-its'
13
+ gem 'rubocop', '~> 0.52'
14
+ gem 'timecop', '~> 0.9'
15
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Denis Defreyne
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/NEWS.md ADDED
@@ -0,0 +1,23 @@
1
+ # DDMetrics news
2
+
3
+ ## 1.0.0rc1 (2018-01-04)
4
+
5
+ Changes:
6
+
7
+ * Renamed to DDMetrics (from DDTelemetry)
8
+
9
+ ## 1.0.0a3 (2017-12-25)
10
+
11
+ Changes:
12
+
13
+ * Made labels be a hash
14
+
15
+ ## 1.0.0a2 (2017-12-18)
16
+
17
+ Changes:
18
+
19
+ * Many API changes to make usage simpler
20
+
21
+ ## 1.0.0a1 (2017-12-02)
22
+
23
+ Initial release.
@@ -0,0 +1,260 @@
1
+ [![Gem version](https://img.shields.io/gem/v/ddmetrics.svg)](http://rubygems.org/gems/ddmetrics)
2
+ [![Gem downloads](https://img.shields.io/gem/dt/ddmetrics.svg)](http://rubygems.org/gems/ddmetrics)
3
+ [![Build status](https://img.shields.io/travis/ddfreyne/ddmetrics.svg)](https://travis-ci.org/ddfreyne/ddmetrics)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/ddfreyne/ddmetrics.svg)](https://codeclimate.com/github/ddfreyne/ddmetrics)
5
+ [![Code Coverage](https://img.shields.io/codecov/c/github/ddfreyne/ddmetrics.svg)](https://codecov.io/gh/ddfreyne/ddmetrics)
6
+
7
+ # DDMetrics
8
+
9
+ _DDMetrics_ is a Ruby library for recording and analysing measurements in short-running Ruby processes.
10
+
11
+ If you are looking for a full-featured timeseries monitoring system, look no further than [Prometheus](https://prometheus.io/).
12
+
13
+ ## Example
14
+
15
+ Take the following (naïve) cache implementation as a starting point:
16
+
17
+ ```ruby
18
+ class Cache
19
+ def initialize
20
+ @map = {}
21
+ end
22
+
23
+ def []=(key, value)
24
+ @map[key] = value
25
+ end
26
+
27
+ def [](key)
28
+ @map[key]
29
+ end
30
+ end
31
+ ```
32
+
33
+ To start instrumenting this code, require `ddmetrics`, create a counter, and record some metrics:
34
+
35
+ ```ruby
36
+ require 'ddmetrics'
37
+
38
+ class Cache
39
+ attr_reader :counter
40
+
41
+ def initialize
42
+ @map = {}
43
+ @counter = DDMetrics::Counter.new
44
+ end
45
+
46
+ def []=(key, value)
47
+ @counter.increment(type: :set)
48
+
49
+ @map[key] = value
50
+ end
51
+
52
+ def [](key)
53
+ if @map.key?(key)
54
+ @counter.increment(type: :get_hit)
55
+ else
56
+ @counter.increment(type: :get_miss)
57
+ end
58
+
59
+ @map[key]
60
+ end
61
+ end
62
+ ```
63
+
64
+ Let’s construct a cache and exercise it:
65
+
66
+ ```ruby
67
+ cache = Cache.new
68
+
69
+ cache['greeting']
70
+ cache['greeting']
71
+ cache['greeting'] = 'Hi there!'
72
+ cache['greeting']
73
+ cache['greeting']
74
+ cache['greeting']
75
+ ```
76
+
77
+ Finally, get the recorded values:
78
+
79
+ ```ruby
80
+ cache.counter.get(type: :set) # => 1
81
+ cache.counter.get(type: :get_hit) # => 3
82
+ cache.counter.get(type: :get_miss) # => 2
83
+ ```
84
+
85
+ Or even print all stats:
86
+
87
+ ```ruby
88
+ puts cache.counter
89
+ ```
90
+
91
+ ```
92
+ │ count
93
+ ──────────────┼──────
94
+ type=get_miss │ 2
95
+ type=set │ 1
96
+ type=get_hit │ 3
97
+ ```
98
+
99
+ ## Scope
100
+
101
+ * No timeseries: Metrics are not recorded over time. If you want to record timeseries data, consider using [Prometheus](https://prometheus.io/).
102
+
103
+ * Not intended for long-running processes: Metrics data (particularly summary metrics) can accumulate in memory and cause memory pressure. This project is not suited for long-running processes, such as servers. For monitoring long-running processes, consider using [Prometheus](https://prometheus.io/).
104
+
105
+ * Not thread-safe: The implementation is not thread-safe. If you require thread safety, consider wrapping the functionality provided.
106
+
107
+ ## Installation
108
+
109
+ Add this line to your application's Gemfile:
110
+
111
+ ```ruby
112
+ gem 'ddmetrics'
113
+ ```
114
+
115
+ And then execute:
116
+
117
+ $ bundle
118
+
119
+ Or install it yourself as:
120
+
121
+ $ gem install ddmetrics
122
+
123
+ ## Usage
124
+
125
+ _DDMetrics_ provides two metric types:
126
+
127
+ * A **counter** is an integer metric that only ever increases. Examples: cache hits, number of files written, …
128
+
129
+ * A **summary** records observations, and provides functionality for describing the distribution of the observations through quantiles. Examples: outgoing request durations, size of written files, …
130
+
131
+ Each metric is recorded with a label, which is a hash that is useful to further refine the kind of data that is being recorded. For example:
132
+
133
+ ```ruby
134
+ cache_hits_counter.increment(target: :file_cache)
135
+ request_durations_summary.observe(1.07, api: :weather)
136
+ ```
137
+
138
+ ### Counters
139
+
140
+ To create a counter, instantiate `DDMetrics::Counter`:
141
+
142
+ ```ruby
143
+ counter = DDMetrics::Counter.new
144
+ ```
145
+
146
+ To increment a counter, call `#increment` with a label:
147
+
148
+ ```ruby
149
+ counter.increment(target: :file_cache)
150
+ ```
151
+
152
+ To get the value for a certain label, use `#get`:
153
+
154
+ ```ruby
155
+ counter.get(target: :file_cache)
156
+ # => 1
157
+ ```
158
+
159
+ ### Summaries
160
+
161
+ To create a summary, instantiate `DDMetrics::Summary`:
162
+
163
+ ```ruby
164
+ summary = DDMetrics::Summary.new
165
+ ```
166
+
167
+ To observe a value, call `#observe` with the value to observe, along with a label:
168
+
169
+ ```ruby
170
+ summary.observe(0.88, api: :weather)
171
+ summary.observe(1.07, api: :weather)
172
+ summary.observe(0.91, api: :weather)
173
+ ```
174
+
175
+ To get the list of observations for a certain label, use `#get`, which will return a `DDMetrics::Stats` instance:
176
+
177
+ ```ruby
178
+ summary.get(api: :weather)
179
+ # => <DDMetrics::Stats>
180
+ ```
181
+
182
+ The following methods are available on `DDMetrics::Stats`:
183
+
184
+ * `#count`: returns the number of values
185
+ * `#sum`: returns the sum of all values
186
+ * `#avg`: returns the average of all values
187
+ * `#min`: returns the minimum value
188
+ * `#max`: returns the maximum value
189
+ * `#quantile(fraction)`: returns the quantile at the given fraction (0.0 – 1.0)
190
+
191
+ ### Printing metrics
192
+
193
+ To print a metric, use `#to_s`. For example:
194
+
195
+ ```ruby
196
+ summary = DDMetrics::Summary.new
197
+
198
+ summary.observe(2.1, filter: :erb)
199
+ summary.observe(4.1, filter: :erb)
200
+ summary.observe(5.3, filter: :haml)
201
+
202
+ puts summary
203
+ ```
204
+
205
+ Output:
206
+
207
+ ```
208
+ │ count min .50 .90 .95 max tot
209
+ ────────────┼────────────────────────────────────────────────
210
+ filter=erb │ 2 2.10 3.10 3.90 4.00 4.10 6.20
211
+ filter=haml │ 1 5.30 5.30 5.30 5.30 5.30 5.30
212
+ ```
213
+
214
+ ### Stopwatch
215
+
216
+ The `DDMetrics::Stopwatch` class can be used to measure durations. Use `#start` and `#stop` to start and stop the stopwatch, respectively, and `#duration` to read the value of the stopwatch:
217
+
218
+ ```ruby
219
+ stopwatch = DDMetrics::Stopwatch.new
220
+
221
+ stopwatch.start
222
+ sleep 1
223
+ stopwatch.stop
224
+ puts "That took #{stopwatch.duration}s."
225
+ # Output: That took 1.006831s.
226
+ ```
227
+
228
+ A stopwatch, once created, will never reset its duration. Running the stopwatch again will add to the existing duration:
229
+
230
+ ```ruby
231
+ stopwatch.start
232
+ sleep 1
233
+ stopwatch.stop
234
+ puts "That took #{stopwatch.duration}s."
235
+ # Output: That took 2.012879s.
236
+ ```
237
+
238
+ You can query whether or not a stopwatch is running using `#running?`; `#stopped?` is the opposite of `#running?`.
239
+
240
+ ## Development
241
+
242
+ Install dependencies:
243
+
244
+ $ bundle
245
+
246
+ Run tests:
247
+
248
+ $ bundle exec rake
249
+
250
+ ## Contributing
251
+
252
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ddfreyne/ddmetrics. 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.
253
+
254
+ ## License
255
+
256
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
257
+
258
+ ## Code of Conduct
259
+
260
+ Everyone interacting in the DDMetrics project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ddfreyne/ddmetrics/blob/master/CODE_OF_CONDUCT.md).