prometheus_exporter 0.1.4 → 0.1.5

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: 5ce91417f88ed90178a27b9afabbd205375083260dae5eeaa07241dd03d71982
4
- data.tar.gz: 95bcbb41f28bdf3c6ed0708c208d979f36728aa7ec339c0db69470789a4afb13
3
+ metadata.gz: d17c6718584f3b92aadf8cbfed5cd2b592df3f2407d19bd6575e0ce4efd6a735
4
+ data.tar.gz: f0cb1972defe21ee5b6ee3fd403fd6b20074f928ca5637f6c03128ecaa882eb1
5
5
  SHA512:
6
- metadata.gz: 53f83e8fee67c6d3ad13508b0785ff83d96117ae0dc1e560e12643e8983c19ed81a7f34a5951f2de707ad7c9b96fb921ba3ff7d7d8b45684175ecbf0c4818140
7
- data.tar.gz: f5c4c83a44bdf8a1cf09c449af256426d1596f33c9dd94571bfca426f5cb0a94acae7031d983e8a63f49744b1c93b32e2605a88c99d720e4eadf73a6b0d79bcd
6
+ metadata.gz: a2a5351286014650a71dbec6f723a8373647c54dd2fd6b9f707746468f4023fdb809893ea225ea72c81c2816fc26b5014b4db42c6c98253e8c2261e518d9ca49
7
+ data.tar.gz: c370dfcff273a85a8706429578e7f85e42930562ccf14eea8820df5858bf3f34ccd1bbb6376248491fe93f102460def7b4d89fb9c1388bf8abccc61e2fd193e7
data/README.md CHANGED
@@ -115,7 +115,8 @@ class MyCustomCollector < PrometheusExporter::Server::Collector
115
115
  @mutex = Mutex.new
116
116
  end
117
117
 
118
- def process(obj)
118
+ def process(str)
119
+ obj = JSON.parse(str)
119
120
  @mutex.synchronize do
120
121
  if thing1 = obj["thing1"]
121
122
  @gauge1.observe(thing1)
@@ -147,8 +148,8 @@ In your application ship it the metrics you want:
147
148
  require 'prometheus_exporter/client'
148
149
 
149
150
  client = PrometheusExporter::Client.new(host: 'localhost', port: 12345)
150
- client.send(thing1: 122)
151
- client.send(thing2: 12)
151
+ client.send_json(thing1: 122)
152
+ client.send_json(thing2: 12)
152
153
  ```
153
154
 
154
155
  Now your exporter will echo the metrics:
@@ -173,7 +174,8 @@ thing2 12
173
174
 
174
175
  Prometheus Exporter handles transport using a simple HTTP protocol. In multi process mode we avoid needing a large number of HTTP request by using chunked encoding to send metrics. This means that a single HTTP channel can deliver 100s or even 1000s of metrics over a single HTTP session to the `/send-metrics` endpoint.
175
176
 
176
- When sending data to `send-metrics` we always serialize the data for the chunk to a JSON string, and deserialize it back into an Object before handing the data to the collector.
177
+ The `/bench` directory has simple benchmark it is able to send through 10k messages in 500ms.
178
+
177
179
 
178
180
  ## Contributing
179
181
 
data/bench/bench.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require_relative '../lib/prometheus_exporter'
2
2
  require_relative '../lib/prometheus_exporter/client'
3
3
  require_relative '../lib/prometheus_exporter/server'
4
- require 'oj'
5
4
 
6
5
  # test how long it takes a custom collector to process 10k messages
7
6
 
@@ -13,8 +12,8 @@ class Collector
13
12
 
14
13
  def process(message)
15
14
  _parsed = JSON.parse(message)
16
- p @i if @i % 100 == 0
17
- @done.call if (@i += 1) == 10_000
15
+ @i += 1
16
+ @done.call if @i % 10_000 == 0
18
17
  end
19
18
 
20
19
  def prometheus_metrics_text
@@ -22,16 +21,23 @@ class Collector
22
21
  end
23
22
 
24
23
  @start = nil
24
+ @client = nil
25
+ @runs = 1000
26
+
25
27
  done = lambda do
26
28
  puts "Elapsed for 10k messages is #{Time.now - @start}"
29
+ if (@runs -= 1) > 0
30
+ @start = Time.now
31
+ 10_000.times { @client.send_json(hello: "world") }
32
+ end
27
33
  end
28
34
 
29
35
  collector = Collector.new(done)
30
36
  server = PrometheusExporter::Server::WebServer.new port: 12349, collector: collector
31
37
  server.start
32
- client = PrometheusExporter::Client.new port: 12349, max_queue_size: 20_000
38
+ @client = PrometheusExporter::Client.new port: 12349, max_queue_size: 100_000
33
39
 
34
40
  @start = Time.now
35
- 10_000.times { client.send_json(hello: "world") }
41
+ 10_000.times { @client.send_json(hello: "world") }
36
42
 
37
43
  sleep
@@ -140,7 +140,6 @@ class PrometheusExporter::Client
140
140
 
141
141
  def close_socket_if_old!
142
142
  if @socket && ((@socket_started + MAX_SOCKET_AGE) < Time.now.to_f)
143
- p "CLOSE OLD"
144
143
  close_socket!
145
144
  end
146
145
  end
@@ -1,3 +1,3 @@
1
1
  module PrometheusExporter
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron