prometheus_exporter 0.1.14 → 0.1.15

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
- SHA256:
3
- metadata.gz: fd8e78f5b3845845709c7479c94326c24f24b8a6e46b124b88c8f3d1a433f66e
4
- data.tar.gz: 8813dc2dede6682afa0cf0ffa148bdd482f2a2affc6d5c719b825f1f1f8b8612
2
+ SHA1:
3
+ metadata.gz: d2f98b4a43ff42569d5b63f603fca9dbc011aba6
4
+ data.tar.gz: 80f468ac5abf12049e4d58bd981186b7134b5059
5
5
  SHA512:
6
- metadata.gz: de2d4650f99c955d1bc22a0f364504d17670628d03130f47aa50c835c2933e57547a093d0c6807dd9763255b3bdcc6f8ba469bbe1b8c2094419f55907ad1f893
7
- data.tar.gz: 04e43b29d74c7f938d667c70dde47b94330482344edcb1134a39f9d9d70a7187b02c6e4a746452cdc6c236574b7fdb7d0d38986bd057daa5f1c1009fe8a31f85
6
+ metadata.gz: 1d77695ef60e34eafd2dcbec8d7247eba6610568305a6d0a5a146300ff59f2f7c5776756bcd20562d14743d5354d493dc50e95a9e8f72d4bcdfaac55283bb100
7
+ data.tar.gz: e8e4c0b5a0ea42b97c2fdd9dd75ba6894a9063a22764c8817488eaa31c6cc0fd627194a3664af067e9de0a5019bfabfe73a9031f81b16742fdceb7ba40f8df27
data/.travis ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ dist: trusty
3
+ language: ruby
4
+ rvm:
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - jruby
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ 0.1.15 - 2018-02-19
2
+
3
+ - Feature: Prefer to use oj if it is loadable
4
+
5
+ 0.1.14 - 2018-02-17
6
+
7
+ - Fix: error when shipping summary metric with no labels
8
+ - Feature: runner was extracted so it can be reused @304
@@ -35,7 +35,7 @@ class PrometheusExporter::Client
35
35
  MAX_SOCKET_AGE = 25
36
36
  MAX_QUEUE_SIZE = 10_000
37
37
 
38
- def initialize(host: 'localhost', port: PrometheusExporter::DEFAULT_PORT, max_queue_size: nil, thread_sleep: 0.5)
38
+ def initialize(host: 'localhost', port: PrometheusExporter::DEFAULT_PORT, max_queue_size: nil, thread_sleep: 0.5, json_serializer: nil)
39
39
  @metrics = []
40
40
 
41
41
  @queue = Queue.new
@@ -55,6 +55,8 @@ class PrometheusExporter::Client
55
55
  @worker_thread = nil
56
56
  @mutex = Mutex.new
57
57
  @thread_sleep = thread_sleep
58
+
59
+ @json_serializer = PrometheusExporter.detect_json_serializer(@json_serializer)
58
60
  end
59
61
 
60
62
  def register(type, name, help)
@@ -64,7 +66,7 @@ class PrometheusExporter::Client
64
66
  end
65
67
 
66
68
  def send_json(obj)
67
- send(obj.to_json)
69
+ send(@json_serializer.dump(obj))
68
70
  end
69
71
 
70
72
  def send(str)
@@ -20,11 +20,12 @@ module PrometheusExporter::Server
20
20
  total_allocated_objects: "Total number of allocateds objects by process",
21
21
  }
22
22
 
23
- def initialize
23
+ def initialize(json_serializer: nil)
24
24
  @process_metrics = []
25
25
  @metrics = {}
26
26
  @mutex = Mutex.new
27
27
  @collectors = {}
28
+ @json_serializer = PrometheusExporter.detect_json_serializer(json_serializer)
28
29
  register_collector(WebCollector.new)
29
30
  register_collector(ProcessCollector.new)
30
31
  register_collector(SidekiqCollector.new)
@@ -35,7 +36,7 @@ module PrometheusExporter::Server
35
36
  end
36
37
 
37
38
  def process(str)
38
- obj = JSON.parse(str)
39
+ obj = @json_serializer.parse(str)
39
40
  @mutex.synchronize do
40
41
  if collector = @collectors[obj["type"]]
41
42
  collector.collect(obj)
@@ -1,3 +1,3 @@
1
1
  module PrometheusExporter
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
@@ -6,4 +6,35 @@ module PrometheusExporter
6
6
  # per: https://github.com/prometheus/prometheus/wiki/Default-port-allocations
7
7
  DEFAULT_PORT = 9394
8
8
  DEFAULT_PREFIX = 'ruby_'
9
+
10
+ class OjCompat
11
+ def self.parse(obj)
12
+ Oj.compat_load(obj)
13
+ end
14
+ def self.dump(obj)
15
+ Oj.dump(obj, mode: :compat)
16
+ end
17
+ end
18
+
19
+ def self.detect_json_serializer(preferred)
20
+ if preferred.nil?
21
+ preferred = :oj if has_oj?
22
+ end
23
+
24
+ preferred == :oj ? OjCompat : JSON
25
+ end
26
+
27
+ @@has_oj = nil
28
+ def self.has_oj?
29
+ (
30
+ @@has_oj ||=
31
+ begin
32
+ require 'oj'
33
+ :true
34
+ rescue LoadError
35
+ :false
36
+ end
37
+ ) == :true
38
+ end
39
+
9
40
  end
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "guard", "~> 2.0"
28
28
  spec.add_development_dependency "mini_racer", "~> 0.1"
29
29
  spec.add_development_dependency "guard-minitest", "~> 2.0"
30
+ spec.add_development_dependency "oj", "~> 3.0"
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: oj
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
97
111
  description: Prometheus metric collector and exporter for Ruby
98
112
  email:
99
113
  - sam.saffron@gmail.com
@@ -104,7 +118,9 @@ extra_rdoc_files: []
104
118
  files:
105
119
  - ".gitignore"
106
120
  - ".rubocop.yml"
121
+ - ".travis"
107
122
  - ".travis.yml"
123
+ - CHANGELOG
108
124
  - CODE_OF_CONDUCT.md
109
125
  - Gemfile
110
126
  - Guardfile
@@ -158,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
174
  version: '0'
159
175
  requirements: []
160
176
  rubyforge_project:
161
- rubygems_version: 2.7.3
177
+ rubygems_version: 2.5.2
162
178
  signing_key:
163
179
  specification_version: 4
164
180
  summary: Prometheus Exporter