prometheus_exporter 0.7.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +298 -35
- data/README.md +276 -53
- data/{bin → exe}/prometheus_exporter +20 -7
- data/lib/prometheus_exporter/client.rb +41 -32
- data/lib/prometheus_exporter/instrumentation/active_record.rb +29 -35
- data/lib/prometheus_exporter/instrumentation/delayed_job.rb +28 -13
- data/lib/prometheus_exporter/instrumentation/good_job.rb +28 -0
- data/lib/prometheus_exporter/instrumentation/hutch.rb +1 -1
- data/lib/prometheus_exporter/instrumentation/method_profiler.rb +67 -27
- data/lib/prometheus_exporter/instrumentation/periodic_stats.rb +54 -0
- data/lib/prometheus_exporter/instrumentation/process.rb +25 -27
- data/lib/prometheus_exporter/instrumentation/puma.rb +36 -27
- data/lib/prometheus_exporter/instrumentation/resque.rb +33 -0
- data/lib/prometheus_exporter/instrumentation/shoryuken.rb +6 -7
- data/lib/prometheus_exporter/instrumentation/sidekiq.rb +51 -23
- data/lib/prometheus_exporter/instrumentation/sidekiq_process.rb +45 -0
- data/lib/prometheus_exporter/instrumentation/sidekiq_queue.rb +38 -33
- data/lib/prometheus_exporter/instrumentation/sidekiq_stats.rb +32 -0
- data/lib/prometheus_exporter/instrumentation/unicorn.rb +12 -17
- data/lib/prometheus_exporter/instrumentation.rb +5 -0
- data/lib/prometheus_exporter/metric/base.rb +20 -17
- data/lib/prometheus_exporter/metric/counter.rb +1 -3
- data/lib/prometheus_exporter/metric/gauge.rb +6 -6
- data/lib/prometheus_exporter/metric/histogram.rb +15 -5
- data/lib/prometheus_exporter/metric/summary.rb +5 -14
- data/lib/prometheus_exporter/middleware.rb +72 -38
- data/lib/prometheus_exporter/server/active_record_collector.rb +16 -14
- data/lib/prometheus_exporter/server/collector.rb +29 -17
- data/lib/prometheus_exporter/server/collector_base.rb +0 -2
- data/lib/prometheus_exporter/server/delayed_job_collector.rb +76 -33
- data/lib/prometheus_exporter/server/good_job_collector.rb +52 -0
- data/lib/prometheus_exporter/server/hutch_collector.rb +19 -11
- data/lib/prometheus_exporter/server/metrics_container.rb +66 -0
- data/lib/prometheus_exporter/server/process_collector.rb +15 -14
- data/lib/prometheus_exporter/server/puma_collector.rb +21 -18
- data/lib/prometheus_exporter/server/resque_collector.rb +50 -0
- data/lib/prometheus_exporter/server/runner.rb +49 -13
- data/lib/prometheus_exporter/server/shoryuken_collector.rb +22 -17
- data/lib/prometheus_exporter/server/sidekiq_collector.rb +22 -14
- data/lib/prometheus_exporter/server/sidekiq_process_collector.rb +47 -0
- data/lib/prometheus_exporter/server/sidekiq_queue_collector.rb +12 -12
- data/lib/prometheus_exporter/server/sidekiq_stats_collector.rb +49 -0
- data/lib/prometheus_exporter/server/type_collector.rb +2 -0
- data/lib/prometheus_exporter/server/unicorn_collector.rb +32 -33
- data/lib/prometheus_exporter/server/web_collector.rb +48 -31
- data/lib/prometheus_exporter/server/web_server.rb +70 -48
- data/lib/prometheus_exporter/server.rb +4 -0
- data/lib/prometheus_exporter/version.rb +1 -1
- data/lib/prometheus_exporter.rb +12 -13
- metadata +19 -206
- data/.github/workflows/ci.yml +0 -42
- data/.gitignore +0 -13
- data/.rubocop.yml +0 -7
- data/Appraisals +0 -10
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -8
- data/Guardfile +0 -8
- data/Rakefile +0 -12
- data/bench/bench.rb +0 -45
- data/examples/custom_collector.rb +0 -27
- data/gemfiles/.bundle/config +0 -2
- data/gemfiles/ar_60.gemfile +0 -5
- data/gemfiles/ar_61.gemfile +0 -7
- data/prometheus_exporter.gemspec +0 -46
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PrometheusExporter::Server
|
|
4
|
+
class SidekiqStatsCollector < TypeCollector
|
|
5
|
+
MAX_METRIC_AGE = 60
|
|
6
|
+
|
|
7
|
+
SIDEKIQ_STATS_GAUGES = {
|
|
8
|
+
"dead_size" => "Size of dead the queue",
|
|
9
|
+
"enqueued" => "Number of enqueued jobs",
|
|
10
|
+
"failed" => "Number of failed jobs",
|
|
11
|
+
"processed" => "Total number of processed jobs",
|
|
12
|
+
"processes_size" => "Number of processes",
|
|
13
|
+
"retry_size" => "Size of the retries queue",
|
|
14
|
+
"scheduled_size" => "Size of the scheduled queue",
|
|
15
|
+
"workers_size" => "Number of jobs actively being processed",
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
attr_reader :sidekiq_metrics, :gauges
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
@sidekiq_metrics = MetricsContainer.new(ttl: MAX_METRIC_AGE)
|
|
22
|
+
@gauges = {}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def type
|
|
26
|
+
"sidekiq_stats"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def metrics
|
|
30
|
+
SIDEKIQ_STATS_GAUGES.each_key { |name| gauges[name]&.reset! }
|
|
31
|
+
|
|
32
|
+
sidekiq_metrics.map do |metric|
|
|
33
|
+
SIDEKIQ_STATS_GAUGES.map do |name, help|
|
|
34
|
+
if (value = metric["stats"][name])
|
|
35
|
+
gauge =
|
|
36
|
+
gauges[name] ||= PrometheusExporter::Metric::Gauge.new("sidekiq_stats_#{name}", help)
|
|
37
|
+
gauge.observe(value)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
gauges.values
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def collect(object)
|
|
46
|
+
@sidekiq_metrics << object
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -2,47 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
# custom type collector for prometheus_exporter for handling the metrics sent from
|
|
4
4
|
# PrometheusExporter::Instrumentation::Unicorn
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
module PrometheusExporter::Server
|
|
6
|
+
class UnicornCollector < PrometheusExporter::Server::TypeCollector
|
|
7
|
+
MAX_METRIC_AGE = 60
|
|
8
|
+
|
|
9
|
+
UNICORN_GAUGES = {
|
|
10
|
+
workers: "Number of unicorn workers.",
|
|
11
|
+
active_workers: "Number of active unicorn workers",
|
|
12
|
+
request_backlog: "Number of requests waiting to be processed by a unicorn worker.",
|
|
13
|
+
}.freeze
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
@unicorn_metrics = MetricsContainer.new(ttl: MAX_METRIC_AGE)
|
|
17
|
+
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
def type
|
|
20
|
+
"unicorn"
|
|
21
|
+
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
def metrics
|
|
24
|
+
return [] if @unicorn_metrics.length.zero?
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
metrics = {}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
@unicorn_metrics.map do |m|
|
|
29
|
+
labels = m["custom_labels"] || {}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
UNICORN_GAUGES.map do |k, help|
|
|
32
|
+
k = k.to_s
|
|
33
|
+
if (v = m[k])
|
|
34
|
+
g = metrics[k] ||= PrometheusExporter::Metric::Gauge.new("unicorn_#{k}", help)
|
|
35
|
+
g.observe(v, labels)
|
|
36
|
+
end
|
|
35
37
|
end
|
|
36
38
|
end
|
|
37
|
-
end
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
metrics.values
|
|
41
|
+
end
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@unicorn_metrics.delete_if { |m| m['created_at'] + MAX_UNICORN_METRIC_AGE < now }
|
|
46
|
-
@unicorn_metrics << obj
|
|
43
|
+
def collect(obj)
|
|
44
|
+
@unicorn_metrics << obj
|
|
45
|
+
end
|
|
47
46
|
end
|
|
48
47
|
end
|
|
@@ -5,10 +5,11 @@ module PrometheusExporter::Server
|
|
|
5
5
|
def initialize
|
|
6
6
|
@metrics = {}
|
|
7
7
|
@http_requests_total = nil
|
|
8
|
-
@
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
@
|
|
8
|
+
@http_request_duration_seconds = nil
|
|
9
|
+
@http_request_redis_duration_seconds = nil
|
|
10
|
+
@http_request_sql_duration_seconds = nil
|
|
11
|
+
@http_request_queue_duration_seconds = nil
|
|
12
|
+
@http_request_memcache_duration_seconds = nil
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def type
|
|
@@ -28,51 +29,67 @@ module PrometheusExporter::Server
|
|
|
28
29
|
|
|
29
30
|
def ensure_metrics
|
|
30
31
|
unless @http_requests_total
|
|
31
|
-
@metrics["http_requests_total"] = @http_requests_total =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
@metrics["http_requests_total"] = @http_requests_total =
|
|
33
|
+
PrometheusExporter::Metric::Counter.new(
|
|
34
|
+
"http_requests_total",
|
|
35
|
+
"Total HTTP requests from web app.",
|
|
36
|
+
)
|
|
35
37
|
|
|
36
|
-
@metrics["
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
@metrics["http_request_duration_seconds"] = @http_request_duration_seconds =
|
|
39
|
+
PrometheusExporter::Metric::Base.default_aggregation.new(
|
|
40
|
+
"http_request_duration_seconds",
|
|
41
|
+
"Time spent in HTTP reqs in seconds.",
|
|
42
|
+
)
|
|
40
43
|
|
|
41
|
-
@metrics["
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
@metrics["http_request_redis_duration_seconds"] = @http_request_redis_duration_seconds =
|
|
45
|
+
PrometheusExporter::Metric::Base.default_aggregation.new(
|
|
46
|
+
"http_request_redis_duration_seconds",
|
|
47
|
+
"Time spent in HTTP reqs in Redis, in seconds.",
|
|
48
|
+
)
|
|
45
49
|
|
|
46
|
-
@metrics["
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
@metrics["http_request_sql_duration_seconds"] = @http_request_sql_duration_seconds =
|
|
51
|
+
PrometheusExporter::Metric::Base.default_aggregation.new(
|
|
52
|
+
"http_request_sql_duration_seconds",
|
|
53
|
+
"Time spent in HTTP reqs in SQL in seconds.",
|
|
54
|
+
)
|
|
50
55
|
|
|
51
|
-
@metrics[
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
@metrics[
|
|
57
|
+
"http_request_memcache_duration_seconds"
|
|
58
|
+
] = @http_request_memcache_duration_seconds =
|
|
59
|
+
PrometheusExporter::Metric::Base.default_aggregation.new(
|
|
60
|
+
"http_request_memcache_duration_seconds",
|
|
61
|
+
"Time spent in HTTP reqs in Memcache in seconds.",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@metrics["http_request_queue_duration_seconds"] = @http_request_queue_duration_seconds =
|
|
65
|
+
PrometheusExporter::Metric::Base.default_aggregation.new(
|
|
66
|
+
"http_request_queue_duration_seconds",
|
|
67
|
+
"Time spent queueing the request in load balancer in seconds.",
|
|
68
|
+
)
|
|
55
69
|
end
|
|
56
70
|
end
|
|
57
71
|
|
|
58
72
|
def observe(obj)
|
|
59
|
-
default_labels = obj[
|
|
60
|
-
custom_labels = obj[
|
|
73
|
+
default_labels = obj["default_labels"]
|
|
74
|
+
custom_labels = obj["custom_labels"]
|
|
61
75
|
labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
|
|
62
76
|
|
|
63
|
-
@http_requests_total.observe(1, labels)
|
|
77
|
+
@http_requests_total.observe(1, labels.merge("status" => obj["status"]))
|
|
64
78
|
|
|
65
79
|
if timings = obj["timings"]
|
|
66
|
-
@
|
|
80
|
+
@http_request_duration_seconds.observe(timings["total_duration"], labels)
|
|
67
81
|
if redis = timings["redis"]
|
|
68
|
-
@
|
|
82
|
+
@http_request_redis_duration_seconds.observe(redis["duration"], labels)
|
|
69
83
|
end
|
|
70
84
|
if sql = timings["sql"]
|
|
71
|
-
@
|
|
85
|
+
@http_request_sql_duration_seconds.observe(sql["duration"], labels)
|
|
86
|
+
end
|
|
87
|
+
if memcache = timings["memcache"]
|
|
88
|
+
@http_request_memcache_duration_seconds.observe(memcache["duration"], labels)
|
|
72
89
|
end
|
|
73
90
|
end
|
|
74
91
|
if queue_time = obj["queue_time"]
|
|
75
|
-
@
|
|
92
|
+
@http_request_queue_duration_seconds.observe(queue_time, labels)
|
|
76
93
|
end
|
|
77
94
|
end
|
|
78
95
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require "webrick"
|
|
4
|
+
require "timeout"
|
|
5
|
+
require "zlib"
|
|
6
|
+
require "stringio"
|
|
7
7
|
|
|
8
8
|
module PrometheusExporter::Server
|
|
9
9
|
class WebServer
|
|
@@ -12,47 +12,67 @@ module PrometheusExporter::Server
|
|
|
12
12
|
def initialize(opts)
|
|
13
13
|
@port = opts[:port] || PrometheusExporter::DEFAULT_PORT
|
|
14
14
|
@bind = opts[:bind] || PrometheusExporter::DEFAULT_BIND_ADDRESS
|
|
15
|
-
@collector = opts[:collector] || Collector.new
|
|
16
15
|
@timeout = opts[:timeout] || PrometheusExporter::DEFAULT_TIMEOUT
|
|
17
16
|
@verbose = opts[:verbose] || false
|
|
18
17
|
@auth = opts[:auth]
|
|
19
18
|
@realm = opts[:realm] || PrometheusExporter::DEFAULT_REALM
|
|
20
19
|
|
|
21
|
-
@metrics_total =
|
|
20
|
+
@metrics_total =
|
|
21
|
+
PrometheusExporter::Metric::Counter.new(
|
|
22
|
+
"collector_metrics_total",
|
|
23
|
+
"Total metrics processed by exporter web.",
|
|
24
|
+
)
|
|
22
25
|
|
|
23
|
-
@sessions_total =
|
|
26
|
+
@sessions_total =
|
|
27
|
+
PrometheusExporter::Metric::Counter.new(
|
|
28
|
+
"collector_sessions_total",
|
|
29
|
+
"Total send_metric sessions processed by exporter web.",
|
|
30
|
+
)
|
|
24
31
|
|
|
25
|
-
@bad_metrics_total =
|
|
32
|
+
@bad_metrics_total =
|
|
33
|
+
PrometheusExporter::Metric::Counter.new(
|
|
34
|
+
"collector_bad_metrics_total",
|
|
35
|
+
"Total mis-handled metrics by collector.",
|
|
36
|
+
)
|
|
26
37
|
|
|
27
38
|
@metrics_total.observe(0)
|
|
28
39
|
@sessions_total.observe(0)
|
|
29
40
|
@bad_metrics_total.observe(0)
|
|
30
41
|
|
|
31
42
|
@access_log, @logger = nil
|
|
43
|
+
log_target = opts[:log_target]
|
|
32
44
|
|
|
33
45
|
if @verbose
|
|
34
46
|
@access_log = [
|
|
35
47
|
[$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
|
|
36
48
|
[$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
|
|
37
49
|
]
|
|
38
|
-
@logger = WEBrick::Log.new($stderr)
|
|
50
|
+
@logger = WEBrick::Log.new(log_target || $stderr)
|
|
39
51
|
else
|
|
40
52
|
@access_log = []
|
|
41
|
-
@logger = WEBrick::Log.new("/dev/null")
|
|
53
|
+
@logger = WEBrick::Log.new(log_target || "/dev/null")
|
|
42
54
|
end
|
|
43
55
|
|
|
44
56
|
@logger.info "Using Basic Authentication via #{@auth}" if @verbose && @auth
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)
|
|
58
|
+
if %w[ALL ANY].include?(@bind)
|
|
59
|
+
@logger.info "Listening on both 0.0.0.0/:: network interfaces"
|
|
60
|
+
@bind = nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
@collector = opts[:collector] || Collector.new(logger: @logger)
|
|
52
64
|
|
|
53
|
-
@server
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
@server =
|
|
66
|
+
WEBrick::HTTPServer.new(
|
|
67
|
+
Port: @port,
|
|
68
|
+
BindAddress: @bind,
|
|
69
|
+
Logger: @logger,
|
|
70
|
+
AccessLog: @access_log,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
@server.mount_proc "/" do |req, res|
|
|
74
|
+
res["Content-Type"] = "text/plain; charset=utf-8"
|
|
75
|
+
if req.path == "/metrics"
|
|
56
76
|
authenticate(req, res) if @auth
|
|
57
77
|
|
|
58
78
|
res.status = 200
|
|
@@ -70,11 +90,14 @@ module PrometheusExporter::Server
|
|
|
70
90
|
else
|
|
71
91
|
res.body = metrics
|
|
72
92
|
end
|
|
73
|
-
elsif req.path ==
|
|
93
|
+
elsif req.path == "/send-metrics"
|
|
74
94
|
handle_metrics(req, res)
|
|
95
|
+
elsif req.path == "/ping"
|
|
96
|
+
res.body = "PONG"
|
|
75
97
|
else
|
|
76
98
|
res.status = 404
|
|
77
|
-
res.body =
|
|
99
|
+
res.body =
|
|
100
|
+
"Not Found! The Prometheus Ruby Exporter only listens on /ping, /metrics and /send-metrics"
|
|
78
101
|
end
|
|
79
102
|
end
|
|
80
103
|
end
|
|
@@ -86,16 +109,11 @@ module PrometheusExporter::Server
|
|
|
86
109
|
@metrics_total.observe
|
|
87
110
|
@collector.process(block)
|
|
88
111
|
rescue => e
|
|
89
|
-
if @verbose
|
|
90
|
-
STDERR.puts
|
|
91
|
-
STDERR.puts e.inspect
|
|
92
|
-
STDERR.puts e.backtrace
|
|
93
|
-
STDERR.puts
|
|
94
|
-
end
|
|
112
|
+
@logger.error "\n\n#{e.inspect}\n#{e.backtrace}\n\n" if @verbose
|
|
95
113
|
@bad_metrics_total.observe
|
|
96
114
|
res.body = "Bad Metrics #{e}"
|
|
97
115
|
res.status = e.respond_to?(:status_code) ? e.status_code : 500
|
|
98
|
-
|
|
116
|
+
break
|
|
99
117
|
end
|
|
100
118
|
end
|
|
101
119
|
|
|
@@ -104,13 +122,14 @@ module PrometheusExporter::Server
|
|
|
104
122
|
end
|
|
105
123
|
|
|
106
124
|
def start
|
|
107
|
-
@runner ||=
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
@runner ||=
|
|
126
|
+
Thread.start do
|
|
127
|
+
begin
|
|
128
|
+
@server.start
|
|
129
|
+
rescue => e
|
|
130
|
+
@logger.error "Failed to start prometheus collector web on port #{@port}: #{e}"
|
|
131
|
+
end
|
|
112
132
|
end
|
|
113
|
-
end
|
|
114
133
|
end
|
|
115
134
|
|
|
116
135
|
def stop
|
|
@@ -120,12 +139,10 @@ module PrometheusExporter::Server
|
|
|
120
139
|
def metrics
|
|
121
140
|
metric_text = nil
|
|
122
141
|
begin
|
|
123
|
-
Timeout
|
|
124
|
-
metric_text = @collector.prometheus_metrics_text
|
|
125
|
-
end
|
|
142
|
+
Timeout.timeout(@timeout) { metric_text = @collector.prometheus_metrics_text }
|
|
126
143
|
rescue Timeout::Error
|
|
127
144
|
# we timed out ... bummer
|
|
128
|
-
|
|
145
|
+
@logger.error "Generating Prometheus metrics text timed out"
|
|
129
146
|
end
|
|
130
147
|
|
|
131
148
|
metrics = []
|
|
@@ -133,14 +150,10 @@ module PrometheusExporter::Server
|
|
|
133
150
|
metrics << add_gauge(
|
|
134
151
|
"collector_working",
|
|
135
152
|
"Is the master process collector able to collect metrics",
|
|
136
|
-
metric_text && metric_text.length > 0 ? 1 : 0
|
|
153
|
+
metric_text && metric_text.length > 0 ? 1 : 0,
|
|
137
154
|
)
|
|
138
155
|
|
|
139
|
-
metrics << add_gauge(
|
|
140
|
-
"collector_rss",
|
|
141
|
-
"total memory used by collector process",
|
|
142
|
-
get_rss
|
|
143
|
-
)
|
|
156
|
+
metrics << add_gauge("collector_rss", "total memory used by collector process", get_rss)
|
|
144
157
|
|
|
145
158
|
metrics << @metrics_total
|
|
146
159
|
metrics << @sessions_total
|
|
@@ -153,9 +166,18 @@ module PrometheusExporter::Server
|
|
|
153
166
|
end
|
|
154
167
|
|
|
155
168
|
def get_rss
|
|
156
|
-
@pagesize ||=
|
|
169
|
+
@pagesize ||=
|
|
170
|
+
begin
|
|
171
|
+
`getconf PAGESIZE`.to_i
|
|
172
|
+
rescue StandardError
|
|
173
|
+
4096
|
|
174
|
+
end
|
|
157
175
|
@pid ||= Process.pid
|
|
158
|
-
|
|
176
|
+
begin
|
|
177
|
+
File.read("/proc/#{@pid}/statm").split(" ")[1].to_i * @pagesize
|
|
178
|
+
rescue StandardError
|
|
179
|
+
0
|
|
180
|
+
end
|
|
159
181
|
end
|
|
160
182
|
|
|
161
183
|
def add_gauge(name, help, value)
|
|
@@ -166,10 +188,10 @@ module PrometheusExporter::Server
|
|
|
166
188
|
|
|
167
189
|
def authenticate(req, res)
|
|
168
190
|
htpasswd = WEBrick::HTTPAuth::Htpasswd.new(@auth)
|
|
169
|
-
basic_auth =
|
|
191
|
+
basic_auth =
|
|
192
|
+
WEBrick::HTTPAuth::BasicAuth.new({ Realm: @realm, UserDB: htpasswd, Logger: @logger })
|
|
170
193
|
|
|
171
194
|
basic_auth.authenticate(req, res)
|
|
172
195
|
end
|
|
173
|
-
|
|
174
196
|
end
|
|
175
197
|
end
|
|
@@ -6,6 +6,8 @@ require_relative "server/web_collector"
|
|
|
6
6
|
require_relative "server/process_collector"
|
|
7
7
|
require_relative "server/sidekiq_collector"
|
|
8
8
|
require_relative "server/sidekiq_queue_collector"
|
|
9
|
+
require_relative "server/sidekiq_process_collector"
|
|
10
|
+
require_relative "server/sidekiq_stats_collector"
|
|
9
11
|
require_relative "server/delayed_job_collector"
|
|
10
12
|
require_relative "server/collector_base"
|
|
11
13
|
require_relative "server/collector"
|
|
@@ -16,3 +18,5 @@ require_relative "server/hutch_collector"
|
|
|
16
18
|
require_relative "server/unicorn_collector"
|
|
17
19
|
require_relative "server/active_record_collector"
|
|
18
20
|
require_relative "server/shoryuken_collector"
|
|
21
|
+
require_relative "server/resque_collector"
|
|
22
|
+
require_relative "server/good_job_collector"
|
data/lib/prometheus_exporter.rb
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "prometheus_exporter/version"
|
|
4
4
|
require "json"
|
|
5
|
-
require "thread"
|
|
6
5
|
|
|
7
6
|
module PrometheusExporter
|
|
8
7
|
# per: https://github.com/prometheus/prometheus/wiki/Default-port-allocations
|
|
9
8
|
DEFAULT_PORT = 9394
|
|
10
|
-
DEFAULT_BIND_ADDRESS =
|
|
11
|
-
DEFAULT_PREFIX =
|
|
9
|
+
DEFAULT_BIND_ADDRESS = "localhost"
|
|
10
|
+
DEFAULT_PREFIX = "ruby_"
|
|
12
11
|
DEFAULT_LABEL = {}
|
|
13
12
|
DEFAULT_TIMEOUT = 2
|
|
14
|
-
DEFAULT_REALM =
|
|
13
|
+
DEFAULT_REALM = "Prometheus Exporter"
|
|
15
14
|
|
|
16
15
|
class OjCompat
|
|
17
16
|
def self.parse(obj)
|
|
18
17
|
Oj.compat_load(obj)
|
|
19
18
|
end
|
|
19
|
+
|
|
20
20
|
def self.dump(obj)
|
|
21
21
|
Oj.dump(obj, mode: :compat)
|
|
22
22
|
end
|
|
@@ -25,7 +25,7 @@ module PrometheusExporter
|
|
|
25
25
|
def self.hostname
|
|
26
26
|
@hostname ||=
|
|
27
27
|
begin
|
|
28
|
-
require
|
|
28
|
+
require "socket"
|
|
29
29
|
Socket.gethostname
|
|
30
30
|
rescue => e
|
|
31
31
|
STDERR.puts "Unable to lookup hostname #{e}"
|
|
@@ -45,13 +45,12 @@ module PrometheusExporter
|
|
|
45
45
|
def self.has_oj?
|
|
46
46
|
(
|
|
47
47
|
@@has_oj ||=
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
) == :
|
|
48
|
+
begin
|
|
49
|
+
require "oj"
|
|
50
|
+
:T
|
|
51
|
+
rescue LoadError
|
|
52
|
+
:F
|
|
53
|
+
end
|
|
54
|
+
) == :T
|
|
55
55
|
end
|
|
56
|
-
|
|
57
56
|
end
|