Download the PHP package stechstudio/laravel-metrics without Composer

On this page you can find all versions of the php package stechstudio/laravel-metrics. 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-metrics

Laravel Metrics

Latest Version on Packagist Total Downloads

This package makes it incredibly easy to ship app metrics to backends such as PostHog, InfluxDB or CloudWatch.

There are two major components: a facade that lets you create metrics on your own, and an event listener to automatically send metrics for Laravel events.

Installation

You know the drill...

Backend configuration

PostHog

  1. Install the PostHog PHP client: composer require posthog/posthog-php

  2. Add the following to your .env file:

InfluxDB v1.7 and under

  1. Install the InfluxDB PHP client: composer require influxdb/influxdb-php

  2. Add the following to your .env file:

InfluxDB V1.8 and above

  1. Install the InfluxDB PHP client: composer require influxdata/influxdb-client-php

  2. Add the following to your .env file:

  3. In order to use UDP with InfluxDB V1.8+ you must follow extra setup steps

Add the following to your .env file:

CloudWatch

  1. Install the AWS PHP SDK: composer require aws/aws-sdk-php.

  2. Add the following to your .env file:

Prometheus

  1. Install the Prometheus PHP client: composer require promphp/prometheus_client_php
  2. Configuring the backend to use Prometheus, makes sense only if you have an endpoint to expose them. Its purpose is only to format the registered metrics in a way that Prometheus can scrape them.

NullDriver (for development)

If you need to disable metrics just set the backend to null:

This null driver will simply discard any metrics.

Sending an individual metric

You can create metric by using the facade like this:

The only required attribute is the name, everything else is optional.

Driver mapping

This is how we are mapping metric attributes in our backends.

Metric attribute PostHog InfluxDB CloudWatch Prometheus
name event measurement MetricName name
value properties[value] fields[value] Value value
unit ignored ignored Unit ignored
resolution ignored ignored StorageResolution ignored
tags ignored tags Dimensions keys -> labelNames
values -> labelValues
extra properties fields ignored ignored
timestamp ignored timestamp Timestamp ignored
description ignored ignored ignored help
namespace ignored ignored ignored namespace
type ignored ignored ignored used to register counter or gauge metric

See the CloudWatch docs and InfluxDB docs for more information on their respective data formats. Note we only do minimal validation, you are expected to know what data types and formats your backend supports for a given metric attribute.

Sending metrics from Laravel events

The main motivation for this library was to send metrics automatically when certain events occur in a Laravel application. So this is where things really get fun!

Let's say you have a simple Laravel event called OrderReceived:

The first step is to implement an interface:

This will tell the global event listener to send a metric for this event.

There are two different ways you can then provide the metric details.

1. Use the ProvidesMetric trait

You can also include a trait that helps with building this metric:

In this case, the trait will build a metric called order_received (taken from the class name) with a value of 1.

Customizing event metric data

If you decide to use the trait, you likely will want to customize the event metric data.

You can provide metric data with class attributes:

Or if some of your metric data is dynamic you can use getter methods:

You can provide any of our metric attributes using these class attributes or getter methods.

2. Create the metric yourself

Depending on how much detail you need to provide for your metric, it may be simpler to just build it yourself. In this case you can ditch the trait and simply provide a public createMetric function that returns a new Metric instance:


All versions of laravel-metrics with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
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 stechstudio/laravel-metrics contains the following files

Loading the files please wait ....