prometheus-client-mmap 0.7.0.beta11 → 0.7.0.beta12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -9
- data/lib/prometheus/client/formats/text.rb +75 -76
- data/lib/prometheus/client/metric.rb +0 -1
- data/lib/prometheus/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d37ca4308c9dbdb10a22066b37df88b7e456cfb3
|
4
|
+
data.tar.gz: a27b2e124d343da9bb5b8f639894cd84f846334a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fba7137a3ea1f5fa1ea375bb1999d85b1765a6c73adb69ef77a0f6f2d77db4f1ac057a37de600baf8b6abe355aaac97ee4db88e4ccf82aa81b4b14f4d845df9
|
7
|
+
data.tar.gz: e785931142ce33b5485b6dcb6742adaedc238235fd1c92e5117cfd3d483945912b9a721719a91ad6b013f4a8038dcb20c1a10e3bfe5fb47fff20115168055f9f
|
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
# Prometheus Ruby Client
|
1
|
+
# Prometheus Ruby Mmap Client
|
2
|
+
|
3
|
+
This Prometheus library is fork of [Prometheus Ruby Client](https://github.com/prometheus/client_ruby)
|
4
|
+
that uses mmap'ed files to share metrics from multiple processes.
|
5
|
+
This allows efficient metrics processing for Ruby web apps running in multiprocess setups like Unicorn.
|
2
6
|
|
3
7
|
A suite of instrumentation metric primitives for Ruby that can be exposed
|
4
8
|
through a HTTP interface. Intended to be used together with a
|
5
9
|
[Prometheus server][1].
|
6
10
|
|
7
|
-
[![Gem Version][4]](http://badge.fury.io/rb/prometheus-client)
|
8
|
-
[![Build Status][3]](
|
11
|
+
[![Gem Version][4]](http://badge.fury.io/rb/prometheus-client-mmap)
|
12
|
+
[![Build Status][3]](https://gitlab.com/gitlab-org/prometheus-client-mmap/commits/master)
|
9
13
|
[![Dependency Status][5]](https://gemnasium.com/prometheus/client_ruby)
|
10
|
-
[![Code Climate][6]](https://codeclimate.com/github/prometheus/client_ruby)
|
11
|
-
[![Coverage Status][7]](https://coveralls.io/r/prometheus/client_ruby)
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
@@ -173,11 +175,8 @@ rake
|
|
173
175
|
|
174
176
|
[1]: https://github.com/prometheus/prometheus
|
175
177
|
[2]: http://rack.github.io/
|
176
|
-
[3]: https://
|
178
|
+
[3]: https://gitlab.com/gitlab-org/prometheus-client-mmap/badges/master/pipeline.svg
|
177
179
|
[4]: https://badge.fury.io/rb/prometheus-client.svg
|
178
|
-
[5]: https://gemnasium.com/prometheus/client_ruby.svg
|
179
|
-
[6]: https://codeclimate.com/github/prometheus/client_ruby.png
|
180
|
-
[7]: https://coveralls.io/repos/prometheus/client_ruby/badge.png?branch=master
|
181
180
|
[8]: https://github.com/prometheus/pushgateway
|
182
181
|
[9]: lib/prometheus/client/rack/exporter.rb
|
183
182
|
[10]: lib/prometheus/client/rack/collector.rb
|
@@ -5,96 +5,95 @@ module Prometheus
|
|
5
5
|
module Formats
|
6
6
|
# Text format is human readable mainly used for manual inspection.
|
7
7
|
module Text
|
8
|
-
MEDIA_TYPE
|
9
|
-
VERSION
|
8
|
+
MEDIA_TYPE = 'text/plain'.freeze
|
9
|
+
VERSION = '0.0.4'.freeze
|
10
10
|
CONTENT_TYPE = "#{MEDIA_TYPE}; version=#{VERSION}".freeze
|
11
11
|
|
12
12
|
METRIC_LINE = '%s%s %s'.freeze
|
13
|
-
TYPE_LINE
|
14
|
-
HELP_LINE
|
13
|
+
TYPE_LINE = '# TYPE %s %s'.freeze
|
14
|
+
HELP_LINE = '# HELP %s %s'.freeze
|
15
15
|
|
16
|
-
LABEL
|
16
|
+
LABEL = '%s="%s"'.freeze
|
17
17
|
SEPARATOR = ','.freeze
|
18
18
|
DELIMITER = "\n".freeze
|
19
19
|
|
20
|
-
REGEX
|
20
|
+
REGEX = { doc: /[\n\\]/, label: /[\n\\"]/ }.freeze
|
21
21
|
REPLACE = { "\n" => '\n', '\\' => '\\\\', '"' => '\"' }.freeze
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
class << self
|
24
|
+
def marshal(registry)
|
25
|
+
lines = []
|
26
|
+
|
27
|
+
registry.metrics.each do |metric|
|
28
|
+
lines << format(HELP_LINE, metric.name, escape(metric.docstring))
|
29
|
+
lines << format(TYPE_LINE, metric.name, metric.type)
|
30
|
+
metric.values.each do |label_set, value|
|
31
|
+
representation(metric, label_set, value) { |l| lines << l }
|
32
|
+
end
|
32
33
|
end
|
34
|
+
|
35
|
+
# there must be a trailing delimiter
|
36
|
+
(lines << nil).join(DELIMITER)
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
39
|
+
def marshal_multiprocess(path = Prometheus::Client.configuration.multiprocess_files_dir)
|
40
|
+
metrics = load_metrics(path)
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
lines = []
|
43
|
+
merge_metrics(metrics).each do |name, metric|
|
44
|
+
lines << format(HELP_LINE, name, escape(metric[:help]))
|
45
|
+
lines << format(TYPE_LINE, name, metric[:type])
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
buckets = {}
|
45
|
-
metric[:samples].each do |name, labels, value|
|
46
|
-
case metric[:type]
|
47
|
-
when :gauge
|
48
|
-
without_pid = labels.select{ |l| l[0] != 'pid' }
|
49
|
-
case metric[:multiprocess_mode]
|
50
|
-
when 'min'
|
51
|
-
s = samples.fetch([name, without_pid], value)
|
52
|
-
samples[[name, without_pid]] = [s, value].min
|
53
|
-
when 'max'
|
54
|
-
s = samples.fetch([name, without_pid], value)
|
55
|
-
samples[[name, without_pid]] = [s, value].max
|
56
|
-
when 'livesum'
|
57
|
-
s = samples.fetch([name, without_pid], 0.0)
|
58
|
-
samples[[name, without_pid]] = s + value
|
59
|
-
else # all/liveall
|
60
|
-
samples[[name, labels]] = value
|
61
|
-
end
|
62
|
-
else
|
63
|
-
# Counter, Histogram and Summary.
|
64
|
-
without_pid = labels.select{ |l| l[0] != 'pid' }
|
65
|
-
s = samples.fetch([name, without_pid], 0.0)
|
66
|
-
samples[[name, without_pid]] = s + value
|
47
|
+
metric[:samples].each do |metric_name, labels, value|
|
48
|
+
lines << metric(metric_name, format_labels(labels), value)
|
67
49
|
end
|
50
|
+
end
|
51
|
+
(lines << nil).join(DELIMITER)
|
52
|
+
end
|
68
53
|
|
69
|
-
|
70
|
-
|
54
|
+
private
|
55
|
+
|
56
|
+
def merge_metrics(metrics)
|
57
|
+
metrics.each_value do |metric|
|
58
|
+
metric[:samples] = merge_samples(metric[:samples], metric[:type], metric[:multiprocess_mode]).map do |(name, labels), value|
|
71
59
|
[name, labels.to_h, value]
|
72
60
|
end
|
73
61
|
end
|
74
62
|
end
|
75
63
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
64
|
+
def merge_samples(raw_samples, metric_type, multiprocess_mode)
|
65
|
+
samples = {}
|
66
|
+
raw_samples.each do |name, labels, value|
|
67
|
+
without_pid = labels.reject { |l| l[0] == 'pid' }
|
68
|
+
|
69
|
+
case metric_type
|
70
|
+
when :gauge
|
71
|
+
case multiprocess_mode
|
72
|
+
when 'min'
|
73
|
+
s = samples.fetch([name, without_pid], value)
|
74
|
+
samples[[name, without_pid]] = [s, value].min
|
75
|
+
when 'max'
|
76
|
+
s = samples.fetch([name, without_pid], value)
|
77
|
+
samples[[name, without_pid]] = [s, value].max
|
78
|
+
when 'livesum'
|
79
|
+
s = samples.fetch([name, without_pid], 0.0)
|
80
|
+
samples[[name, without_pid]] = s + value
|
81
|
+
else # all/liveall
|
82
|
+
samples[[name, labels]] = value
|
83
|
+
end
|
84
|
+
else
|
85
|
+
# Counter, Histogram and Summary.
|
86
|
+
s = samples.fetch([name, without_pid], 0.0)
|
87
|
+
samples[[name, without_pid]] = s + value
|
85
88
|
end
|
86
|
-
output += "#{metric_name}#{labelstr} #{value}\n"
|
87
89
|
end
|
88
|
-
end
|
89
|
-
output
|
90
|
-
end
|
91
90
|
|
92
|
-
|
93
|
-
|
91
|
+
samples
|
92
|
+
end
|
94
93
|
|
95
94
|
def load_metrics(path)
|
96
95
|
metrics = {}
|
97
|
-
Dir.glob(File.join(path, '*.db')).each do |f|
|
96
|
+
Dir.glob(File.join(path, '*.db')).sort.each do |f|
|
98
97
|
parts = File.basename(f, '.db').split('_')
|
99
98
|
type = parts[0].to_sym
|
100
99
|
d = MmapedDict.new(f)
|
@@ -133,36 +132,36 @@ module Prometheus
|
|
133
132
|
elsif metric.type == :histogram
|
134
133
|
histogram(metric.name, set, value, &block)
|
135
134
|
else
|
136
|
-
yield metric(metric.name,
|
135
|
+
yield metric(metric.name, format_labels(set), value.get)
|
137
136
|
end
|
138
137
|
end
|
139
138
|
|
140
139
|
def summary(name, set, value)
|
141
|
-
value.each do |q, v|
|
142
|
-
yield metric(name,
|
140
|
+
value.get.each do |q, v|
|
141
|
+
yield metric(name, format_labels(set.merge(quantile: q)), v)
|
143
142
|
end
|
144
143
|
|
145
|
-
l =
|
146
|
-
yield metric("#{name}_sum", l, value.sum
|
147
|
-
yield metric("#{name}_count", l, value.total
|
144
|
+
l = format_labels(set)
|
145
|
+
yield metric("#{name}_sum", l, value.get.sum)
|
146
|
+
yield metric("#{name}_count", l, value.get.total)
|
148
147
|
end
|
149
148
|
|
150
149
|
def histogram(name, set, value)
|
151
|
-
value.each do |q, v|
|
152
|
-
yield metric(name,
|
150
|
+
value.get.each do |q, v|
|
151
|
+
yield metric(name, format_labels(set.merge(le: q)), v)
|
153
152
|
end
|
154
|
-
yield metric(name,
|
153
|
+
yield metric(name, format_labels(set.merge(le: '+Inf')), value.get.total)
|
155
154
|
|
156
|
-
l =
|
157
|
-
yield metric("#{name}_sum", l, value.sum
|
158
|
-
yield metric("#{name}_count", l, value.total
|
155
|
+
l = format_labels(set)
|
156
|
+
yield metric("#{name}_sum", l, value.get.sum)
|
157
|
+
yield metric("#{name}_count", l, value.get.total)
|
159
158
|
end
|
160
159
|
|
161
160
|
def metric(name, labels, value)
|
162
161
|
format(METRIC_LINE, name, labels, value)
|
163
162
|
end
|
164
163
|
|
165
|
-
def
|
164
|
+
def format_labels(set)
|
166
165
|
return if set.empty?
|
167
166
|
|
168
167
|
strings = set.each_with_object([]) do |(key, value), memo|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prometheus-client-mmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.beta12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Schmidt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mmap2
|