Download the PHP package kbeaud11/laravel-cloud-tracker without Composer

On this page you can find all versions of the php package kbeaud11/laravel-cloud-tracker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cloud-tracker

Laravel Cloud Tracker

Track usage-based infrastructure costs per model in Laravel Cloud environments. Built for observability — not billing.

Laravel Cloud Tracker gives you per-entity, per-feature cost visibility by wrapping expensive operations in a fluent API that measures execution time, calculates estimated cost across multiple infrastructure dimensions, and stores both granular events and aggregated monthly rollups.

Why?

Laravel Cloud bills by usage: compute time, database CPU, cache operations, bandwidth, and more. When you run a multi-tenant SaaS, you need to understand which tenants consume which resources and how much it costs.

This package answers questions like:

It does not enforce billing, integrate with Stripe, or render UI. It's the observability layer that makes those things possible.

Requirements

Installation

Publish Configuration

Publish & Run Migrations

This creates three tables:

Table Purpose
model_tracking_policies Per-model tracking configuration (mode, feature lists, multiplier)
model_usage_events Granular event log for every tracked operation
model_usage_rollups Monthly aggregates per model + feature for fast querying

Configuration

After publishing, the config lives at config/cloud-tracker.php.

Master Switch & Environments

Tracking is disabled by default in local development. The callback always executes — only timing, cost calculation, and DB writes are skipped.

Laravel Cloud Plan

Stored for reference and future quota features. Does not affect per-unit rates (those are determined by instance selection).

Supported values: starter, growth, business, enterprise.

Cost Dimensions

Every billable Laravel Cloud resource is represented as a cost dimension. Rates are pre-populated from Laravel Cloud's published pricing (US East region).

Compute (Time-Based)

Select your instance size via environment variable:

Available instances:

Instance Monthly Per Second
flex-1c-256m $4/mo $0.00000165/s
flex-2c-512m $8/mo $0.00000331/s
flex-4c-2g $16/mo $0.00000661/s
pro-1c-1g $20/mo $0.00000827/s
pro-2c-4g $40/mo $0.00001650/s
pro-4c-8g $80/mo $0.00003310/s

Queue Workers (Time-Based)

Queue workers use the same instance pricing as compute but are configured independently:

Serverless Postgres (Time-Based)

Billed at $0.106/hour per vCPU:

Cache / Valkey (Flat Monthly)

Flat monthly rate amortized over estimated operations:

Tier Monthly
250m $6/mo
1g $20/mo
2g $40/mo
5g $80/mo
10g $140/mo
25g $200/mo
50g $272/mo

Adjust estimated_operations_per_month to match your actual usage for more accurate per-operation cost.

WebSockets / Reverb (Flat Monthly)

Amortized over estimated_messages_per_month (default: 1,000,000).

Bandwidth (Count-Based)

Object Storage (Count-Based)

Event Logging

Set to false to skip writing to model_usage_events and only maintain rollups. Reduces write volume in high-throughput scenarios.

Default Dimension

Applied when no dimension is explicitly chained on a track() call.

Usage

1. Add the Trait to Your Billable Model

This provides three relationships:

2. Track an Operation

The callback's return value is always passed through. Timing, cost calculation, event logging, and rollup upsert happen transparently.

3. Chain Multiple Dimensions

When an operation spans multiple infrastructure resources:

Each dimension calculates cost independently based on its unit type, then all are summed.

For time-based dimensions (compute, postgres, queue), cost is derived from execution time automatically.

For count-based and flat-monthly dimensions (cache, websocket, bandwidth, storage), pass a quantity:

4. Force Tracking (Bypass Policy)

For admin or internal operations that should always be tracked regardless of the model's policy:

force() bypasses the tracking policy but still respects environment restrictions (local stays disabled).

5. Attach Metadata

Store arbitrary context with the event for debugging or reporting:

Metadata is stored as JSON on the model_usage_events row.

Tracking Policies

Every billable model can have a tracking policy that controls which features are tracked and at what cost multiplier. Policies are stored in the model_tracking_policies table (created by the package migration).

Creating a Policy

Or via the trait relationship:

Tracking Modes

Mode Behavior
all Track every feature. This is also the default when no policy row exists.
none Track nothing. The callback still executes, but no timing or DB writes occur.
allowlist Only track features listed in tracking_features.
denylist Track everything except features listed in tracking_features.

Usage Multiplier

The usage_multiplier column scales all cost calculations for a model:

Policy Resolution

Policy is evaluated before timing starts. When tracking is disabled for a model+feature:

Policies are cached in memory for the duration of the request to avoid redundant queries.

Querying Usage Data

Via Relationships

Via Models Directly

Extending the Package

Both the policy resolver and cost calculator are bound to contracts in the service container. You can swap in your own implementations.

Custom Policy Resolver

Register in your AppServiceProvider:

Custom Cost Calculator

Register in your AppServiceProvider:

How It Works

Execution Flow

Cost Calculation

Each dimension type calculates cost differently:

Unit Type Formula Examples
time execution_time_ms ÷ 1000 × per_second_rate compute, postgres, queue
count quantity × per_unit_rate bandwidth, storage
flat_monthly quantity × (monthly_rate ÷ estimated_ops_per_month) cache, websocket

The total cost across all dimensions is then multiplied by the model's usage_multiplier.

Rollup Aggregation

Rollups use an atomic database upsert keyed by (billable_type, billable_id, feature, period_start). On conflict, total_execution_ms, total_cost, and event_count are incremented atomically — no read-then-write race conditions.

Compatible with MySQL, PostgreSQL, and SQLite.

Testing

Running Package Tests

Tests run against an in-memory SQLite database with no external dependencies.

Test Coverage

Suite Tests Covers
Feature/TrackingPolicyTest 8 All policy modes, multiplier, caching, trait relationships
Feature/CloudCostTrackingTest 18 Full tracking lifecycle, force bypass, dimension chaining, environment/config disabling, timing accuracy, metadata, event logging toggle
Unit/CostCalculationTest 11 All dimension unit types, multiplier scaling, multi-dimension summation, edge cases, unknown dimension errors

Testing in Your Application

The package respects the environments config. Add 'testing' to track during tests, or leave it out to skip tracking entirely in your test suite:

To assert tracking in your application tests:

What This Package Is Not

It is the observability foundation that makes all of those things possible.

License

MIT


All versions of laravel-cloud-tracker with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kbeaud11/laravel-cloud-tracker contains the following files

Loading the files please wait ...