cloudcost - cloudscale.ch Cost Explorer

A CLI-tool which helps you explore costs on cloudscale.ch.

Resources are fetched from the API and costs calculated using prices defined in data/pricing.yml.

Please note that costs are always calculated based on the current usage. Your actual bills are based on the effective usage over time and may include additional service fees, i.e. for data transfer or discounts.

Installation

Install the gem:

gem install cloudcost

Configure API-Auth

cloudcost does support the same auth configuration options as cloudscale-cli.

You can manage multiple profiles using cloudscale.ini files (see here for instructions).

Otherwise you can export a CLOUDSCALE_API_TOKEN in your environment:

export CLOUDSCALE_API_TOKEN=HELPIMTRAPPEDINATOKENGENERATOR

or you can directly pass a token as a argument to the command: --api-token HELPIMTRAPPEDINATOKENGENERATOR

Usage

Help

Display help:

cloudcost help

Describe the server command:

cloudcost help server

Servers

Detailed List

List all servers from the given environment:

cloudcost servers

Summary

Only show summarized usage:

cloudcost servers --summary

Group and summarize by tag

By using the --group-by option, you can summarize usage by tag:

cloudcost servers --group-by budget-group

Influx Line Protocol output

The CLI also supports output in Influxdb Line Protocol format when using the --group-by option:

cloudcost servers --group-by budget-group --output influx

The output can directly ba pipped to the influxdb CLI:

cloudcost servers --group-by budget-group --profile prod | \
influx write --bucket my-bucket --org my-org --token my-super-secret-auth-token

Example Flux-Query for loading data from InfluxDB:

influx query --org my-org --token my-super-secret-auth-token \
'from(bucket:"my-bucket")
  |> range(start: -1d)
  |> filter(fn: (r) =>
    r._measurement == "cloudscaleServerCosts" and
    r._field == "cost_per_day") and
    r.profile == "prod" and 
    r.group == "my-budget-group"'

CSV Output

Output in CSV format instead of a table:

cloudcost servers --output csv

Filter by name

Filter by servers by regex on name:

# only show servers which names include a k8s or rancher:
cloudcost servers --name "k8s|rancher"

# exclude different name patterns
cloudcost servers --name "^[^ocp|^k8s|^rancher].*"

Filter by tag

Filter servers by tag key:

cloudcost servers --tag service

Filter servers by tag value:

cloudcost servers --tag service=ocp4

Server Tags

Show tags

Display a list of servers and show theire tags:

cloudcost server-tags

Note thats the same filter options as with the servers command apply.

Show servers with missing tag

Only show servers which do NOT have a tag-key named "budget-group":

cloudcost server-tags --missing-tag budget-group

Note that this option can also be combined with set-tags or any other option.

Set tags

cloudcost server-tags --name ldap --set-tags owner=sys budget-group=base-infrastructure

Remove tags

cloudcost server-tags --name ldap --remove-tags owner budget-group

Volumes

List all volumes:

cloudcost volumes

Only list volumes of type bulk

cloudcost volumes --type bulk

List volumes which are not attached to a server:

cloudcost volumes --no-attached

Filter volumes by names:

cloudcost volumes --name "pvc"

Output as InfluxDB Line Protocol:

cloudcost volumes --output influx --profile prod --no-attached

NOTE: The Line Protocol output includes a tag state which is either "attached", "unattached" or "all".