Class: PgReports::Configuration
- Inherits:
-
Object
- Object
- PgReports::Configuration
- Defined in:
- lib/pg_reports/configuration.rb
Instance Attribute Summary collapse
-
#allow_raw_query_execution ⇒ Object
Security settings.
-
#bloat_threshold_percent ⇒ Object
Table analysis thresholds.
-
#connection_pool ⇒ Object
Connection settings.
-
#dashboard_auth ⇒ Object
Dashboard settings.
-
#dead_rows_threshold ⇒ Object
Tables with more dead rows need vacuum.
-
#expensive_query_threshold_ms ⇒ Object
Total time threshold for expensive queries.
-
#fake_source_data ⇒ Object
Development/testing settings.
-
#grafana_cache_ttl ⇒ Object
Default cache TTL for collected reports, seconds.
-
#grafana_favorites ⇒ Object
Grafana / Prometheus exporter settings.
-
#grafana_metrics_token ⇒ Object
Bearer token required to access /metrics (nil = no auth).
-
#heavy_query_threshold_calls ⇒ Object
Queries with more calls than this are heavy.
-
#inefficient_index_threshold_ratio ⇒ Object
Read/fetch ratio above this is inefficient.
-
#load_external_fonts ⇒ Object
Assets / privacy settings.
-
#max_query_length ⇒ Object
Output settings.
-
#query_monitor_backtrace_filter ⇒ Object
Proc to filter backtrace lines.
-
#query_monitor_log_file ⇒ Object
Query monitoring settings.
-
#query_monitor_max_queries ⇒ Object
Maximum number of queries to keep in buffer.
-
#slow_query_threshold_ms ⇒ Object
Query analysis thresholds.
-
#telegram_bot_token ⇒ Object
Telegram settings.
-
#telegram_chat_id ⇒ Object
Returns the value of attribute telegram_chat_id.
-
#unused_index_threshold_scans ⇒ Object
Index analysis thresholds.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #telegram_configured? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pg_reports/configuration.rb', line 50 def initialize # Telegram @telegram_bot_token = ENV.fetch("PG_REPORTS_TELEGRAM_TOKEN", nil) @telegram_chat_id = ENV.fetch("PG_REPORTS_TELEGRAM_CHAT_ID", nil) # Query thresholds @slow_query_threshold_ms = 100 @heavy_query_threshold_calls = 1000 @expensive_query_threshold_ms = 10_000 # Index thresholds @unused_index_threshold_scans = 50 @inefficient_index_threshold_ratio = 10 # Table thresholds @bloat_threshold_percent = 20 @dead_rows_threshold = 10_000 # Connection @connection_pool = nil # Output @max_query_length = 200 # Dashboard @dashboard_auth = nil # Assets / privacy @load_external_fonts = ActiveModel::Type::Boolean.new.cast(ENV.fetch("PG_REPORTS_LOAD_EXTERNAL_FONTS", false)) # Development/testing @fake_source_data = ENV.fetch("PG_REPORTS_FAKE_SOURCE_DATA", "false") == "true" # Query monitoring @query_monitor_log_file = defined?(Rails) ? Rails.root.join("log", "pg_reports.log") : nil @query_monitor_max_queries = 100 @query_monitor_backtrace_filter = ->(location) { # Exclude gem paths, framework paths !location.path.match?(%r{/(gems|ruby|railties)/}) } # Security @allow_raw_query_execution = ActiveModel::Type::Boolean.new.cast( ENV.fetch("PG_REPORTS_ALLOW_RAW_QUERY_EXECUTION", false) ) # Grafana / Prometheus exporter @grafana_favorites = [] @grafana_metrics_token = ENV.fetch("PG_REPORTS_METRICS_TOKEN", nil) @grafana_cache_ttl = 60 end |
Instance Attribute Details
#allow_raw_query_execution ⇒ Object
Security settings
43 44 45 |
# File 'lib/pg_reports/configuration.rb', line 43 def allow_raw_query_execution @allow_raw_query_execution end |
#bloat_threshold_percent ⇒ Object
Table analysis thresholds
19 20 21 |
# File 'lib/pg_reports/configuration.rb', line 19 def bloat_threshold_percent @bloat_threshold_percent end |
#connection_pool ⇒ Object
Connection settings
23 24 25 |
# File 'lib/pg_reports/configuration.rb', line 23 def connection_pool @connection_pool end |
#dashboard_auth ⇒ Object
Dashboard settings
29 30 31 |
# File 'lib/pg_reports/configuration.rb', line 29 def dashboard_auth @dashboard_auth end |
#dead_rows_threshold ⇒ Object
Tables with more dead rows need vacuum
20 21 22 |
# File 'lib/pg_reports/configuration.rb', line 20 def dead_rows_threshold @dead_rows_threshold end |
#expensive_query_threshold_ms ⇒ Object
Total time threshold for expensive queries
12 13 14 |
# File 'lib/pg_reports/configuration.rb', line 12 def expensive_query_threshold_ms @expensive_query_threshold_ms end |
#fake_source_data ⇒ Object
Development/testing settings
35 36 37 |
# File 'lib/pg_reports/configuration.rb', line 35 def fake_source_data @fake_source_data end |
#grafana_cache_ttl ⇒ Object
Default cache TTL for collected reports, seconds
48 49 50 |
# File 'lib/pg_reports/configuration.rb', line 48 def grafana_cache_ttl @grafana_cache_ttl end |
#grafana_favorites ⇒ Object
Grafana / Prometheus exporter settings
46 47 48 |
# File 'lib/pg_reports/configuration.rb', line 46 def grafana_favorites @grafana_favorites end |
#grafana_metrics_token ⇒ Object
Bearer token required to access /metrics (nil = no auth)
47 48 49 |
# File 'lib/pg_reports/configuration.rb', line 47 def grafana_metrics_token @grafana_metrics_token end |
#heavy_query_threshold_calls ⇒ Object
Queries with more calls than this are heavy
11 12 13 |
# File 'lib/pg_reports/configuration.rb', line 11 def heavy_query_threshold_calls @heavy_query_threshold_calls end |
#inefficient_index_threshold_ratio ⇒ Object
Read/fetch ratio above this is inefficient
16 17 18 |
# File 'lib/pg_reports/configuration.rb', line 16 def inefficient_index_threshold_ratio @inefficient_index_threshold_ratio end |
#load_external_fonts ⇒ Object
Assets / privacy settings
32 33 34 |
# File 'lib/pg_reports/configuration.rb', line 32 def load_external_fonts @load_external_fonts end |
#max_query_length ⇒ Object
Output settings
26 27 28 |
# File 'lib/pg_reports/configuration.rb', line 26 def max_query_length @max_query_length end |
#query_monitor_backtrace_filter ⇒ Object
Proc to filter backtrace lines
40 41 42 |
# File 'lib/pg_reports/configuration.rb', line 40 def query_monitor_backtrace_filter @query_monitor_backtrace_filter end |
#query_monitor_log_file ⇒ Object
Query monitoring settings
38 39 40 |
# File 'lib/pg_reports/configuration.rb', line 38 def query_monitor_log_file @query_monitor_log_file end |
#query_monitor_max_queries ⇒ Object
Maximum number of queries to keep in buffer
39 40 41 |
# File 'lib/pg_reports/configuration.rb', line 39 def query_monitor_max_queries @query_monitor_max_queries end |
#slow_query_threshold_ms ⇒ Object
Query analysis thresholds
10 11 12 |
# File 'lib/pg_reports/configuration.rb', line 10 def slow_query_threshold_ms @slow_query_threshold_ms end |
#telegram_bot_token ⇒ Object
Telegram settings
6 7 8 |
# File 'lib/pg_reports/configuration.rb', line 6 def telegram_bot_token @telegram_bot_token end |
#telegram_chat_id ⇒ Object
Returns the value of attribute telegram_chat_id.
7 8 9 |
# File 'lib/pg_reports/configuration.rb', line 7 def telegram_chat_id @telegram_chat_id end |
#unused_index_threshold_scans ⇒ Object
Index analysis thresholds
15 16 17 |
# File 'lib/pg_reports/configuration.rb', line 15 def unused_index_threshold_scans @unused_index_threshold_scans end |
Instance Method Details
#connection ⇒ Object
102 103 104 |
# File 'lib/pg_reports/configuration.rb', line 102 def connection @connection_pool || ActiveRecord::Base.connection end |
#telegram_configured? ⇒ Boolean
106 107 108 |
# File 'lib/pg_reports/configuration.rb', line 106 def telegram_configured? telegram_bot_token.present? && telegram_chat_id.present? end |