Module: PgHero::Methods::System
- Included in:
- Database
- Defined in:
- lib/pghero/methods/system.rb
Instance Method Summary collapse
- #connection_stats(**options) ⇒ Object
- #cpu_usage(**options) ⇒ Object
- #free_space_stats(**options) ⇒ Object
- #rds_stats(metric_name, duration: nil, period: nil, offset: nil, series: false) ⇒ Object
- #read_iops_stats(**options) ⇒ Object
- #replication_lag_stats(**options) ⇒ Object
- #system_stats_enabled? ⇒ Boolean
- #system_stats_provider ⇒ Object
- #write_iops_stats(**options) ⇒ Object
Instance Method Details
#connection_stats(**options) ⇒ Object
20 21 22 |
# File 'lib/pghero/methods/system.rb', line 20 def connection_stats(**) system_stats(:connections, **) end |
#cpu_usage(**options) ⇒ Object
16 17 18 |
# File 'lib/pghero/methods/system.rb', line 16 def cpu_usage(**) system_stats(:cpu, **) end |
#free_space_stats(**options) ⇒ Object
36 37 38 |
# File 'lib/pghero/methods/system.rb', line 36 def free_space_stats(**) system_stats(:free_space, **) end |
#rds_stats(metric_name, duration: nil, period: nil, offset: nil, series: false) ⇒ Object
40 41 42 43 44 45 46 47 48 49 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 |
# File 'lib/pghero/methods/system.rb', line 40 def rds_stats(metric_name, duration: nil, period: nil, offset: nil, series: false) if system_stats_enabled? = {region: aws_region} if aws_access_key_id [:access_key_id] = aws_access_key_id [:secret_access_key] = aws_secret_access_key end client = Aws::CloudWatch::Client.new() duration = (duration || 1.hour).to_i period = (period || 1.minute).to_i offset = (offset || 0).to_i end_time = Time.at(((Time.now - offset).to_f / period).ceil * period) start_time = end_time - duration resp = client.get_metric_statistics( namespace: "AWS/RDS", metric_name: metric_name, dimensions: [{name: "DBInstanceIdentifier", value: aws_db_instance_identifier}], start_time: start_time.iso8601, end_time: end_time.iso8601, period: period, statistics: ["Average"] ) data = {} resp[:datapoints].sort_by { |d| d[:timestamp] }.each do |d| data[d[:timestamp]] = d[:average] end add_missing_data(data, start_time, end_time, period) if series data else raise NotEnabled, "System stats not enabled" end end |
#read_iops_stats(**options) ⇒ Object
28 29 30 |
# File 'lib/pghero/methods/system.rb', line 28 def read_iops_stats(**) system_stats(:read_iops, **) end |
#replication_lag_stats(**options) ⇒ Object
24 25 26 |
# File 'lib/pghero/methods/system.rb', line 24 def replication_lag_stats(**) system_stats(:replication_lag, **) end |
#system_stats_enabled? ⇒ Boolean
4 5 6 |
# File 'lib/pghero/methods/system.rb', line 4 def system_stats_enabled? !system_stats_provider.nil? end |
#system_stats_provider ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/pghero/methods/system.rb', line 8 def system_stats_provider if aws_db_instance_identifier :aws elsif gcp_database_id :gcp end end |
#write_iops_stats(**options) ⇒ Object
32 33 34 |
# File 'lib/pghero/methods/system.rb', line 32 def write_iops_stats(**) system_stats(:write_iops, **) end |