evil-metrics-prometheus 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 509ebad673a4851d59c6bde88eb28d2860e428a6c30c813fd70a5dc66aa9b0bb
4
- data.tar.gz: 45a02c6c00f18ec88111a81045a305a38f4a747db1157e6f6a689f21091ccf11
3
+ metadata.gz: aa32c629dfbb01f9e0239b1fea8a17a05a568791d13283a38cab13442a60e05a
4
+ data.tar.gz: e7b189a0e79b27bdcf3d758fd3a30b62216776a40a2eecb6dcd589ba69b0bf23
5
5
  SHA512:
6
- metadata.gz: 844dc54dc3d846964487612ce86d12d7df53fcc07b9c2ab812369df4a0e1c739861a3f0e793769edbd974fcc4f342e08695bdaabd569241ddc7cce6f2f7b6335
7
- data.tar.gz: 34d17c7a862223e6bfc029535297ef3199042830d426c04ac8efb30ade055784f1e7f74b0a07be1e2e6cf801059a4c10e6aa007a17e6ac72ede397667a7862da
6
+ metadata.gz: be379ea0f300113c3757ddb9d8169237e614399e93cfe66ace6f7e2b076e1c23a04cdd4d301f4abf395d9db158c893d37ec5a100ad27a0fdcbb315161dd6bc94
7
+ data.tar.gz: 06ff68b060f460b4379299bb914858ec37c17b39b0c431da0a114e6b22017f061a663408c1ff7ccfb933aa97811d24f2283cc3706ab769a4d4d3df86fa663c87
@@ -6,7 +6,7 @@ require "evil/metrics/prometheus/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "evil-metrics-prometheus"
9
- spec.version = "0.1.0"
9
+ spec.version = Evil::Metrics::Prometheus::VERSION
10
10
  spec.authors = ["Andrey Novikov"]
11
11
  spec.email = ["envek@envek.name"]
12
12
 
@@ -3,6 +3,9 @@
3
3
  require "prometheus/client"
4
4
  require "evil/metrics/base_adapter"
5
5
 
6
+ require_relative "./counter_wrapper"
7
+ require_relative "./gauge_wrapper"
8
+
6
9
  module Evil
7
10
  module Metrics
8
11
  class Prometheus::Adapter < BaseAdapter
@@ -12,20 +15,20 @@ module Evil
12
15
 
13
16
  def register_counter!(metric)
14
17
  validate_metric!(metric)
15
- registry.counter(build_name(metric), metric.comment)
18
+ registry.register(Prometheus::CounterWrapper.new(metric))
16
19
  end
17
20
 
18
- def perform_counter_increment!(metric, tags, increment)
19
- registry.get(build_name(metric)).increment(tags, increment)
21
+ def perform_counter_increment!(*)
22
+ # Do nothing. Prometheus will read current value from evil metric
20
23
  end
21
24
 
22
25
  def register_gauge!(metric)
23
26
  validate_metric!(metric)
24
- registry.gauge(build_name(metric), metric.comment)
27
+ registry.register(Prometheus::GaugeWrapper.new(metric))
25
28
  end
26
29
 
27
- def perform_gauge_set!(metric, tags, increment)
28
- registry.get(build_name(metric)).set(tags, increment)
30
+ def perform_gauge_set!(*)
31
+ # Do nothing. Prometheus will read current value from evil metric
29
32
  end
30
33
 
31
34
  def register_histogram!(metric)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./metric_wrapper"
4
+
5
+ module Evil
6
+ module Metrics
7
+ class Prometheus::CounterWrapper < Prometheus::MetricWrapper
8
+ def type
9
+ :counter
10
+ end
11
+
12
+ def increment(labels = {}, by = 1)
13
+ metric.increment(labels, by: by)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./metric_wrapper"
4
+
5
+ module Evil
6
+ module Metrics
7
+ class Prometheus::GaugeWrapper < Prometheus::MetricWrapper
8
+ def type
9
+ :gauge
10
+ end
11
+
12
+ def set(labels, value)
13
+ unless value.is_a?(Numeric)
14
+ raise ArgumentError, 'value must be a number'
15
+ end
16
+
17
+ metric.set(labels, value)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "prometheus/client/metric"
4
+
5
+ module Evil
6
+ module Metrics
7
+ class Prometheus::MetricWrapper < ::Prometheus::Client::Metric
8
+ attr_reader :metric
9
+
10
+ def initialize(metric, base_labels = {})
11
+ @metric = metric
12
+
13
+ @validator = ::Prometheus::Client::LabelSetValidator.new
14
+ @base_labels = base_labels
15
+
16
+ validate_name(self.name)
17
+ validate_docstring(self.docstring)
18
+ @validator.valid?(base_labels)
19
+ end
20
+
21
+ def name
22
+ @name ||=
23
+ [metric.group, metric.name, metric.unit].compact.join("_").to_sym
24
+ end
25
+
26
+ def docstring
27
+ metric.comment
28
+ end
29
+
30
+ def get(labels = {})
31
+ @validator.valid?(labels)
32
+
33
+ metric.get(labels)
34
+ end
35
+
36
+ def values
37
+ metric.values
38
+ end
39
+ end
40
+ end
41
+ end
@@ -3,7 +3,7 @@
3
3
  module Evil
4
4
  module Metrics
5
5
  module Prometheus
6
- VERSION = "0.1.0"
6
+ VERSION = "0.1.1"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evil-metrics-prometheus
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
  - Andrey Novikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evil-metrics
@@ -100,7 +100,10 @@ files:
100
100
  - evil-metrics-prometheus.gemspec
101
101
  - lib/evil/metrics/prometheus.rb
102
102
  - lib/evil/metrics/prometheus/adapter.rb
103
+ - lib/evil/metrics/prometheus/counter_wrapper.rb
103
104
  - lib/evil/metrics/prometheus/exporter.rb
105
+ - lib/evil/metrics/prometheus/gauge_wrapper.rb
106
+ - lib/evil/metrics/prometheus/metric_wrapper.rb
104
107
  - lib/evil/metrics/prometheus/version.rb
105
108
  homepage: https://github.com/evil-metrics/evil-metrics-prometheus
106
109
  licenses: