prometheus-client 3.0.0 → 4.1.0

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: b7017e1e3c284f9558d758e91d4855ad97b5df63fdef115cee035aa0948aed30
4
- data.tar.gz: 52a7abaadf1addf7bf9303d73a31a14338429882b488eb80c2144a6817cfdb7d
3
+ metadata.gz: 47fef80d530cba8aed214132cb1eb512c7094f9e0daa89db9d5db3f2f0393980
4
+ data.tar.gz: 98cfad337c9ff3907ba519fbd355e81697108af3251ec574fbb2c14bdd35af2c
5
5
  SHA512:
6
- metadata.gz: 1e3b2ff9368dacbdc175ea8cb709e1ad7be73b0d8e644468f65bf36f44b517798a28d7f5dab73b538519fc1a918f977e083e101986a761fdf2fe42ab719fcc1d
7
- data.tar.gz: 7fb5a1887a88f7687f2af5ef4839e26030da25cc0c51a03445bbb43706caf8d2231c65108cf3265cc024bc286d5dc8a38ec5d29145b39b2f0cbd0277f29f1972
6
+ metadata.gz: 844a860cf2090a1833a0f3a24d0c7629a761391f69aac8ebea5550463a2219947144438caae36662038cdf242747eea0afe42f3fbe2e86e2e4177f75ee1e50bf
7
+ data.tar.gz: 3429071dd55ee6f0493790b8860639e653e0e0bb4ddfdc1dffc30c051a66df598272ea2056e9ef87e0c67eb964606cfeba29c9faf05408f2e40e48ab09e31fbc
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -5,7 +5,7 @@ through a HTTP interface. Intended to be used together with a
5
5
  [Prometheus server][1].
6
6
 
7
7
  [![Gem Version][4]](http://badge.fury.io/rb/prometheus-client)
8
- [![Build Status][3]](https://circleci.com/gh/prometheus/client_ruby/tree/master.svg?style=svg)
8
+ [![Build Status][3]](https://circleci.com/gh/prometheus/client_ruby/tree/main.svg?style=svg)
9
9
 
10
10
  ## Usage
11
11
 
@@ -56,11 +56,11 @@ use Rack::Deflater
56
56
  use Prometheus::Middleware::Collector
57
57
  use Prometheus::Middleware::Exporter
58
58
 
59
- run ->(_) { [200, {'Content-Type' => 'text/html'}, ['OK']] }
59
+ run ->(_) { [200, {'content-type' => 'text/html'}, ['OK']] }
60
60
  ```
61
61
 
62
62
  Start the server and have a look at the metrics endpoint:
63
- [http://localhost:5000/metrics](http://localhost:5000/metrics).
63
+ [http://localhost:5123/metrics](http://localhost:5123/metrics).
64
64
 
65
65
  For further instructions and other scripts to get started, have a look at the
66
66
  integrated [example application](examples/rack/README.md).
@@ -227,17 +227,17 @@ summary_value['count'] # => 100
227
227
  All metrics can have labels, allowing grouping of related time series.
228
228
 
229
229
  Labels are an extremely powerful feature, but one that must be used with care.
230
- Refer to the best practices on [naming](https://prometheus.io/docs/practices/naming/) and
230
+ Refer to the best practices on [naming](https://prometheus.io/docs/practices/naming/) and
231
231
  [labels](https://prometheus.io/docs/practices/instrumentation/#use-labels).
232
232
 
233
- Most importantly, avoid labels that can have a large number of possible values (high
233
+ Most importantly, avoid labels that can have a large number of possible values (high
234
234
  cardinality). For example, an HTTP Status Code is a good label. A User ID is **not**.
235
235
 
236
236
  Labels are specified optionally when updating metrics, as a hash of `label_name => value`.
237
- Refer to [the Prometheus documentation](https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels)
237
+ Refer to [the Prometheus documentation](https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels)
238
238
  as to what's a valid `label_name`.
239
239
 
240
- In order for a metric to accept labels, their names must be specified when first initializing
240
+ In order for a metric to accept labels, their names must be specified when first initializing
241
241
  the metric. Then, when the metric is updated, all the specified labels must be present.
242
242
 
243
243
  Example:
@@ -255,8 +255,8 @@ You can also "pre-set" some of these label values, if they'll always be the same
255
255
  need to specify them every time:
256
256
 
257
257
  ```ruby
258
- https_requests_total = Counter.new(:http_requests_total,
259
- docstring: '...',
258
+ https_requests_total = Counter.new(:http_requests_total,
259
+ docstring: '...',
260
260
  labels: [:service, :status_code],
261
261
  preset_labels: { service: "my_service" })
262
262
 
@@ -271,7 +271,7 @@ with a subset (or full set) of labels set, so that you can increment / observe t
271
271
  without having to specify the labels for every call.
272
272
 
273
273
  Moreover, if all the labels the metric can take have been pre-set, validation of the labels
274
- is done on the call to `with_labels`, and then skipped for each observation, which can
274
+ is done on the call to `with_labels`, and then skipped for each observation, which can
275
275
  lead to performance improvements. If you are incrementing a counter in a fast loop, you
276
276
  definitely want to be doing this.
277
277
 
@@ -282,8 +282,8 @@ Examples:
282
282
 
283
283
  ```ruby
284
284
  # in the metric definition:
285
- records_processed_total = registry.counter.new(:records_processed_total,
286
- docstring: '...',
285
+ records_processed_total = registry.counter.new(:records_processed_total,
286
+ docstring: '...',
287
287
  labels: [:service, :component],
288
288
  preset_labels: { service: "my_service" })
289
289
 
@@ -296,11 +296,11 @@ class MyComponent
296
296
  def metric
297
297
  @metric ||= records_processed_total.with_labels(component: "my_component")
298
298
  end
299
-
299
+
300
300
  def process
301
301
  records.each do |record|
302
302
  # process the record
303
- metric.increment
303
+ metric.increment
304
304
  end
305
305
  end
306
306
  end
@@ -324,7 +324,7 @@ metric definition will result in a
324
324
 
325
325
  ## Data Stores
326
326
 
327
- The data for all the metrics (the internal counters associated with each labelset)
327
+ The data for all the metrics (the internal counters associated with each labelset)
328
328
  is stored in a global Data Store object, rather than in the metric objects themselves.
329
329
  (This "storage" is ephemeral, generally in-memory, it's not "long-term storage")
330
330
 
@@ -334,12 +334,12 @@ example), require a shared store between all the processes, to be able to report
334
334
  numbers. At the same time, other applications may not have this requirement but be very
335
335
  sensitive to performance, and would prefer instead a simpler, faster store.
336
336
 
337
- By having a standardized and simple interface that metrics use to access this store,
337
+ By having a standardized and simple interface that metrics use to access this store,
338
338
  we abstract away the details of storing the data from the specific needs of each metric.
339
- This allows us to then simply swap around the stores based on the needs of different
340
- applications, with no changes to the rest of the client.
339
+ This allows us to then simply swap around the stores based on the needs of different
340
+ applications, with no changes to the rest of the client.
341
341
 
342
- The client provides 3 built-in stores, but if neither of these is ideal for your
342
+ The client provides 3 built-in stores, but if neither of these is ideal for your
343
343
  requirements, you can easily make your own store and use that instead. More on this below.
344
344
 
345
345
  ### Configuring which store to use.
@@ -357,7 +357,7 @@ NOTE: You **must** make sure to set the `data_store` before initializing any met
357
357
  If using Rails, you probably want to set up your Data Store on `config/application.rb`,
358
358
  or `config/environments/*`, both of which run before `config/initializers/*`
359
359
 
360
- Also note that `config.data_store` is set to an *instance* of a `DataStore`, not to the
360
+ Also note that `config.data_store` is set to an *instance* of a `DataStore`, not to the
361
361
  class. This is so that the stores can receive parameters. Most of the built-in stores
362
362
  don't require any, but `DirectFileStore` does, for example.
363
363
 
@@ -376,45 +376,45 @@ documentation of each store for more details.
376
376
 
377
377
  There are 3 built-in stores, with different trade-offs:
378
378
 
379
- - **Synchronized**: Default store. Thread safe, but not suitable for multi-process
379
+ - **Synchronized**: Default store. Thread safe, but not suitable for multi-process
380
380
  scenarios (e.g. pre-fork servers, like Unicorn). Stores data in Hashes, with all accesses
381
- protected by Mutexes.
381
+ protected by Mutexes.
382
382
  - **SingleThreaded**: Fastest store, but only suitable for single-threaded scenarios.
383
- This store does not make any effort to synchronize access to its internal hashes, so
383
+ This store does not make any effort to synchronize access to its internal hashes, so
384
384
  it's absolutely not thread safe.
385
385
  - **DirectFileStore**: Stores data in binary files, one file per process and per metric.
386
- This is generally the recommended store to use with pre-fork servers and other
386
+ This is generally the recommended store to use with pre-fork servers and other
387
387
  "multi-process" scenarios. There are some important caveats to using this store, so
388
388
  please read on the section below.
389
389
 
390
390
  ### `DirectFileStore` caveats and things to keep in mind
391
391
 
392
392
  Each metric gets a file for each process, and manages its contents by storing keys and
393
- binary floats next to them, and updating the offsets of those Floats directly. When
394
- exporting metrics, it will find all the files that apply to each metric, read them,
393
+ binary floats next to them, and updating the offsets of those Floats directly. When
394
+ exporting metrics, it will find all the files that apply to each metric, read them,
395
395
  and aggregate them.
396
396
 
397
397
  **Aggregation of metrics**: Since there will be several files per metrics (one per process),
398
398
  these need to be aggregated to present a coherent view to Prometheus. Depending on your
399
- use case, you may need to control how this works. When using this store,
399
+ use case, you may need to control how this works. When using this store,
400
400
  each Metric allows you to specify an `:aggregation` setting, defining how
401
401
  to aggregate the multiple possible values we can get for each labelset. By default,
402
402
  Counters, Histograms and Summaries are `SUM`med, and Gauges report all their values (one
403
403
  for each process), tagged with a `pid` label. You can also select `SUM`, `MAX`, `MIN`, or
404
404
  `MOST_RECENT` for your gauges, depending on your use case.
405
405
 
406
- Please note that that the `MOST_RECENT` aggregation only works for gauges, and it does not
407
- allow the use of `increment` / `decrement`, you can only use `set`.
406
+ Please note that the `MOST_RECENT` aggregation only works for gauges, and it does not
407
+ allow the use of `increment` / `decrement`, you can only use `set`.
408
408
 
409
409
  **Memory Usage**: When scraped by Prometheus, this store will read all these files, get all
410
410
  the values and aggregate them. We have notice this can have a noticeable effect on memory
411
411
  usage for your app. We recommend you test this in a realistic usage scenario to make sure
412
412
  you won't hit any memory limits your app may have.
413
413
 
414
- **Resetting your metrics on each run**: You should also make sure that the directory where
415
- you store your metric files (specified when initializing the `DirectFileStore`) is emptied
416
- when your app starts. Otherwise, each app run will continue exporting the metrics from the
417
- previous run.
414
+ **Resetting your metrics on each run**: You should also make sure that the directory where
415
+ you store your metric files (specified when initializing the `DirectFileStore`) is emptied
416
+ when your app starts. Otherwise, each app run will continue exporting the metrics from the
417
+ previous run.
418
418
 
419
419
  If you have this issue, one way to do this is to run code similar to this as part of you
420
420
  initialization:
@@ -440,15 +440,15 @@ If you're absolutely sure that every child process will run the metric declarati
440
440
  then you won't run into this issue, but the simplest approach is to declare the metrics
441
441
  before forking.
442
442
 
443
- **Large numbers of files**: Because there is an individual file per metric and per process
444
- (which is done to optimize for observation performance), you may end up with a large number
443
+ **Large numbers of files**: Because there is an individual file per metric and per process
444
+ (which is done to optimize for observation performance), you may end up with a large number
445
445
  of files. We don't currently have a solution for this problem, but we're working on it.
446
446
 
447
- **Performance**: Even though this store saves data on disk, it's still much faster than
448
- would probably be expected, because the files are never actually `fsync`ed, so the store
449
- never blocks while waiting for disk. The kernel's page cache is incredibly efficient in
450
- this regard. If in doubt, check the benchmark scripts described in the documentation for
451
- creating your own stores and run them in your particular runtime environment to make sure
447
+ **Performance**: Even though this store saves data on disk, it's still much faster than
448
+ would probably be expected, because the files are never actually `fsync`ed, so the store
449
+ never blocks while waiting for disk. The kernel's page cache is incredibly efficient in
450
+ this regard. If in doubt, check the benchmark scripts described in the documentation for
451
+ creating your own stores and run them in your particular runtime environment to make sure
452
452
  this provides adequate performance.
453
453
 
454
454
 
@@ -457,7 +457,7 @@ this provides adequate performance.
457
457
  If none of these stores is suitable for your requirements, you can easily make your own.
458
458
 
459
459
  The interface and requirements of Stores are specified in detail in the `README.md`
460
- in the `client/data_stores` directory. This thoroughly documents how to make your own
460
+ in the `client/data_stores` directory. This thoroughly documents how to make your own
461
461
  store.
462
462
 
463
463
  There are also links there to non-built-in stores created by others that may be useful,
@@ -469,16 +469,16 @@ If you are in a multi-process environment (such as pre-fork servers like Unicorn
469
469
  process will probably keep their own counters, which need to be aggregated when receiving
470
470
  a Prometheus scrape, to report coherent total numbers.
471
471
 
472
- For Counters, Histograms and quantile-less Summaries this is simply a matter of
472
+ For Counters, Histograms and quantile-less Summaries this is simply a matter of
473
473
  summing the values of each process.
474
474
 
475
- For Gauges, however, this may not be the right thing to do, depending on what they're
475
+ For Gauges, however, this may not be the right thing to do, depending on what they're
476
476
  measuring. You might want to take the maximum or minimum value observed in any process,
477
477
  rather than the sum of all of them. By default, we export each process's individual
478
478
  value, with a `pid` label identifying each one.
479
479
 
480
- If these defaults don't work for your use case, you should use the `store_settings`
481
- parameter when registering the metric, to specify an `:aggregation` setting.
480
+ If these defaults don't work for your use case, you should use the `store_settings`
481
+ parameter when registering the metric, to specify an `:aggregation` setting.
482
482
 
483
483
  ```ruby
484
484
  free_disk_space = registry.gauge(:free_disk_space_bytes,
@@ -489,8 +489,8 @@ free_disk_space = registry.gauge(:free_disk_space_bytes,
489
489
  NOTE: This will only work if the store you're using supports the `:aggregation` setting.
490
490
  Of the built-in stores, only `DirectFileStore` does.
491
491
 
492
- Also note that the `:aggregation` setting works for all metric types, not just for gauges.
493
- It would be unusual to use it for anything other than gauges, but if your use-case
492
+ Also note that the `:aggregation` setting works for all metric types, not just for gauges.
493
+ It would be unusual to use it for anything other than gauges, but if your use-case
494
494
  requires it, the store will respect your aggregation wishes.
495
495
 
496
496
  ## Tests
@@ -504,9 +504,8 @@ rake
504
504
 
505
505
  [1]: https://github.com/prometheus/prometheus
506
506
  [2]: http://rack.github.io/
507
- [3]: https://secure.travis-ci.org/prometheus/client_ruby.svg?branch=master
507
+ [3]: https://circleci.com/gh/prometheus/client_ruby/tree/main.svg?style=svg
508
508
  [4]: https://badge.fury.io/rb/prometheus-client.svg
509
- [7]: https://coveralls.io/repos/prometheus/client_ruby/badge.svg?branch=master
510
509
  [8]: https://github.com/prometheus/pushgateway
511
510
  [9]: lib/prometheus/middleware/exporter.rb
512
511
  [10]: lib/prometheus/middleware/collector.rb
@@ -114,8 +114,7 @@ module Prometheus
114
114
 
115
115
  key = store_key(labels)
116
116
  in_process_sync do
117
- value = internal_store.read_value(key)
118
- internal_store.write_value(key, value + by.to_f)
117
+ internal_store.increment_value(key, by.to_f)
119
118
  end
120
119
  end
121
120
 
@@ -286,6 +285,21 @@ module Prometheus
286
285
  @f.flush
287
286
  end
288
287
 
288
+ def increment_value(key, by)
289
+ if !@positions.has_key?(key)
290
+ init_value(key)
291
+ end
292
+
293
+ pos = @positions[key]
294
+ @f.seek(pos)
295
+ value = @f.read(8).unpack('d')[0]
296
+
297
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
298
+ @f.seek(-8, :CUR)
299
+ @f.write([value + by, now].pack('dd'))
300
+ @f.flush
301
+ end
302
+
289
303
  def close
290
304
  @f.close
291
305
  end
@@ -5,8 +5,7 @@ module Prometheus
5
5
  # LabelSetValidator ensures that all used label sets comply with the
6
6
  # Prometheus specification.
7
7
  class LabelSetValidator
8
- # TODO: we might allow setting :instance in the future
9
- BASE_RESERVED_LABELS = [:job, :instance, :pid].freeze
8
+ BASE_RESERVED_LABELS = [:pid].freeze
10
9
  LABEL_NAME_REGEX = /\A[a-zA-Z_][a-zA-Z0-9_]*\Z/
11
10
 
12
11
  class LabelSetError < StandardError; end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prometheus
4
4
  module Client
5
- VERSION = '3.0.0'
5
+ VERSION = '4.1.0'
6
6
  end
7
7
  end
@@ -72,12 +72,12 @@ module Prometheus
72
72
  counter_labels = {
73
73
  code: code,
74
74
  method: env['REQUEST_METHOD'].downcase,
75
- path: strip_ids_from_path(path),
75
+ path: path,
76
76
  }
77
77
 
78
78
  duration_labels = {
79
79
  method: env['REQUEST_METHOD'].downcase,
80
- path: strip_ids_from_path(path),
80
+ path: path,
81
81
  }
82
82
 
83
83
  @requests.increment(labels: counter_labels)
@@ -87,52 +87,10 @@ module Prometheus
87
87
  nil
88
88
  end
89
89
 
90
- # While `PATH_INFO` is framework agnostic, and works for any Rack app, some Ruby web
91
- # frameworks pass a more useful piece of information into the request env - the
92
- # route that the request matched.
93
- #
94
- # This means that rather than using our generic `:id` and `:uuid` replacements in
95
- # the `path` label for any path segments that look like dynamic IDs, we can put the
96
- # actual route that matched in there, with correctly named parameters. For example,
97
- # if a Sinatra app defined a route like:
98
- #
99
- # get "/foo/:bar" do
100
- # ...
101
- # end
102
- #
103
- # instead of containing `/foo/:id`, the `path` label would contain `/foo/:bar`.
104
- #
105
- # Sadly, Rails is a notable exception, and (as far as I can tell at the time of
106
- # writing) doesn't provide this info in the request env.
107
90
  def generate_path(env)
108
- if env['sinatra.route']
109
- route = env['sinatra.route'].partition(' ').last
110
- elsif env['grape.routing_args']
111
- # We are deep in the weeds of an object that Grape passes into the request env,
112
- # but don't document any explicit guarantees about. Let's have a fallback in
113
- # case they change it down the line.
114
- #
115
- # This code would be neater with the safe navigation operator (`&.`) here rather
116
- # than the much more verbose `respond_to?` calls, but unlike Rails' `try`
117
- # method, it still raises an error if the object is non-nil, but doesn't respond
118
- # to the method being called on it.
119
- route = nil
120
-
121
- route_info = env.dig('grape.routing_args', :route_info)
122
- if route_info.respond_to?(:pattern)
123
- pattern = route_info.pattern
124
- if pattern.respond_to?(:origin)
125
- route = pattern.origin
126
- end
127
- end
128
-
129
- # Fall back to PATH_INFO if Grape change the structure of `grape.routing_args`
130
- route ||= env['PATH_INFO']
131
- else
132
- route = env['PATH_INFO']
133
- end
134
-
135
- [env['SCRIPT_NAME'], route].join
91
+ full_path = [env['SCRIPT_NAME'], env['PATH_INFO']].join
92
+
93
+ strip_ids_from_path(full_path)
136
94
  end
137
95
 
138
96
  def strip_ids_from_path(path)
@@ -66,7 +66,7 @@ module Prometheus
66
66
  def respond_with(format)
67
67
  [
68
68
  200,
69
- { 'Content-Type' => format::CONTENT_TYPE },
69
+ { 'content-type' => format::CONTENT_TYPE },
70
70
  [format.marshal(@registry)],
71
71
  ]
72
72
  end
@@ -76,7 +76,7 @@ module Prometheus
76
76
 
77
77
  [
78
78
  406,
79
- { 'Content-Type' => 'text/plain' },
79
+ { 'content-type' => 'text/plain' },
80
80
  ["Supported media types: #{types.join(', ')}"],
81
81
  ]
82
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Kochie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-02-05 00:00:00.000000000 Z
13
+ date: 2023-03-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: benchmark-ips
@@ -49,6 +49,7 @@ executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
+ - LICENSE
52
53
  - README.md
53
54
  - lib/prometheus.rb
54
55
  - lib/prometheus/client.rb
@@ -71,7 +72,7 @@ files:
71
72
  - lib/prometheus/middleware/exporter.rb
72
73
  homepage: https://github.com/prometheus/client_ruby
73
74
  licenses:
74
- - Apache 2.0
75
+ - Apache-2.0
75
76
  metadata: {}
76
77
  post_install_message:
77
78
  rdoc_options: []
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  - !ruby/object:Gem::Version
89
90
  version: '0'
90
91
  requirements: []
91
- rubygems_version: 3.2.32
92
+ rubygems_version: 3.3.26
92
93
  signing_key:
93
94
  specification_version: 4
94
95
  summary: A suite of instrumentation metric primitivesthat can be exposed through a