Class: CloudCostTracker::Billing::AWS::Elasticache::ClusterBillingPolicy

Inherits:
ResourceBillingPolicy show all
Defined in:
lib/cloud_cost_tracker/billing/elasticache/clusters.rb

Overview

The default billing policy for Amazon Elasticache Clusters

Constant Summary collapse

CENTS_PER_HOUR =

The YAML pricing data is read from config/billing

YAML.load(File.read File.join(
CONSTANTS_DIR, 'elasticache-aws.yml'))

Constants included from CloudCostTracker

VERSION

Instance Method Summary collapse

Methods inherited from ResourceBillingPolicy

#initialize, #setup, #write_billing_record_for

Methods included from CloudCostTracker

account_coding_class, connect_to_database, create_billing_agents, create_coding_agents, env, read_accounts

Constructor Details

This class inherits a constructor from CloudCostTracker::Billing::ResourceBillingPolicy

Instance Method Details

#billing_typeObject



11
# File 'lib/cloud_cost_tracker/billing/elasticache/clusters.rb', line 11

def billing_type ; "Elasticache Cluster runtime" end

#get_cost_for_duration(cluster, duration) ⇒ Object

Returns the storage cost for a given Elasticache Cluster over some duration (in seconds)



15
16
17
18
19
20
21
# File 'lib/cloud_cost_tracker/billing/elasticache/clusters.rb', line 15

def get_cost_for_duration(cluster, duration)
  #@log.warn "Calculating cost for #{cluster.tracker_description}"
  return 0.0 if cluster.status =~ /(stopped|terminated)/
  hourly_cost = cluster.num_nodes *
    CENTS_PER_HOUR[region(cluster)][cluster.node_type]
  (hourly_cost * duration) / SECONDS_PER_HOUR
end

#region(cluster) ⇒ Object

Chops the availability zone letter from the availability zone and returns it as a string. e.g., “us-east-XXXXX” => “us-east”



25
26
27
# File 'lib/cloud_cost_tracker/billing/elasticache/clusters.rb', line 25

def region(cluster)
  cluster.zone.split('-')[0..1].join('-')
end