greek_fire 0.2.2 → 0.3.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 +4 -4
- data/README.md +14 -1
- data/app/models/greek_fire/counter.rb +4 -0
- data/app/models/greek_fire/gauge.rb +1 -60
- data/app/models/greek_fire/measure.rb +63 -0
- data/app/views/greek_fire/counters/_counter.html.erb +3 -0
- data/lib/greek_fire/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf28be620605ec968ec44e74413f5a02ecc060f
|
4
|
+
data.tar.gz: 4045fbe1bcb0acc5950de74178f2afa2e65e85b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14a8377f24478a1e5d9dfc6bd9a9ae08ed4cb3d70fc3ac5375a9e2322912de44df7bd4709aafe4fe320d96337c823d3cbe5f682a12ccfdf06c9e35d3c65501d
|
7
|
+
data.tar.gz: d99259ac70047a57638779c5db568142c28003bc1d80ae4eb08b4eb1c4c5c75c2ad1a8c8aa39899354500ec0ba301b61217c23165b7ce62fab4b21d00f896681
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ end
|
|
60
60
|
## Metrics API
|
61
61
|
The api for creating metrics.
|
62
62
|
|
63
|
-
Currently only gauge
|
63
|
+
Currently only gauge and counter types of metrics are supported, but other metrics are a PR away!
|
64
64
|
|
65
65
|
### Gauges
|
66
66
|
```
|
@@ -75,6 +75,19 @@ end
|
|
75
75
|
|
76
76
|
To register a Gauge (point in time value) call the above method.
|
77
77
|
|
78
|
+
### Counters
|
79
|
+
```
|
80
|
+
module GreekFire
|
81
|
+
class Counter
|
82
|
+
def self.register(name, description:nil, labels:nil, &block)
|
83
|
+
...
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
To register a Counter (point in time value) call the above method.
|
90
|
+
|
78
91
|
### Labels
|
79
92
|
Labels are a hash of label_name to label_value(s).
|
80
93
|
A label_value may be a collection of values for the labels, or a Proc that returns a collection of label values.
|
@@ -1,63 +1,4 @@
|
|
1
|
-
require 'active_model'
|
2
|
-
|
3
1
|
module GreekFire
|
4
|
-
class Gauge
|
5
|
-
include ActiveModel::Conversion
|
6
|
-
|
7
|
-
attr_reader :name, :description
|
8
|
-
|
9
|
-
def self.register(name, description:nil, labels:nil, &block)
|
10
|
-
GreekFire::Metric.register(self.new(name, description: description, labels: labels, &block))
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(name, description:nil, labels:nil, &block)
|
14
|
-
labels ||= {}
|
15
|
-
@name = name
|
16
|
-
|
17
|
-
@labels = {
|
18
|
-
app_name: ::Rails.application.class.parent_name,
|
19
|
-
app_env: Rails.env.to_s
|
20
|
-
}.merge(labels)
|
21
|
-
|
22
|
-
@description = description
|
23
|
-
@callable = block
|
24
|
-
end
|
25
|
-
|
26
|
-
def labels
|
27
|
-
label_products(convert_label_values_to_array @labels)
|
28
|
-
end
|
29
|
-
|
30
|
-
def value(labels)
|
31
|
-
@callable.call(labels).tap do |value|
|
32
|
-
unless value.is_a?(Numeric)
|
33
|
-
raise ArgumentError, "Gauge value must be a number: #{value.inspect}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def metrics
|
39
|
-
labels.map {|label_set| Metric.new(name, label_set, value(label_set))}
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
def convert_label_values_to_array(labels)
|
44
|
-
labels.inject({}) do |doc, label_name|
|
45
|
-
label_values = label_name[1]
|
46
|
-
label_values = label_values.call if label_values.respond_to? :call
|
47
|
-
label_values = [label_values] unless label_values.is_a?(Enumerable)
|
48
|
-
doc[label_name[0]] = label_values
|
49
|
-
doc
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def label_products(hsh)
|
54
|
-
#http://stackoverflow.com/questions/9786264/all-possible-combinations-from-a-hash-of-arrays-in-ruby
|
55
|
-
#thanks, internet
|
56
|
-
attrs = hsh.values
|
57
|
-
keys = hsh.keys
|
58
|
-
product = attrs[0].product(*attrs[1..-1])
|
59
|
-
product.map{ |p| Hash[keys.zip p] }
|
60
|
-
end
|
61
|
-
|
2
|
+
class Gauge < Measure
|
62
3
|
end
|
63
4
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module GreekFire
|
4
|
+
class Measure
|
5
|
+
include ActiveModel::Conversion
|
6
|
+
|
7
|
+
attr_reader :name, :description
|
8
|
+
|
9
|
+
def self.register(name, description:nil, labels:nil, &block)
|
10
|
+
GreekFire::Metric.register(self.new(name, description: description, labels: labels, &block))
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(name, description:nil, labels:nil, &block)
|
14
|
+
labels ||= {}
|
15
|
+
@name = name
|
16
|
+
|
17
|
+
@labels = {
|
18
|
+
app_name: ::Rails.application.class.parent_name,
|
19
|
+
app_env: Rails.env.to_s
|
20
|
+
}.merge(labels)
|
21
|
+
|
22
|
+
@description = description
|
23
|
+
@callable = block
|
24
|
+
end
|
25
|
+
|
26
|
+
def labels
|
27
|
+
label_products(convert_label_values_to_array @labels)
|
28
|
+
end
|
29
|
+
|
30
|
+
def value(labels)
|
31
|
+
@callable.call(labels).tap do |value|
|
32
|
+
unless value.is_a?(Numeric)
|
33
|
+
raise ArgumentError, "Gauge value must be a number: #{value.inspect}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def metrics
|
39
|
+
labels.map {|label_set| Metric.new(name, label_set, value(label_set))}
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def convert_label_values_to_array(labels)
|
44
|
+
labels.inject({}) do |doc, label_name|
|
45
|
+
label_values = label_name[1]
|
46
|
+
label_values = label_values.call if label_values.respond_to? :call
|
47
|
+
label_values = [label_values] unless label_values.is_a?(Enumerable)
|
48
|
+
doc[label_name[0]] = label_values
|
49
|
+
doc
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def label_products(hsh)
|
54
|
+
#http://stackoverflow.com/questions/9786264/all-possible-combinations-from-a-hash-of-arrays-in-ruby
|
55
|
+
#thanks, internet
|
56
|
+
attrs = hsh.values
|
57
|
+
keys = hsh.keys
|
58
|
+
product = attrs[0].product(*attrs[1..-1])
|
59
|
+
product.map{ |p| Hash[keys.zip p] }
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/lib/greek_fire/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greek_fire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cconstantine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -80,8 +80,11 @@ files:
|
|
80
80
|
- app/assets/javascripts/greek_fire/application.js
|
81
81
|
- app/assets/stylesheets/greek_fire/application.css
|
82
82
|
- app/controllers/greek_fire/metrics_controller.rb
|
83
|
+
- app/models/greek_fire/counter.rb
|
83
84
|
- app/models/greek_fire/gauge.rb
|
85
|
+
- app/models/greek_fire/measure.rb
|
84
86
|
- app/models/greek_fire/metric.rb
|
87
|
+
- app/views/greek_fire/counters/_counter.html.erb
|
85
88
|
- app/views/greek_fire/gauges/_gauge.html.erb
|
86
89
|
- app/views/greek_fire/metrics/_labels.html.erb
|
87
90
|
- app/views/greek_fire/metrics/_metric.html.erb
|