prometheus_exporter 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/prometheus_exporter +26 -33
- data/lib/prometheus_exporter/metric/summary.rb +2 -1
- data/lib/prometheus_exporter/server/runner.rb +89 -0
- data/lib/prometheus_exporter/server.rb +2 -1
- data/lib/prometheus_exporter/version.rb +1 -1
- data/lib/prometheus_exporter.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd8e78f5b3845845709c7479c94326c24f24b8a6e46b124b88c8f3d1a433f66e
|
4
|
+
data.tar.gz: 8813dc2dede6682afa0cf0ffa148bdd482f2a2affc6d5c719b825f1f1f8b8612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de2d4650f99c955d1bc22a0f364504d17670628d03130f47aa50c835c2933e57547a093d0c6807dd9763255b3bdcc6f8ba469bbe1b8c2094419f55907ad1f893
|
7
|
+
data.tar.gz: 04e43b29d74c7f938d667c70dde47b94330482344edcb1134a39f9d9d70a7187b02c6e4a746452cdc6c236574b7fdb7d0d38986bd057daa5f1c1009fe8a31f85
|
data/bin/prometheus_exporter
CHANGED
@@ -6,76 +6,69 @@ require_relative "./../lib/prometheus_exporter"
|
|
6
6
|
require_relative "./../lib/prometheus_exporter/server"
|
7
7
|
|
8
8
|
def run
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
verbose = false
|
13
|
-
type_collectors = []
|
14
|
-
collector_class = PrometheusExporter::Server::Collector
|
9
|
+
options = {}
|
10
|
+
custom_collector_filename = nil
|
11
|
+
custom_type_collectors_filenames = []
|
15
12
|
|
16
13
|
OptionParser.new do |opt|
|
14
|
+
opt.banner = "Usage: prometheus_exporter [options]"
|
17
15
|
opt.on('-p',
|
18
16
|
'--port INTEGER',
|
19
17
|
Integer,
|
20
|
-
"Port exporter should listen on (default: #{
|
21
|
-
port = o.to_i
|
18
|
+
"Port exporter should listen on (default: #{PrometheusExporter::DEFAULT_PORT})") do |o|
|
19
|
+
options[:port] = o.to_i
|
22
20
|
end
|
23
|
-
opt.on('--prefix METRIC_PREFIX', String, "Prefix to apply to all metrics (default: #{
|
24
|
-
prefix = o.to_s
|
21
|
+
opt.on('--prefix METRIC_PREFIX', String, "Prefix to apply to all metrics (default: #{PrometheusExporter::DEFAULT_PREFIX})") do |o|
|
22
|
+
options[:prefix] = o.to_s
|
25
23
|
end
|
26
24
|
opt.on('-c', '--collector FILE', String, "(optional) Custom collector to run") do |o|
|
27
|
-
|
25
|
+
custom_collector_filename = o.to_s
|
28
26
|
end
|
29
27
|
opt.on('-a', '--type-collector FILE', String, "(optional) Custom type collectors to run in main collector") do |o|
|
30
|
-
|
28
|
+
custom_type_collectors_filenames << o
|
31
29
|
end
|
32
30
|
opt.on('-v', '--verbose') do |o|
|
33
|
-
verbose = true
|
31
|
+
options[:verbose] = true
|
34
32
|
end
|
35
33
|
|
36
34
|
end.parse!
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
if collector_filename
|
41
|
-
eval File.read(collector_filename), nil, File.expand_path(collector_filename)
|
42
|
-
|
36
|
+
if custom_collector_filename
|
37
|
+
eval File.read(custom_collector_filename), nil, File.expand_path(custom_collector_filename)
|
43
38
|
found = false
|
44
39
|
|
40
|
+
base_klass = PrometheusExporter::Server::CollectorBase
|
41
|
+
|
45
42
|
ObjectSpace.each_object(Class) do |klass|
|
46
|
-
if klass <
|
47
|
-
collector_class = klass
|
48
|
-
found = true
|
43
|
+
if klass < base_klass && klass != base_klass
|
44
|
+
options[:collector_class] = klass
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
52
48
|
if !found
|
53
|
-
STDERR.puts "Can not find a class inheriting off PrometheusExporter::Server::CollectorBase"
|
54
|
-
usage
|
49
|
+
STDERR.puts "[Error] Can not find a class inheriting off PrometheusExporter::Server::CollectorBase"
|
55
50
|
exit 1
|
56
51
|
end
|
57
52
|
end
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
if type_collectors.length > 0
|
62
|
-
type_collectors.each do |t|
|
54
|
+
if custom_type_collectors_filenames.length > 0
|
55
|
+
custom_type_collectors_filenames.each do |t|
|
63
56
|
eval File.read(t), nil, File.expand_path(t)
|
64
57
|
end
|
65
58
|
|
66
59
|
ObjectSpace.each_object(Class) do |klass|
|
67
60
|
if klass < PrometheusExporter::Server::TypeCollector
|
68
|
-
|
69
|
-
|
61
|
+
options[:type_collectors] ||= []
|
62
|
+
options[:type_collectors] << klass
|
70
63
|
end
|
71
64
|
end
|
72
65
|
end
|
73
66
|
|
74
|
-
|
75
|
-
server = PrometheusExporter::Server::WebServer.new port: port, collector: collector, verbose: verbose
|
76
|
-
server.start
|
77
|
-
sleep
|
67
|
+
runner = PrometheusExporter::Server::Runner.new(options)
|
78
68
|
|
69
|
+
puts "#{Time.now} Starting prometheus exporter on port #{runner.port}"
|
70
|
+
runner.start
|
71
|
+
sleep
|
79
72
|
end
|
80
73
|
|
81
74
|
run
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PrometheusExporter::Server
|
4
|
+
class RunnerException < StandardError; end;
|
5
|
+
class WrongInheritance < RunnerException; end;
|
6
|
+
|
7
|
+
class Runner
|
8
|
+
def initialize(options = {})
|
9
|
+
options.each do |k, v|
|
10
|
+
send("#{k}=", v) if self.class.method_defined?("#{k}=")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
PrometheusExporter::Metric::Base.default_prefix = prefix
|
16
|
+
|
17
|
+
register_type_collectors
|
18
|
+
|
19
|
+
unless collector.is_a?(PrometheusExporter::Server::CollectorBase)
|
20
|
+
raise WrongInheritance, 'Collector class must be inherited from PrometheusExporter::Server::CollectorBase'
|
21
|
+
end
|
22
|
+
|
23
|
+
server = server_class.new port: port, collector: collector, verbose: verbose
|
24
|
+
server.start
|
25
|
+
end
|
26
|
+
|
27
|
+
def prefix=(prefix)
|
28
|
+
@prefix = prefix
|
29
|
+
end
|
30
|
+
|
31
|
+
def prefix
|
32
|
+
@prefix || PrometheusExporter::DEFAULT_PREFIX
|
33
|
+
end
|
34
|
+
|
35
|
+
def port=(port)
|
36
|
+
@port = port
|
37
|
+
end
|
38
|
+
|
39
|
+
def port
|
40
|
+
@port || PrometheusExporter::DEFAULT_PORT
|
41
|
+
end
|
42
|
+
|
43
|
+
def collector_class=(collector_class)
|
44
|
+
@collector_class = collector_class
|
45
|
+
end
|
46
|
+
|
47
|
+
def collector_class
|
48
|
+
@collector_class || PrometheusExporter::Server::Collector
|
49
|
+
end
|
50
|
+
|
51
|
+
def type_collectors=(type_collectors)
|
52
|
+
@type_collectors = type_collectors
|
53
|
+
end
|
54
|
+
|
55
|
+
def type_collectors
|
56
|
+
@type_collectors || []
|
57
|
+
end
|
58
|
+
|
59
|
+
def verbose=(verbose)
|
60
|
+
@verbose = verbose
|
61
|
+
end
|
62
|
+
|
63
|
+
def verbose
|
64
|
+
return @verbose if defined? @verbose
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def server_class=(server_class)
|
69
|
+
@server_class = server_class
|
70
|
+
end
|
71
|
+
|
72
|
+
def server_class
|
73
|
+
@server_class || PrometheusExporter::Server::WebServer
|
74
|
+
end
|
75
|
+
|
76
|
+
def collector
|
77
|
+
@_collector ||= collector_class.new
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def register_type_collectors
|
83
|
+
type_collectors.each do |klass|
|
84
|
+
collector.register_collector klass.new
|
85
|
+
STDERR.puts "Registered TypeCollector: #{klass}" if verbose
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative "metric"
|
1
2
|
require_relative "server/type_collector"
|
2
3
|
require_relative "server/web_collector"
|
3
4
|
require_relative "server/process_collector"
|
@@ -5,4 +6,4 @@ require_relative "server/sidekiq_collector"
|
|
5
6
|
require_relative "server/collector_base"
|
6
7
|
require_relative "server/collector"
|
7
8
|
require_relative "server/web_server"
|
8
|
-
require_relative "
|
9
|
+
require_relative "server/runner"
|
data/lib/prometheus_exporter.rb
CHANGED
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.
|
4
|
+
version: 0.1.14
|
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-
|
11
|
+
date: 2018-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/prometheus_exporter/server/collector.rb
|
132
132
|
- lib/prometheus_exporter/server/collector_base.rb
|
133
133
|
- lib/prometheus_exporter/server/process_collector.rb
|
134
|
+
- lib/prometheus_exporter/server/runner.rb
|
134
135
|
- lib/prometheus_exporter/server/sidekiq_collector.rb
|
135
136
|
- lib/prometheus_exporter/server/type_collector.rb
|
136
137
|
- lib/prometheus_exporter/server/web_collector.rb
|
@@ -157,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
160
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.7.3
|
161
162
|
signing_key:
|
162
163
|
specification_version: 4
|
163
164
|
summary: Prometheus Exporter
|