metrics 0.5.0 → 0.6.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
2
  SHA256:
3
- metadata.gz: e702c99fcc40f6be98ab5cab1d6ff490fbcd6bd6cf1d792a643f45573c4cd710
4
- data.tar.gz: 35ec716809e70775717f18bc10a4f70165cad91a1bbd076b200f847c812c764c
3
+ metadata.gz: 97bd0f590ab9a19775a10d083f0fd136eb9df4983dcaf414377775d6f9b7a3ca
4
+ data.tar.gz: ab0c2c11a0a747c3eaeaa7702e726b1818dd650b553406a692db7ba88223b21d
5
5
  SHA512:
6
- metadata.gz: bc4627290512e876360564aae30dc4319cd0568a31826c3b28b2773a981121d684a4494f49fc2d8d2b3bd16d19807b9b22440505cb58e8b95fd4f4a68cd60c4c
7
- data.tar.gz: fc270ec8d5d3afea0358482e981329f74639a27bdaf5e66a1b6e3b2d014e6dbc8f0602584ed5446e39d9ad4cd33dad68539821b276b3ec817696d0efca661029
6
+ metadata.gz: bb45133a3c85cf82a4965c1aa85845c0126c1dd00916dd277d3c08c91dd2136c6516447fb513fa6b7e9664ed9d889f70bafa922898da0eb23501b1627b06d4b0
7
+ data.tar.gz: f7675759c9ac7d8b908a400ee72a79ae48f269a63554330635dcc4468988bbf9a1c06dc7a33774c27228a5733d1c26f5ddc13d2ec7323930cc1522a442388620
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ def capture
7
+ ENV['METRICS_BACKEND'] = 'metrics/backend/capture'
8
+ require 'metrics'
9
+ end
10
+
11
+ # Generate a list of metrics using the document backend.
12
+ def list
13
+ Metrics::Backend::Capture.metrics.sort_by!{|metric| metric.name}
14
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
5
+
6
+ require 'console'
7
+ require_relative '../metric'
8
+
9
+ module Metrics
10
+ module Backend
11
+ module Capture
12
+ class Metric < Metrics::Metric
13
+ def initialize(...)
14
+ super
15
+
16
+ @values = []
17
+ @tags = Set.new
18
+ @sample_rates = []
19
+ end
20
+
21
+ attr :values
22
+ attr :tags
23
+ attr :sample_rates
24
+
25
+ def emit(value, tags: nil, sample_rate: 1.0)
26
+ @values << value
27
+ @tags.merge(tags) if tags
28
+ @sample_rates << sample_rate
29
+ end
30
+
31
+ def as_json
32
+ {
33
+ name: @name,
34
+ type: @type,
35
+ description: @description,
36
+ unit: @unit,
37
+ values: @values,
38
+ tags: @tags.to_a.sort,
39
+ sample_rates: @sample_rates.sort.uniq
40
+ }
41
+ end
42
+
43
+ def to_json(...)
44
+ as_json.to_json(...)
45
+ end
46
+ end
47
+
48
+ def self.metrics
49
+ @metrics ||= []
50
+ end
51
+
52
+ module Interface
53
+ def metric(name, type, description: nil, unit: nil, &block)
54
+ metric = Metric.new(name, type, description, unit)
55
+
56
+ Capture.metrics << metric
57
+
58
+ return metric
59
+ end
60
+ end
61
+ end
62
+
63
+ Interface = Capture::Interface
64
+ end
65
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2022, by Samuel Williams.
4
+ # Copyright, 2021-2023, by Samuel Williams.
5
5
 
6
6
  require 'console'
7
7
  require_relative '../metric'
@@ -34,4 +34,3 @@ module Metrics
34
34
  Interface = Console::Interface
35
35
  end
36
36
  end
37
-
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2022, by Samuel Williams.
5
5
 
6
6
  module Metrics
7
- VERSION = "0.5.0"
7
+ VERSION = "0.6.1"
8
8
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2021-2022, by Samuel Williams.
3
+ Copyright, 2021-2023, by Samuel Williams.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -27,27 +27,3 @@ We welcome contributions to this project.
27
27
 
28
28
  - [metrics-backend-datadog](https://github.com/socketry/metrics-backend-datadog) — A Metrics backend for Datadog.
29
29
  - [traces](https://github.com/socketry/traces) — A code tracing interface which follows a similar pattern.
30
-
31
- ## License
32
-
33
- Released under the MIT license.
34
-
35
- Copyright, 2021, by [Samuel G. D. Williams](http://www.codeotaku.com).
36
-
37
- Permission is hereby granted, free of charge, to any person obtaining a copy
38
- of this software and associated documentation files (the "Software"), to deal
39
- in the Software without restriction, including without limitation the rights
40
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
41
- copies of the Software, and to permit persons to whom the Software is
42
- furnished to do so, subject to the following conditions:
43
-
44
- The above copyright notice and this permission notice shall be included in
45
- all copies or substantial portions of the Software.
46
-
47
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
48
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
51
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
52
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
53
- THE SOFTWARE.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2022-11-09 00:00:00.000000000 Z
40
+ date: 2023-03-03 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bake-test
@@ -101,8 +101,10 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - bake/metrics/capture.rb
104
105
  - lib/metrics.rb
105
106
  - lib/metrics/backend.rb
107
+ - lib/metrics/backend/capture.rb
106
108
  - lib/metrics/backend/console.rb
107
109
  - lib/metrics/backend/test.rb
108
110
  - lib/metrics/metric.rb
@@ -130,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
132
  - !ruby/object:Gem::Version
131
133
  version: '0'
132
134
  requirements: []
133
- rubygems_version: 3.3.7
135
+ rubygems_version: 3.4.7
134
136
  signing_key:
135
137
  specification_version: 4
136
138
  summary: Application metrics and instrumentation.
metadata.gz.sig CHANGED
Binary file