lib/pghero/methods/system.rb in pghero-1.7.0 vs lib/pghero/methods/system.rb in pghero-2.0.0

- old
+ new

@@ -1,29 +1,33 @@ module PgHero module Methods module System - def cpu_usage(options = {}) + def cpu_usage(**options) rds_stats("CPUUtilization", options) end - def connection_stats(options = {}) + def connection_stats(**options) rds_stats("DatabaseConnections", options) end - def replication_lag_stats(options = {}) + def replication_lag_stats(**options) rds_stats("ReplicaLag", options) end - def read_iops_stats(options = {}) + def read_iops_stats(**options) rds_stats("ReadIOPS", options) end - def write_iops_stats(options = {}) + def write_iops_stats(**options) rds_stats("WriteIOPS", options) end - def rds_stats(metric_name, options = {}) + def free_space_stats(**options) + rds_stats("FreeStorageSpace", options) + end + + def rds_stats(metric_name, duration: nil, period: nil, offset: nil) if system_stats_enabled? aws_options = {region: region} if access_key_id aws_options[:access_key_id] = access_key_id aws_options[:secret_access_key] = secret_access_key @@ -34,13 +38,13 @@ Aws::CloudWatch::Client.new(aws_options) else AWS::CloudWatch.new(aws_options).client end - duration = (options[:duration] || 1.hour).to_i - period = (options[:period] || 1.minute).to_i - offset = (options[:offset] || 0).to_i + duration = (duration || 1.hour).to_i + period = (period || 1.minute).to_i + offset = (offset || 0).to_i end_time = (Time.now - offset) # ceil period end_time = Time.at((end_time.to_f / period).ceil * period) @@ -57,10 +61,10 @@ resp[:datapoints].sort_by { |d| d[:timestamp] }.each do |d| data[d[:timestamp]] = d[:average] end data else - {} + raise NotEnabled, "System stats not enabled" end end def system_stats_enabled? !!((defined?(Aws) || defined?(AWS)) && db_instance_identifier)