prometheus_exporter 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +31 -6
- data/lib/prometheus_exporter/metric/base.rb +9 -0
- data/lib/prometheus_exporter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49c574a415d9c6c164b9e0671c6649928bbee2cb5645e52a43ef37b899d13bc3
|
4
|
+
data.tar.gz: 822b077292371a669291e69944c85d220dfda7c592711e5bc73e252e41b3ee84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14eb93a948c46817e889f95c0f9899c0046c667408710eac60a9f96b2693da35d8a0724b9d426e5b5f0882b31f498acfefe5944dce9895629c04dc32af0a3466
|
7
|
+
data.tar.gz: 4ed4f50b3ee95e527d0820cfbbf24f90a44bb51f0ecd652d7159a9a53d7731e1490f8bbd46e0090ca39d723cadbded57f0c2567afc93e7f9700839274e3ce6cd
|
data/README.md
CHANGED
@@ -116,7 +116,7 @@ gem 'prometheus_exporter'
|
|
116
116
|
```
|
117
117
|
|
118
118
|
|
119
|
-
```
|
119
|
+
```ruby
|
120
120
|
# in an initializer
|
121
121
|
|
122
122
|
unless Rails.env == "test"
|
@@ -129,7 +129,7 @@ end
|
|
129
129
|
|
130
130
|
You may also be interested in per-process stats, this collects memory and GC stats
|
131
131
|
|
132
|
-
```
|
132
|
+
```ruby
|
133
133
|
# in an initializer
|
134
134
|
unless Rails.env == "test"
|
135
135
|
require 'prometheus_exporter/instrumentation'
|
@@ -148,7 +148,7 @@ end
|
|
148
148
|
|
149
149
|
Including Sidekiq metrics (how many jobs ran? how many failed? how long did they take?)
|
150
150
|
|
151
|
-
```
|
151
|
+
```ruby
|
152
152
|
Sidekiq.configure_server do |config|
|
153
153
|
config.server_middleware do |chain|
|
154
154
|
require 'prometheus_exporter/instrumentation'
|
@@ -159,7 +159,7 @@ end
|
|
159
159
|
|
160
160
|
It also comes with a DelayedJob plugin.
|
161
161
|
|
162
|
-
```
|
162
|
+
```ruby
|
163
163
|
# in an initializer
|
164
164
|
unless Rails.env == "test"
|
165
165
|
require 'prometheus_exporter/instrumentation'
|
@@ -233,7 +233,7 @@ Custom type collectors are the ideal place to collect global metrics, such as us
|
|
233
233
|
|
234
234
|
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:
|
235
235
|
|
236
|
-
```
|
236
|
+
```ruby
|
237
237
|
unless defined? Rails
|
238
238
|
require File.expand_path("../../config/environment", __FILE__)
|
239
239
|
end
|
@@ -241,7 +241,7 @@ end
|
|
241
241
|
|
242
242
|
Then you can collect the metrics you need on demand:
|
243
243
|
|
244
|
-
```
|
244
|
+
```ruby
|
245
245
|
def metrics
|
246
246
|
user_count_gague = PrometheusExporter::Metric::Gauge.new('user_count', 'number of users in the app')
|
247
247
|
user_count_gague.observe User.count
|
@@ -322,6 +322,31 @@ thing1 122
|
|
322
322
|
thing2 12
|
323
323
|
```
|
324
324
|
|
325
|
+
### Metrics default prefix / labels
|
326
|
+
|
327
|
+
You can specify default prefix or labels for metrics, for example:
|
328
|
+
|
329
|
+
```ruby
|
330
|
+
# Specify prefix for metric names
|
331
|
+
PrometheusExporter::Metric.base.default_prefix = "ruby"
|
332
|
+
|
333
|
+
# Specify default labels for metrics
|
334
|
+
PrometheusExporter::Metric.base.default_labels = { "hostname" => "app-server-01" }
|
335
|
+
|
336
|
+
counter = PrometheusExporter::Metric::Counter.new("web_requests", "number of web requests")
|
337
|
+
|
338
|
+
counter.observe(1, route: 'test/route')
|
339
|
+
counter.observe
|
340
|
+
```
|
341
|
+
|
342
|
+
Will result in:
|
343
|
+
|
344
|
+
```
|
345
|
+
# HELP web_requests number of web requests
|
346
|
+
# TYPE web_requests counter
|
347
|
+
ruby_web_requests{hostname="app-server-01",route="test/route"} 1
|
348
|
+
ruby_web_requests{hostname="app-server-01"} 1
|
349
|
+
```
|
325
350
|
|
326
351
|
## Transport concerns
|
327
352
|
|
@@ -11,6 +11,14 @@ module PrometheusExporter::Metric
|
|
11
11
|
@default_prefix.to_s
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.default_labels=(labels)
|
15
|
+
@default_labels = labels
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.default_labels
|
19
|
+
@default_labels || {}
|
20
|
+
end
|
21
|
+
|
14
22
|
attr_accessor :help, :name, :data
|
15
23
|
|
16
24
|
def initialize(name, help)
|
@@ -46,6 +54,7 @@ module PrometheusExporter::Metric
|
|
46
54
|
end
|
47
55
|
|
48
56
|
def labels_text(labels)
|
57
|
+
labels = (labels || {}).merge(Base.default_labels)
|
49
58
|
if labels && labels.length > 0
|
50
59
|
s = labels.map do |key, value|
|
51
60
|
"#{key}=\"#{value}\""
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
190
|
version: '0'
|
191
191
|
requirements: []
|
192
192
|
rubyforge_project:
|
193
|
-
rubygems_version: 2.6
|
193
|
+
rubygems_version: 2.7.6
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
196
196
|
summary: Prometheus Exporter
|