prometheus_exporter 0.1.12 → 0.1.13

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: 2b09dff4a49846230b74243135fcacc1d88b440b04b69e76cf4dce76bd3eaa90
4
- data.tar.gz: fb48d9cecb4d0ed600c00c8c8265ec88f4ab8b0e81369adf08eaee478895c337
2
+ SHA1:
3
+ metadata.gz: 405a56b4f80812423e624398bc135af0ba955af9
4
+ data.tar.gz: 597a3f4587b851f436dafc8687a85c97373e5e06
5
5
  SHA512:
6
- metadata.gz: 777e3913f7fd24cd455af42e6ac1d73b98ef6a803189c43443f2d3d517bf4aa540b3be994d99afbb5060bc83ff83ed42be2037217b14522d848918891d64cb1c
7
- data.tar.gz: bcbde54a95042c01a80e297ca6096444574d9e8c1d17027759469e51f4ff36b8b23cf574f6111034233805546e7f7a73e8cc8922b96f787191b4bdb345e8dbfa
6
+ metadata.gz: d2a19111517b005751654f0084e66300cc6e2c70207c1529ced65d84031b19aa90f218daf71e10624653c976213833e4bc88551371f21e627410fef6b8e9355e
7
+ data.tar.gz: 1c94b5f7d8606c0384211faeaf91e2595e154cbef85013764e7de3d0bda39c966527bd153696b8aa48418ade3c7507dccdb2104156a399638d706da9457bdadf
data/README.md CHANGED
@@ -20,6 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install prometheus_exporter
22
22
 
23
+ ## Can I have some pretty pictures please?
24
+
25
+ Sure, check out: [Instrumenting Rails with Prometheus](https://samsaffron.com/archive/2018/02/02/instrumenting-rails-with-prometheus)
26
+
23
27
  ## Usage
24
28
 
25
29
  ### Single process mode
@@ -199,13 +203,36 @@ bundle exec prometheus_exporter -a person_collector.rb
199
203
 
200
204
  ```
201
205
 
206
+ #### Global metrics in a custom type collector
207
+
208
+ Custom type collectors are the ideal place to collect global metrics, such as user/article counts and connection counts. The custom type collector runs in the collector which usually runs in the prometheus exporter process.
209
+
210
+ Out-of-the-box we try to keep the prometheus exporter as lean as possible, we do not load all the Rails dependencies so you will not have access to your models. You can always ensure it is loaded in your custom type collector with:
211
+
212
+ ```
213
+ unless defined? Rails
214
+ require File.expand_path("../../config/environment", __FILE__)
215
+ end
216
+ ```
217
+
218
+ Then you can collect the metrics you need on demand:
219
+
220
+ ```
221
+ def metrics
222
+ user_count_gague = PrometheusExporter::Metric::Gauge.new('user_count', 'number of users in the app')
223
+ user_count_gague.observe User.count
224
+ [user_count_gauge]
225
+ end
226
+ ```
227
+
228
+ The metrics endpoint is called whenever prometheus calls the `/metrics` HTTP endpoint, it may make sense to introduce some caching so database calls are only performed once every N seconds. [lru_redux](https://github.com/SamSaffron/lru_redux) is the perfect gem for that kind of job as you can `LruRedux::TTL::Cache` which will automatically expire after N seconds.
229
+
230
+
202
231
  ### Multi process mode with custom collector
203
232
 
204
233
  You can opt for custom collector logic in a multi process environment.
205
234
 
206
- This allows you better control over the amount of data transported over HTTP and also allow you to introduce custom logic into your centralized collector.
207
-
208
- The standard collector ships "help", "type" and "name" for every metric, in some cases you may want to avoid sending all that data.
235
+ This allows you to completely replace the collector logic.
209
236
 
210
237
  First, define a custom collector, it is critical you inherit off `PrometheusExporter::Server::Collector`, also it is critical you have custom implementations for #process and #prometheus_metrics_text
211
238
 
@@ -241,7 +268,7 @@ end
241
268
  Next, launch the exporter process:
242
269
 
243
270
  ```bash
244
- % bin/prometheus_exporter 12345 --collector examples/custom_collector.rb
271
+ % bin/prometheus_exporter --collector examples/custom_collector.rb
245
272
  ```
246
273
 
247
274
  In your application ship it the metrics you want:
@@ -274,7 +301,7 @@ thing2 12
274
301
 
275
302
  ## Transport concerns
276
303
 
277
- 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.
304
+ 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. All calls to `send` and `send_json` on the PrometheusExporter::Client class are **non-blocking** and batched.
278
305
 
279
306
  The `/bench` directory has simple benchmark it is able to send through 10k messages in 500ms.
280
307
 
@@ -56,6 +56,12 @@ module PrometheusExporter::Server
56
56
  end
57
57
  end
58
58
 
59
+ def register_metric(metric)
60
+ @mutex.synchronize do
61
+ @metrics[metric.name] = metric
62
+ end
63
+ end
64
+
59
65
  protected
60
66
 
61
67
  def register_metric_unsafe(obj)
@@ -1,3 +1,3 @@
1
1
  module PrometheusExporter
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  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.12
4
+ version: 0.1.13
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-01 00:00:00.000000000 Z
11
+ date: 2018-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.7.3
160
+ rubygems_version: 2.5.2
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Prometheus Exporter