cloudwatch.rb 951 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. require 'fog'
  3. require 'neoinfra/cloudwatch'
  4. # NeoInfra Account information
  5. module NeoInfra
  6. # Provide informations about the accounts available
  7. class Cloudwatch
  8. def get_bucket_size(key, secret, region, bucket)
  9. conf = {
  10. aws_access_key_id: key,
  11. aws_secret_access_key: secret,
  12. region: region
  13. }
  14. cwstats = Fog::AWS::CloudWatch.new(conf)
  15. cwstats.get_metric_statistics({
  16. 'Statistics' => ['Maximum'],
  17. 'StartTime' => DateTime.now-7,
  18. 'EndTime' => DateTime.now,
  19. 'Period' => 3600,
  20. 'MetricName' => 'BucketSizeBytes',
  21. 'Namespace' => "AWS/S3",
  22. 'Dimensions' => [
  23. {'Name' => 'BucketName','Value' => bucket},
  24. {'Name' => 'StorageType','Value' => 'StandardStorage'}]
  25. }).data[:body]['GetMetricStatisticsResult']['Datapoints'].last['Maximum']
  26. end
  27. end
  28. end