npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastly-costs

v0.9.1

Published

Calculate Fastly billing costs per service

Downloads

9

Readme

fastly-costs

The Fastly cost calculator for each service in your account.

Motivation

Fastly's billing provides the total costs for the customer account. However, we often would like to know how is specific service billed. This package provides individual service costs as the following:

  • bandwidth: response bandwidth per Gigabytes
  • requests: received requests per 10K
  • computeRequests: Fastly Compute received requests per 1M
  • computeDurations: Fastly Compute cost by CPU GB-second durations

Especially, Fastly Compute pricing is difficult to calculate so this package supports to calculation easily.

Disclaimer

This tool calculates the serice costs properly for a single service, but you may find a cost difference if you're using Origin-Shielding or Service Chaining due to a request will be passed to multiple origins or service.

Usage

Install via npm registry. We have bin command so we recommend to install as global:

npm install -g fastly-costs

Then you can use fastly-costs command on your CLI:

Usage: fastly-costs [options] [filename]

Calculate Fastly billing costs per service

Arguments:
  filename                Price configuration file (default: "./prices.toml")

Options:
  -V, --version           output the version number
  -s, --start <fromDate>  Start date of billing - YYYY-MM-DD format
  -e, --end <toDate>      End date of billing - YYYY-MM-DD format
  --json                  Output cost data as JSON
  -h, --help              display help for command

See the following sections to run successfully.

API Token

Note that before running this command, you need to set FASTLY_API_TOKEN environment variable that Fastly's API Token. The token is enough to have global:read permission due to this package only calls read-related APIs.

Pricing Configuration

Occasionally you have a specific contract with Fastly - volume discounts - so you can configure the pricing rate for each Fastly region. To configure the pricing rate, you need to create prices.toml in your environment and pass to the command:

fastly-cost /path/to/prices.toml

The price.toml format must be the following:

[region]
bandwidth = (number: bandwidth price rate per unit (GB))
requests = (number: requests price rate per unit (10K))
computeRequests = (number: compute request price rate per unit (1M))
computeDurations = (number: compute duration price rate per unit (GB-Sec))

If you have a gradual volume discount, you should specify as:

[region]
bandwidth = [
  { threshold = 5000, price = 0.1 },
  { threshold = 10000, price = 0.08 },
  { threshold = -1, price = 0.05 },
]

In the above case, the bandwidth in usa region will be calculated as:

  1. Until 5,000 units (5,000 GB = 5TB), price rate is 0.1 doller
  2. Until 10,000 units (10,000 GB = 10TB), price rate is 0.08 doller
  3. Over the 10,000 units, price rate is 0.05 (-1 means unlimited, over the unit)

See prive.toml example in this repository.

You MUST specify all regions price rates that Fastly bills for:

  • asia
  • europe
  • anzac
  • asia_india
  • asia_southkorea
  • africa_std
  • southamerica_std
  • usa

That's all, you are ready to run the fastly-costs command :+1: the command displays:

CleanShot 2024-02-18 at 22 00 54@2x

If you want to change the calculated range, you can specify -s (start) and -e (end) options, for example:

fastly-costs -s 2024-01-01 -e 2024-02-01 /path/to/prices.toml

Also you want to get billing data as JSON (for the finops thing), provide --json option.

Contribution

  • Fork this repository
  • Customize / Fix problem
  • Send PR :-)
  • Or feel free to create issues for us. We'll look into it

Author

Yoshiaki Sugimoto [email protected]

License

MIT