billing

package
v0.0.0-...-230cbbc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2019 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MinimumTotalCost is also used in notify.MonthToDateReport
	MinimumTotalCost = 10.0
	// MinimumCost is also used in notify.MonthToDateReport
	MinimumCost = 5.0
)

Variables

This section is empty.

Functions

func BucketPricePerMonth

func BucketPricePerMonth(bucket cloud.Bucket) float64

BucketPricePerMonth will return the monthly price in USD for a specified bucket. It will not take any account wide discounts that might have been collected for using a certain amount of storage every month.

func ImageCostPerDay

func ImageCostPerDay(image cloud.Image) float64

ImageCostPerDay returns the daily cost in USD for a certain image

func InstancePricePerHour

func InstancePricePerHour(instance cloud.Instance) float64

InstancePricePerHour will return the hourly price in USD for a specified instance.

func ResourceCostPerDay

func ResourceCostPerDay(resource cloud.Resource) float64

ResourceCostPerDay returns the daily cost of a resource in USD

func SnapshotCostPerDay

func SnapshotCostPerDay(snapshot cloud.Snapshot) float64

SnapshotCostPerDay returns the daily cost in USD for a certain snapshot

func VolumeCostPerDay

func VolumeCostPerDay(volume cloud.Volume) float64

VolumeCostPerDay returns the daily cost in USD for a certain volume

Types

type CostList

type CostList []DetailedCost

CostList respresents a list of Costs

func (CostList) Len

func (l CostList) Len() int

func (CostList) Less

func (l CostList) Less(i, j int) bool

func (CostList) Swap

func (l CostList) Swap(i, j int)

type DetailedCost

type DetailedCost struct {
	Cost        float64
	Description string
}

DetailedCost represents a Cost and Description for a Users expense

type Report

type Report struct {
	CSP   cloud.CSP
	Items []ReportItem
}

Report contains a collection of items, and some metadata about when the items were collected and which dates they span. The report struct also has methods to help work with all the items.

func GenerateReport

func GenerateReport(reporter Reporter) Report

GenerateReport generates a Month-to-date billing report for the current month

func (*Report) FormatReport

func (r *Report) FormatReport(accountToUserMapping map[string]string, sortedByTags bool) string

FormatReport returns a simple version of the Month-to-date billing report. It takes a mapping form account/project ID to employee username in order to more easily distinguish the owner of a cost.

func (*Report) SortedTagsByTotalCost

func (r *Report) SortedTagsByTotalCost() UserList

SortedTagsByTotalCost returns a sorted list of grouped sort tag values, sorted by their total cost.

func (*Report) SortedUsersByTotalCost

func (r *Report) SortedUsersByTotalCost() UserList

SortedUsersByTotalCost returns a sorted list of Users by TotalCost

func (*Report) TotalCost

func (r *Report) TotalCost() float64

TotalCost returns the total cost for all items

type ReportItem

type ReportItem struct {
	Owner       string
	Description string
	Cost        float64
	// contains filtered or unexported fields
}

ReportItem represent a single item in a report. This is usually the cost for a specific service for a certain user in a certain account/project.

type Reporter

type Reporter interface {
	GenerateReport(start time.Time) Report
}

Reporter is a general interface that can be implemented for both AWS and GCP to generate expense reports.

func NewReporterAWS

func NewReporterAWS(billingAccount, bucket, bucketRegion, sortTag string) Reporter

NewReporterAWS will initialize a new Reporter for the AWS cloud. This requires specifying the account which holds the billing information, the bucket where the billing CSVs can be found as well as which region this bucket is in. None of these arguments must be empty.

func NewReporterGCP

func NewReporterGCP(bucket, csvPrefix string) Reporter

NewReporterGCP initializes and returns a new Reporter for the GCP cloud. This requires specifying a bucket where the billing CSVs can be found, as well as the prefix of these CSV files. The prefix will be prepended to the date and .csv suffix (e.g. <YOUR PREFIX>-2018-10-09.csv). None of these argument must be empty.

type User

type User struct {
	Name          string
	TotalCost     float64
	DetailedCosts CostList
}

User represents an User and it's TotalCost plus a CostList of all associated DetailedCosts

type UserList

type UserList []User

UserList respresents a list of Users

func (UserList) Len

func (l UserList) Len() int

func (UserList) Less

func (l UserList) Less(i, j int) bool

func (UserList) Swap

func (l UserList) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL