prometheus_exporter 0.5.3 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +5 -0
  5. data/Appraisals +10 -0
  6. data/CHANGELOG +28 -0
  7. data/README.md +138 -16
  8. data/bin/prometheus_exporter +29 -2
  9. data/gemfiles/.bundle/config +2 -0
  10. data/gemfiles/ar_60.gemfile +5 -0
  11. data/gemfiles/ar_61.gemfile +7 -0
  12. data/lib/prometheus_exporter.rb +1 -0
  13. data/lib/prometheus_exporter/client.rb +39 -8
  14. data/lib/prometheus_exporter/instrumentation.rb +1 -0
  15. data/lib/prometheus_exporter/instrumentation/active_record.rb +19 -12
  16. data/lib/prometheus_exporter/instrumentation/delayed_job.rb +3 -2
  17. data/lib/prometheus_exporter/instrumentation/method_profiler.rb +2 -1
  18. data/lib/prometheus_exporter/instrumentation/process.rb +1 -1
  19. data/lib/prometheus_exporter/instrumentation/puma.rb +17 -5
  20. data/lib/prometheus_exporter/instrumentation/resque.rb +40 -0
  21. data/lib/prometheus_exporter/instrumentation/sidekiq.rb +44 -3
  22. data/lib/prometheus_exporter/instrumentation/sidekiq_queue.rb +13 -2
  23. data/lib/prometheus_exporter/instrumentation/unicorn.rb +1 -1
  24. data/lib/prometheus_exporter/middleware.rb +40 -17
  25. data/lib/prometheus_exporter/server.rb +1 -0
  26. data/lib/prometheus_exporter/server/active_record_collector.rb +2 -1
  27. data/lib/prometheus_exporter/server/collector.rb +1 -0
  28. data/lib/prometheus_exporter/server/delayed_job_collector.rb +9 -8
  29. data/lib/prometheus_exporter/server/puma_collector.rb +9 -1
  30. data/lib/prometheus_exporter/server/resque_collector.rb +54 -0
  31. data/lib/prometheus_exporter/server/runner.rb +13 -3
  32. data/lib/prometheus_exporter/server/sidekiq_collector.rb +2 -2
  33. data/lib/prometheus_exporter/server/web_collector.rb +2 -5
  34. data/lib/prometheus_exporter/server/web_server.rb +33 -23
  35. data/lib/prometheus_exporter/version.rb +1 -1
  36. data/prometheus_exporter.gemspec +7 -3
  37. metadata +59 -11
  38. data/.travis.yml +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a284b77cbd17e80457e94520d18976dc3dd6fb8c238d8a90cda6513e291f01ad
4
- data.tar.gz: 4464419fc9c67d387edd9d6d5bdfac1411d0864d29c0cd3a6f10d2f02b3d7e24
3
+ metadata.gz: 47861f365c3db51e840d0c62e30120518dfc64fe208cc639ae6653903d14c578
4
+ data.tar.gz: 8e67b542b68012b0bd2cb64122eb2ba987a18eed1397449cab4363eea009ba44
5
5
  SHA512:
6
- metadata.gz: 84c2e2af95a8839cd9deecca9fbc26bacff590ae5cb3677862f1eb1d476401114406130cc78d2248cec0380e70c1b74b306e1265b3343bbac9c09d8400e692a3
7
- data.tar.gz: 41898546588ef7eafa772252ef5ed1a8c222e4009e64ccec35d463217336597a94f1c844f3e2174e030c19a7c1b90d1028e5729cc393cf797654362f5d66b7f2
6
+ metadata.gz: 1f4ff589012b8f28f81ee3b63f7535c1eb138c232826da36f1b621dc6381398e7fa515aca6b6413423e965630d23b47ad9b505801d418e3c9a625c7d7a0c7030
7
+ data.tar.gz: d457d6d2c60c11960b6b241d5f2e0864994f11f808624845b9f28a42968dc3b9da07214321631d9f1644b2fdcad4b5ad443c843c53416ad6326afae68bd4d879
@@ -0,0 +1,42 @@
1
+ name: Test Exporter
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '0 0 * * 0' # weekly
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ name: Ruby ${{ matrix.ruby }}
13
+ strategy:
14
+ matrix:
15
+ ruby: ["3.0","2.7", "2.6"]
16
+ steps:
17
+ - uses: actions/checkout@master
18
+ with:
19
+ fetch-depth: 1
20
+ - uses: actions/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - uses: actions/cache@v2
24
+ with:
25
+ path: vendor/bundle
26
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gems-v2-${{ hashFiles('**/Gemfile.lock') }}
27
+ restore-keys: |
28
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-v2-
29
+ - name: Setup gems
30
+ run: |
31
+ gem install bundler
32
+ # for Ruby <= 2.6 , details https://github.com/rubygems/rubygems/issues/3284
33
+ gem update --system 3.0.8 && gem update --system
34
+ bundle config path vendor/bundle
35
+ bundle install --jobs 4
36
+ bundle exec appraisal install
37
+ - name: Rubocop
38
+ run: bundle exec rubocop
39
+ - name: install gems
40
+ run: bundle exec appraisal bundle
41
+ - name: Run tests
42
+ run: bundle exec appraisal rake
data/.gitignore CHANGED
@@ -7,5 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+ /gemfiles/*.gemfile.lock
11
+
10
12
 
11
13
  .rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
data/.rubocop.yml CHANGED
@@ -1,2 +1,7 @@
1
1
  inherit_gem:
2
2
  rubocop-discourse: default.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - 'gemfiles/**/*'
7
+ - 'vendor/**/*'
data/Appraisals ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "ar-60" do
4
+ # we are using this version as default in gemspec
5
+ # gem "activerecord", "~> 6.0.0"
6
+ end
7
+
8
+ appraise "ar-61" do
9
+ gem "activerecord", "~> 6.1.1"
10
+ end
data/CHANGELOG CHANGED
@@ -1,3 +1,31 @@
1
+ 0.8.1 - 04-08-2021
2
+
3
+ - FEATURE: swap from hardcoded STDERR to logger pattern (see README for details)
4
+
5
+ 0.8.0 - 05-07-2021
6
+
7
+ - FIX: handle ThreadError more gracefully in cases where process shuts down
8
+ - FEATURE: add job_name and queue_name labels to delayed job metrics
9
+ - FEATURE: always scope puma metrics on hostname in collector
10
+ - FEATURE: add customizable labels option to puma collector
11
+ - FEATURE: support for Resque
12
+ - DEV: Remove support for EOL ruby 2.5
13
+ - FIX: Add source location to MethodProfiler patches
14
+ - FEATURE: Improve Active Record instrumentation
15
+ - FEATURE: Support HTTP_X_AMZN_TRACE_ID when supplied
16
+
17
+ 0.7.0 - 29-12-2020
18
+
19
+ - Dev: Removed support from EOL rubies, only 2.5, 2.6, 2.7 and 3.0 are supported now.
20
+ - Dev: Better support for Ruby 3.0, explicitly depending on webrick
21
+ - Dev: Rails 6.1 instrumentation support
22
+ - FEATURE: clean pattern for overriding middleware labels was introduced (in README)
23
+ - Fix: Better support for forking
24
+
25
+ 0.6.0 - 17-11-2020
26
+
27
+ - FEATURE: add support for basic-auth in the prometheus_exporter web server
28
+
1
29
  0.5.3 - 29-07-2020
2
30
 
3
31
  - FEATURE: added #remove to all metric types so users can remove specific labels if needed
data/README.md CHANGED
@@ -19,6 +19,7 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
19
19
  * [Hutch metrics](#hutch-message-processing-tracer)
20
20
  * [Puma metrics](#puma-metrics)
21
21
  * [Unicorn metrics](#unicorn-process-metrics)
22
+ * [Resque metrics](#resque-metrics)
22
23
  * [Custom type collectors](#custom-type-collectors)
23
24
  * [Multi process mode with custom collector](#multi-process-mode-with-custom-collector)
24
25
  * [GraphQL support](#graphql-support)
@@ -27,13 +28,14 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
27
28
  * [Client default host](#client-default-host)
28
29
  * [Transport concerns](#transport-concerns)
29
30
  * [JSON generation and parsing](#json-generation-and-parsing)
31
+ * [Logging](#logging)
30
32
  * [Contributing](#contributing)
31
33
  * [License](#license)
32
34
  * [Code of Conduct](#code-of-conduct)
33
35
 
34
36
  ## Requirements
35
37
 
36
- Minimum Ruby of version 2.3.0 is required, Ruby 2.2.0 is EOL as of 2018-03-31
38
+ Minimum Ruby of version 2.5.0 is required, Ruby 2.4.0 is EOL as of 2020-04-05
37
39
 
38
40
  ## Installation
39
41
 
@@ -200,12 +202,53 @@ $ bundle exec prometheus_exporter
200
202
  | Summary | `http_sql_duration_seconds`² | Time spent in HTTP reqs in SQL in seconds |
201
203
  | Summary | `http_queue_duration_seconds`³ | Time spent queueing the request in load balancer in seconds |
202
204
 
203
- All metrics have a `controller` and an `action` label.
204
- `http_requests_total` additionally has a (HTTP response) `status` label.
205
+ All metrics have a `controller` and an `action` label.
206
+ `http_requests_total` additionally has a (HTTP response) `status` label.
205
207
 
206
- ¹) Only available when Redis is used.
207
- ²) Only available when Mysql or PostgreSQL are used.
208
- ³) Only available when [Instrumenting Request Queueing Time](#instrumenting-request-queueing-time) is set up.
208
+ To add your own labels to the default metrics, create a subclass of `PrometheusExporter::Middleware`, override `custom_labels`, and use it in your initializer.
209
+ ```ruby
210
+ class MyMiddleware < PrometheusExporter::Middleware
211
+ def custom_labels(env)
212
+ labels = {}
213
+
214
+ if env['HTTP_X_PLATFORM']
215
+ labels['platform'] = env['HTTP_X_PLATFORM']
216
+ end
217
+
218
+ labels
219
+ end
220
+ end
221
+ ```
222
+
223
+ If you're not using Rails like framework, you can extend `PrometheusExporter::Middleware#default_labels` in a way to add more relevant labels.
224
+ For example you can mimic [prometheus-client](https://github.com/prometheus/client_ruby) labels with code like this:
225
+ ```ruby
226
+ class MyMiddleware < PrometheusExporter::Middleware
227
+ def default_labels(env, result)
228
+ status = (result && result[0]) || -1
229
+ path = [env["SCRIPT_NAME"], env["PATH_INFO"]].join
230
+ {
231
+ path: strip_ids_from_path(path),
232
+ method: env["REQUEST_METHOD"],
233
+ status: status
234
+ }
235
+ end
236
+
237
+ def strip_ids_from_path(path)
238
+ path
239
+ .gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|$)}, '/:uuid\\1')
240
+ .gsub(%r{/\d+(/|$)}, '/:id\\1')
241
+ end
242
+ end
243
+ ```
244
+ That way you won't have all metrics labeled with `controller=other` and `action=other`, but have labels such as
245
+ ```
246
+ ruby_http_duration_seconds{path="/api/v1/teams/:id",method="GET",status="200",quantile="0.99"} 0.009880661998977303
247
+ ```
248
+
249
+ ¹) Only available when Redis is used.
250
+ ²) Only available when Mysql or PostgreSQL are used.
251
+ ³) Only available when [Instrumenting Request Queueing Time](#instrumenting-request-queueing-time) is set up.
209
252
 
210
253
  #### Activerecord Connection Pool Metrics
211
254
 
@@ -365,19 +408,19 @@ Sometimes the Sidekiq server shuts down before it can send metrics, that were ge
365
408
  **PrometheusExporter::Instrumentation::Sidekiq**
366
409
  | Type | Name | Description |
367
410
  | --- | --- | --- |
368
- | Counter | `sidekiq_job_duration_seconds` | Total time spent in sidekiq jobs |
411
+ | Summary | `sidekiq_job_duration_seconds` | Time spent in sidekiq jobs |
369
412
  | Counter | `sidekiq_jobs_total` | Total number of sidekiq jobs executed |
370
413
  | Counter | `sidekiq_restarted_jobs_total` | Total number of sidekiq jobs that we restarted because of a sidekiq shutdown |
371
414
  | Counter | `sidekiq_failed_jobs_total` | Total number of failed sidekiq jobs |
372
415
 
373
- All metrics have a `job_name` label.
416
+ All metrics have a `job_name` label and a `queue` label.
374
417
 
375
418
  **PrometheusExporter::Instrumentation::Sidekiq.death_handler**
376
419
  | Type | Name | Description |
377
420
  | --- | --- | --- |
378
421
  | Counter | `sidekiq_dead_jobs_total` | Total number of dead sidekiq jobs |
379
422
 
380
- This metric also has a `job_name` label.
423
+ This metric has a `job_name` label and a `queue` label.
381
424
 
382
425
  **PrometheusExporter::Instrumentation::SidekiqQueue**
383
426
  | Type | Name | Description |
@@ -387,7 +430,7 @@ This metric also has a `job_name` label.
387
430
 
388
431
  Both metrics will have a `queue` label with the name of the queue.
389
432
 
390
- _See [Metrics collected by Process Instrumentation](#metrics-collected-by-process-instrumentation) for a list of metrics the Process instrumentation will produce._
433
+ _See [Metrics collected by Process Instrumentation](#metrics-collected-by-process-instrumentation) for a list of metrics the Process instrumentation will produce._
391
434
 
392
435
  #### Shoryuken metrics
393
436
 
@@ -411,7 +454,7 @@ end
411
454
  | Counter | `shoryuken_restarted_jobs_total` | Total number of shoryuken jobs that we restarted because of a shoryuken shutdown |
412
455
  | Counter | `shoryuken_failed_jobs_total` | Total number of failed shoryuken jobs |
413
456
 
414
- All metrics have labels for `job_name` and `queue_name`.
457
+ All metrics have labels for `job_name` and `queue_name`.
415
458
 
416
459
  #### Delayed Job plugin
417
460
 
@@ -437,6 +480,8 @@ end
437
480
  | Summary | `delayed_job_duration_seconds_summary` | Summary of the time it takes jobs to execute | `status` |
438
481
  | Summary | `delayed_job_attempts_summary` | Summary of the amount of attempts it takes delayed jobs to succeed | - |
439
482
 
483
+ All metrics have labels for `job_name` and `queue_name`.
484
+
440
485
  #### Hutch Message Processing Tracer
441
486
 
442
487
  Capture [Hutch](https://github.com/gocardless/hutch) metrics (how many jobs ran? how many failed? how long did they take?)
@@ -456,7 +501,7 @@ end
456
501
  | Counter | `hutch_jobs_total` | Total number of hutch jobs executed |
457
502
  | Counter | `hutch_failed_jobs_total` | Total number failed hutch jobs executed |
458
503
 
459
- All metrics have a `job_name` label.
504
+ All metrics have a `job_name` label.
460
505
 
461
506
  #### Instrumenting Request Queueing Time
462
507
 
@@ -464,7 +509,7 @@ Request Queueing is defined as the time it takes for a request to reach your app
464
509
 
465
510
  As this metric starts before `prometheus_exporter` can handle the request, you must add a specific HTTP header as early in your infrastructure as possible (we recommend your load balancer or reverse proxy).
466
511
 
467
- Configure your HTTP server / load balancer to add a header `X-Request-Start: t=<MSEC>` when passing the request upstream. For more information, please consult your software manual.
512
+ The Amazon Application Load Balancer [request tracing header](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html) is natively supported. If you are using another upstream entrypoint, you may configure your HTTP server / load balancer to add a header `X-Request-Start: t=<MSEC>` when passing the request upstream. For more information, please consult your software manual.
468
513
 
469
514
  Hint: we aim to be API-compatible with the big APM solutions, so if you've got requests queueing time configured for them, it should be expected to also work with `prometheus_exporter`.
470
515
 
@@ -494,7 +539,29 @@ end
494
539
  | Gauge | `puma_thread_pool_capacity_total` | Number of puma threads available at current scale |
495
540
  | Gauge | `puma_max_threads_total` | Number of puma threads at available at max scale |
496
541
 
497
- All metrics may have a `phase` label.
542
+ All metrics may have a `phase` label and all custom labels provided with the `labels` option.
543
+
544
+ ### Resque metrics
545
+
546
+ The resque metrics are using the `Resque.info` method, which queries Redis internally. To start monitoring your resque
547
+ installation, you'll need to start the instrumentation:
548
+
549
+ ```ruby
550
+ # e.g. config/initializers/resque.rb
551
+ require 'prometheus_exporter/instrumentation'
552
+ PrometheusExporter::Instrumentation::Resque.start
553
+ ```
554
+
555
+ #### Metrics collected by Resque Instrumentation
556
+
557
+ | Type | Name | Description |
558
+ | --- | --- | --- |
559
+ | Gauge | `processed_jobs_total` | Total number of processed Resque jobs |
560
+ | Gauge | `failed_jobs_total` | Total number of failed Resque jobs |
561
+ | Gauge | `pending_jobs_total` | Total number of pending Resque jobs |
562
+ | Gauge | `queues_total` | Total number of Resque queues |
563
+ | Gauge | `workers_total` | Total number of Resque workers running |
564
+ | Gauge | `working_total` | Total number of Resque workers working |
498
565
 
499
566
  ### Unicorn process metrics
500
567
 
@@ -577,8 +644,8 @@ Then you can collect the metrics you need on demand:
577
644
 
578
645
  ```ruby
579
646
  def metrics
580
- user_count_gague = PrometheusExporter::Metric::Gauge.new('user_count', 'number of users in the app')
581
- user_count_gague.observe User.count
647
+ user_count_gauge = PrometheusExporter::Metric::Gauge.new('user_count', 'number of users in the app')
648
+ user_count_gauge.observe User.count
582
649
  [user_count_gauge]
583
650
  end
584
651
  ```
@@ -692,6 +759,25 @@ ruby_web_requests{hostname="app-server-01"} 1
692
759
  When running the process for `prometheus_exporter` using `bin/prometheus_exporter`, there are several configurations that
693
760
  can be passed in:
694
761
 
762
+ ```
763
+ Usage: prometheus_exporter [options]
764
+ -p, --port INTEGER Port exporter should listen on (default: 9394)
765
+ -b, --bind STRING IP address exporter should listen on (default: localhost)
766
+ -t, --timeout INTEGER Timeout in seconds for metrics endpoint (default: 2)
767
+ --prefix METRIC_PREFIX Prefix to apply to all metrics (default: ruby_)
768
+ --label METRIC_LABEL Label to apply to all metrics (default: {})
769
+ -c, --collector FILE (optional) Custom collector to run
770
+ -a, --type-collector FILE (optional) Custom type collectors to run in main collector
771
+ -v, --verbose
772
+ --auth FILE (optional) enable basic authentication using a htpasswd FILE
773
+ --realm REALM (optional) Use REALM for basic authentication (default: "Prometheus Exporter")
774
+ --unicorn-listen-address ADDRESS
775
+ (optional) Address where unicorn listens on (unix or TCP address)
776
+ --unicorn-master PID_FILE (optional) PID file of unicorn master process to monitor unicorn
777
+ ```
778
+
779
+ #### Example
780
+
695
781
  The following will run the process at
696
782
  - Port `8080` (default `9394`)
697
783
  - Bind to `0.0.0.0` (default `localhost`)
@@ -707,6 +793,29 @@ prometheus_exporter -p 8080 \
707
793
  --prefix 'foo_'
708
794
  ```
709
795
 
796
+ #### Enabling Basic Authentication
797
+
798
+ If you desire authentication on your `/metrics` route, you can enable basic authentication with the `--auth` option.
799
+
800
+ ```
801
+ $ prometheus_exporter --auth my-htpasswd-file
802
+ ```
803
+
804
+ Additionally, the `--realm` option may be used to provide a customized realm for the challenge request.
805
+
806
+ Notes:
807
+
808
+ * You will need to create a `htpasswd` formatted file before hand which contains one or more user:password entries
809
+ * Only the basic `crypt` encryption is currently supported
810
+
811
+ A simple `htpasswd` file can be created with the Apache `htpasswd` utility; e.g:
812
+
813
+ ```
814
+ $ htpasswd -cdb my-htpasswd-file my-user my-unencrypted-password
815
+ ```
816
+
817
+ This will create a file named `my-htpasswd-file` which is suitable for use the `--auth` option.
818
+
710
819
  ### Client default labels
711
820
 
712
821
  You can specify a default label for instrumentation metrics sent by a specific client. For example:
@@ -742,6 +851,19 @@ The `PrometheusExporter::Client` class has the method `#send-json`. This method,
742
851
 
743
852
  When `PrometheusExporter::Server::Collector` parses your JSON, by default it will use the faster Oj deserializer if available. This happens cause it only expects a simple Hash out of the box. You can opt in for the default JSON deserializer with `json_serializer: :json`.
744
853
 
854
+ ## Logging
855
+
856
+ `PrometheusExporter::Client.default` will export to `STDERR`. To change this, you can pass your own logger:
857
+ ```ruby
858
+ PrometheusExporter::Client.new(logger: Rails.logger)
859
+ PrometheusExporter::Client.new(logger: Logger.new(STDOUT))
860
+ ```
861
+
862
+ You can also pass a log level (default is [`Logger::WARN`](https://ruby-doc.org/stdlib-3.0.1/libdoc/logger/rdoc/Logger.html)):
863
+ ```ruby
864
+ PrometheusExporter::Client.new(log_level: Logger::DEBUG)
865
+ ```
866
+
745
867
  ## Contributing
746
868
 
747
869
  Bug reports and pull requests are welcome on GitHub at https://github.com/discourse/prometheus_exporter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -3,12 +3,15 @@
3
3
 
4
4
  require 'optparse'
5
5
  require 'json'
6
+ require 'logger'
6
7
 
7
8
  require_relative "./../lib/prometheus_exporter"
8
9
  require_relative "./../lib/prometheus_exporter/server"
9
10
 
10
11
  def run
11
- options = {}
12
+ options = {
13
+ logger_path: STDERR
14
+ }
12
15
  custom_collector_filename = nil
13
16
  custom_type_collectors_filenames = []
14
17
 
@@ -47,6 +50,12 @@ def run
47
50
  opt.on('-v', '--verbose') do |o|
48
51
  options[:verbose] = true
49
52
  end
53
+ opt.on('--auth FILE', String, "(optional) enable basic authentication using a htpasswd FILE") do |o|
54
+ options[:auth] = o
55
+ end
56
+ opt.on('--realm REALM', String, "(optional) Use REALM for basic authentication (default: \"#{PrometheusExporter::DEFAULT_REALM}\")") do |o|
57
+ options[:realm] = o
58
+ end
50
59
 
51
60
  opt.on('--unicorn-listen-address ADDRESS', String, '(optional) Address where unicorn listens on (unix or TCP address)') do |o|
52
61
  options[:unicorn_listen_address] = o
@@ -55,8 +64,26 @@ def run
55
64
  opt.on('--unicorn-master PID_FILE', String, '(optional) PID file of unicorn master process to monitor unicorn') do |o|
56
65
  options[:unicorn_pid_file] = o
57
66
  end
67
+
68
+ opt.on('--logger-path PATH', String, '(optional) Path to file for logger output. Defaults to STDERR') do |o|
69
+ options[:logger_path] = o
70
+ end
58
71
  end.parse!
59
72
 
73
+ logger = Logger.new(options[:logger_path])
74
+ logger.level = Logger::WARN
75
+
76
+ if options.has_key?(:realm) && !options.has_key?(:auth)
77
+ logger.warn "Providing REALM without AUTH has no effect"
78
+ end
79
+
80
+ if options.has_key?(:auth)
81
+ unless File.exist?(options[:auth]) && File.readable?(options[:auth])
82
+ logger.fatal "The AUTH file either doesn't exist or we don't have access to it"
83
+ exit 1
84
+ end
85
+ end
86
+
60
87
  if custom_collector_filename
61
88
  eval File.read(custom_collector_filename), nil, File.expand_path(custom_collector_filename)
62
89
  found = false
@@ -71,7 +98,7 @@ def run
71
98
  end
72
99
 
73
100
  if !found
74
- STDERR.puts "[Error] Can not find a class inheriting off PrometheusExporter::Server::CollectorBase"
101
+ logger.fatal "Can not find a class inheriting off PrometheusExporter::Server::CollectorBase"
75
102
  exit 1
76
103
  end
77
104
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"