Cloud Financial Officer
Watches multiple cloud computing accounts, records expenses by resource, and exposes a REST API to query the recorded costs.
What is it?
Cloud Financial Officer is an application and library for tracking and reporting on the expenses generated by one or more cloud computing accounts. It monitors all the accounts and computes costs for each cloud computing "Resource", like a server (EC2 instance) or a storage container (S3 bucket). It saves the resulting billing records into a database using ActiveRecord, and generates JSON reports on this data.
The cloud computing Resources can be assigned "billing codes", which are arbitrary pairs of Strings that can be used by an organization for internal billing. Each Resource's billing codes are attached to all its billing records.
By default, a useful set of Resource coding policies is included. For example, any Tags that are assigned to EC2 Resources are automatically converted to billing codes. Billing codes from Security Groups are passed on to the Instances that run within them, and from there to the EBS volumes attached to the Instances. Custom policies can also be written (in Ruby) to assign billing codes based on arbitrary logic.
Why is it?
The principal motivation behind this software is to provide "microbilling" for Amazon Web Services, as explained in the README for the Cloud Cost Tracker.
Though every effort is made to calculate costs accurately, the purpose of CFO is not really to produce an exact number matching the bill from a given service provider. It is more useful in determining the relative breakdown of costs by provider, account, or resource type (which it does automatically), and more useful still in reporting costs for internal billing units, like customer or project. This can be achieved with EC2 tags or custom resource coding logic.
Installation
CFO can be used as a standalone application or as a Rack middleware library.
To install as an application
1) Install project dependencies:
gem install rake bundler
2) Fetch the code:
git clone https://github.com/benton/cloud_financial_officer.git
cd cloud_financial_officer
3) Now edit the Gemfile
to include your desired database driver.
Then bundle everything together.
bundle
To install as a library
1) Install the gem, or add it as a Bundler dependency and bundle
.
gem install cloud_financial_officer
2) Require the middleware from your Rack application, then insert it in the stack:
require 'cloud_financial_officer'
...
config.middleware.use CFO::Service # (Rails application.rb)
# or
use CFO::Service # (Sinatra)
3) Require the database migration tasks in your Rakefile
:
require 'cloud_cost_tracker/tasks'
Initializing the database
1) Create a Rails-style config/database.yml
file (example included).
2) Create the tables. ENV['RACK_ENV']
determines the configuration entry
rake db:migrate:tracker
Usage
CFO consists of two parts:
- A rake task that gathers cost information.
- A web service that exposes a REST API for the billing records.
Both require information about which accounts to track and report on.
This is stored in config/accounts.yml
(see the provided example).
Both also require a config/database.yml
.
The tracking process is run with:
rake track
The service is run with:
rake service
or
rackup
The entry point for the REST API is /api/v1/accounts
(See the API documentation)
Development
Getting started with development
1) Install project dependencies
gem install rake bundler
2) Fetch the project code
git clone https://github.com/benton/cloud_financial_officer.git
cd cloud_financial_officer
3) Bundle up and run the tests
bundle && rake