phobos_prometheus 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_common.yml +23 -0
- data/.rubosync.yml +2 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +44 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +176 -0
- data/PULL_REQUEST_TEMPLATE.md +29 -0
- data/README.md +126 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/config/phobos_prometheus.yml.example +46 -0
- data/lib/phobos_prometheus.rb +69 -0
- data/lib/phobos_prometheus/collector.rb +14 -0
- data/lib/phobos_prometheus/collector/counter.rb +34 -0
- data/lib/phobos_prometheus/collector/error_logger.rb +28 -0
- data/lib/phobos_prometheus/collector/gauge.rb +59 -0
- data/lib/phobos_prometheus/collector/helper.rb +35 -0
- data/lib/phobos_prometheus/collector/histogram.rb +48 -0
- data/lib/phobos_prometheus/config_parser.rb +205 -0
- data/lib/phobos_prometheus/errors.rb +8 -0
- data/lib/phobos_prometheus/exporter.rb +43 -0
- data/lib/phobos_prometheus/exporter_helper.rb +42 -0
- data/lib/phobos_prometheus/logger.rb +18 -0
- data/lib/phobos_prometheus/version.rb +5 -0
- data/phobos_prometheus.gemspec +45 -0
- metadata +216 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PhobosPrometheus
|
4
|
+
# Exporter is a Rack application that provides a Prometheus HTTP exposition
|
5
|
+
# endpoint.
|
6
|
+
class Exporter < Sinatra::Base
|
7
|
+
attr_reader :registry
|
8
|
+
|
9
|
+
FORMATS = [Prometheus::Client::Formats::Text].freeze
|
10
|
+
FALLBACK = Prometheus::Client::Formats::Text
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
@registry = Prometheus::Client.registry
|
15
|
+
@acceptable = ExporterHelper.build_dictionary(FORMATS, FALLBACK)
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/' do
|
19
|
+
format = ExporterHelper.negotiate(env, @acceptable)
|
20
|
+
format ? respond_with(format) : not_acceptable(FORMATS)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def respond_with(format)
|
26
|
+
[
|
27
|
+
200,
|
28
|
+
{ 'Content-Type' => format::CONTENT_TYPE },
|
29
|
+
[format.marshal(@registry)]
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def not_acceptable(formats)
|
34
|
+
types = formats.map { |format| format::MEDIA_TYPE }
|
35
|
+
|
36
|
+
[
|
37
|
+
406,
|
38
|
+
{ 'Content-Type' => 'text/plain' },
|
39
|
+
["Supported media types: #{types.join(', ')}"]
|
40
|
+
]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PhobosPrometheus
|
4
|
+
# Helper for Exporter
|
5
|
+
class ExporterHelper
|
6
|
+
class << self
|
7
|
+
def negotiate(env, formats)
|
8
|
+
parse(env.fetch('HTTP_ACCEPT', '*/*')).each_entry do |content_type, _|
|
9
|
+
return formats[content_type] if formats.key?(content_type)
|
10
|
+
end
|
11
|
+
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse(header)
|
16
|
+
header.split(/\s*,\s*/).map do |type|
|
17
|
+
attributes = type.split(/\s*;\s*/)
|
18
|
+
quality = extract_quality(attributes)
|
19
|
+
|
20
|
+
[attributes.join('; '), quality]
|
21
|
+
end.sort_by(&:last).reverse
|
22
|
+
end
|
23
|
+
|
24
|
+
def extract_quality(attributes, default = 1.0)
|
25
|
+
quality = default
|
26
|
+
|
27
|
+
attributes.delete_if do |attr|
|
28
|
+
quality = attr.split('q=').last.to_f if attr.start_with?('q=')
|
29
|
+
end
|
30
|
+
|
31
|
+
quality
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_dictionary(formats, fallback)
|
35
|
+
formats.each_with_object('*/*' => fallback) do |format, memo|
|
36
|
+
memo[format::CONTENT_TYPE] = format
|
37
|
+
memo[format::MEDIA_TYPE] = format
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PhobosPrometheus
|
4
|
+
# Logger module
|
5
|
+
module Logger
|
6
|
+
def log_info(message)
|
7
|
+
Phobos.logger.info(Hash(message: message))
|
8
|
+
end
|
9
|
+
|
10
|
+
def log_warn(message)
|
11
|
+
Phobos.logger.warn(Hash(message: message))
|
12
|
+
end
|
13
|
+
|
14
|
+
def log_error(message)
|
15
|
+
Phobos.logger.error(Hash(message: message))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'phobos_prometheus/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'phobos_prometheus'
|
9
|
+
spec.version = PhobosPrometheus::VERSION
|
10
|
+
spec.authors = ['Mathias Klippinge']
|
11
|
+
spec.email = ['mathias.klippinge@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Prometheus collector for Phobos'
|
14
|
+
spec.description = 'Gathers metrics from Phobos, making it possible for ' \
|
15
|
+
'Prometheus server to consume this'
|
16
|
+
spec.homepage = 'https://github.com/klarna/phobos_prometheus'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
'public gem pushes.'
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = 'bin'
|
31
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_dependency 'phobos'
|
35
|
+
spec.add_dependency 'prometheus-client'
|
36
|
+
spec.add_dependency 'sinatra'
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
|
+
spec.add_development_dependency 'pry'
|
40
|
+
spec.add_development_dependency 'rack-test'
|
41
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
43
|
+
spec.add_development_dependency 'rubocop_rules'
|
44
|
+
spec.add_development_dependency 'simplecov'
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phobos_prometheus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathias Klippinge
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: phobos
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: prometheus-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sinatra
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop_rules
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Gathers metrics from Phobos, making it possible for Prometheus server
|
154
|
+
to consume this
|
155
|
+
email:
|
156
|
+
- mathias.klippinge@gmail.com
|
157
|
+
executables:
|
158
|
+
- console
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- ".editorconfig"
|
163
|
+
- ".gitignore"
|
164
|
+
- ".rspec"
|
165
|
+
- ".rubocop.yml"
|
166
|
+
- ".rubocop_common.yml"
|
167
|
+
- ".rubosync.yml"
|
168
|
+
- ".travis.yml"
|
169
|
+
- CHANGELOG.md
|
170
|
+
- CODE_OF_CONDUCT.md
|
171
|
+
- Gemfile
|
172
|
+
- LICENSE.txt
|
173
|
+
- PULL_REQUEST_TEMPLATE.md
|
174
|
+
- README.md
|
175
|
+
- Rakefile
|
176
|
+
- bin/console
|
177
|
+
- config/phobos_prometheus.yml.example
|
178
|
+
- lib/phobos_prometheus.rb
|
179
|
+
- lib/phobos_prometheus/collector.rb
|
180
|
+
- lib/phobos_prometheus/collector/counter.rb
|
181
|
+
- lib/phobos_prometheus/collector/error_logger.rb
|
182
|
+
- lib/phobos_prometheus/collector/gauge.rb
|
183
|
+
- lib/phobos_prometheus/collector/helper.rb
|
184
|
+
- lib/phobos_prometheus/collector/histogram.rb
|
185
|
+
- lib/phobos_prometheus/config_parser.rb
|
186
|
+
- lib/phobos_prometheus/errors.rb
|
187
|
+
- lib/phobos_prometheus/exporter.rb
|
188
|
+
- lib/phobos_prometheus/exporter_helper.rb
|
189
|
+
- lib/phobos_prometheus/logger.rb
|
190
|
+
- lib/phobos_prometheus/version.rb
|
191
|
+
- phobos_prometheus.gemspec
|
192
|
+
homepage: https://github.com/klarna/phobos_prometheus
|
193
|
+
licenses: []
|
194
|
+
metadata:
|
195
|
+
allowed_push_host: https://rubygems.org
|
196
|
+
post_install_message:
|
197
|
+
rdoc_options: []
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
requirements: []
|
211
|
+
rubyforge_project:
|
212
|
+
rubygems_version: 2.6.13
|
213
|
+
signing_key:
|
214
|
+
specification_version: 4
|
215
|
+
summary: Prometheus collector for Phobos
|
216
|
+
test_files: []
|