PHPackages                             itsemon245/lamet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. itsemon245/lamet

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

itsemon245/lamet
================

A high-performance Laravel metrics collection package with caching, aggregation, and Grafana integration for production monitoring

v1.0.2(10mo ago)031MITPHP

Since Jun 24Pushed 10mo agoCompare

[ Source](https://github.com/itsemon245/lamet)[ Packagist](https://packagist.org/packages/itsemon245/lamet)[ RSS](/packages/itsemon245-lamet/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

[![Laravel Lamet Banner](https://camo.githubusercontent.com/ba3c2441bf1414aeb3d47a834d485791a69e0112942e45ce1a424c032212dc84/68747470733a2f2f706c616365686f6c642e636f2f31323030783430302f3636376565612f77686974653f746578743d4c414d455426666f6e743d52616c65776179)](https://camo.githubusercontent.com/ba3c2441bf1414aeb3d47a834d485791a69e0112942e45ce1a424c032212dc84/68747470733a2f2f706c616365686f6c642e636f2f31323030783430302f3636376565612f77686974653f746578743d4c414d455426666f6e743d52616c65776179)

 [![Total Downloads](https://camo.githubusercontent.com/0b7a915d5302a2ba42fd960d006cc0724a4225c4e966c40e8f49feca8045d59d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f697473656d6f6e3234352f6c616d65743f7374796c653d666f722d7468652d6261646765266c6162656c3d446f776e6c6f61647326636f6c6f723d363143394138)](https://packagist.org/packages/itsemon245/lamet) [![Latest Stable Version](https://camo.githubusercontent.com/f091f3d51d838e9d5a8b528b814a4479d718aab7c8c4c5216c4d8f102bdcfcf4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f697473656d6f6e3234352f6c616d65743f7374796c653d666f722d7468652d6261646765266c6162656c3d56657273696f6e)](https://packagist.org/packages/itsemon245/lamet) [![License](https://camo.githubusercontent.com/c6c868cd0602037a654883568237dcaf4b77b16a94b09c8020e0d43b4c0a6c66/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f697473656d6f6e3234352f6c616d65743f7374796c653d666f722d7468652d6261646765266c6162656c3d4c6963656e7365)](https://packagist.org/packages/itsemon245/lamet)

Laravel Lamet (Laravel + Metrics)
=================================

[](#laravel-lamet-laravel--metrics)

A simple, high-performance package to record and aggregate metrics in Laravel applications, ready for Grafana dashboards.

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [🚀 Installation](#-installation)
- [✨ Usage](#-usage)
    - [Basic Usage](#basic-usage)
    - [Available Methods](#available-methods)
- [📝 Notes](#-notes)
- [📚 More](#-more)
- [Commands](#commands)
    - [lamet:install](#lametinstall)
    - [lamet:flush](#lametflush)
    - [lamet:clean](#lametclean)
- [Configuration](#configuration)
- [Environment Variables](#environment-variables)
- [Cache System](#cache-system)
    - [Cache Configuration](#cache-configuration-1)
- [Scheduled Tasks](#scheduled-tasks)
- [Grafana Integration](#grafana-integration)
    - [Database as Data Source](#database-as-data-source)
    - [Recommended Dashboard Panels](#recommended-dashboard-panels)
    - [Alerting](#alerting)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

🚀 Installation
--------------

[](#-installation)

1. **Install via Composer:**

    ```
    composer require itsemon245/lamet
    ```
2. **Publish the configuration and migration:**

    ```
    php artisan lamet:install
    ```

    This will publish `config/lamet.php` and the migration to `database/migrations/lamet/`.

    Alternatively, you can publish them separately:

    ```
    php artisan vendor:publish --tag=lamet-config
    php artisan vendor:publish --tag=lamet-migrations
    ```
3. **Configure your database and cache:**

    - Set up your desired database connection in `config/database.php` (e.g., `sqlite`, `mysql`, `pgsql`). *Postgres is recommended*

    ```
     'lamet' => [
          'driver' => env('LAMET_DB_CONNECTION', 'pgsql'),
          'url' => env('LAMET_DATABASE_URL'),
          'host' => env('LAMET_DB_HOST', '127.0.0.1'),
          'port' => env('LAMET_DB_PORT', '5432'),
          'database' => env('LAMET_DB_DATABASE', 'lamet_metrics'),
          'username' => env('LAMET_DB_USERNAME', 'root'),
          'password' => env('LAMET_DB_PASSWORD', ''),
          'charset' => 'utf8',
          'prefix' => '',
          'prefix_indexes' => true,
          'search_path' => env('LAMET_DB_CONNECTION', 'pgsql') === 'pgsql' ? 'public' : null,
          'sslmode' => env('LAMET_DB_CONNECTION', 'pgsql') === 'pgsql' ? 'prefer' : null,
      ],
    ```

    - Create a new cache store or use an existing one from `config/cache.php` (e.g., `redis`).
    - Add and update the .env variables for the new database connection

    ```
    #Database Connection
    LAMET_DB_CONNECTION=pgsql
    LAMET_DB_HOST=127.0.0.1
    LAMET_DB_PORT=5432
    LAMET_DB_DATABASE=lamet_metrics
    LAMET_DB_USERNAME=root
    LAMET_DB_PASSWORD=password

    #Other Config options (these are the defaults)
    LAMET_CACHE_STORE=redis
    LAMET_CACHE_PREFIX=metrics:
    LAMET_CACHE_TTL=3600
    LAMET_CACHE_BATCH_SIZE=1000
    LAMET_LOG=false
    ```

    > \[!NOTE\] &gt; **Quick Setup**: Use the provided `misc/postgres-docker-compose.yml` example to quickly spin up a PostgreSQL container for development and testing.
4. **Run the migration:**

    ```
    php artisan migrate
    ```

    > \[!IMPORTANT\] The 5th step is very important. If you skip this your metrics won't be saved in the database. Also keep in mind that you have to set the frequency lower than the ttl value in `config/lamet.php`
5. **Schedule periodic flushing:**In `app/Console/Kernel.php`:

    ```
    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('lamet:flush')->everyFiveMinutes();
    }
    ```

    > \[!TIP\] Higher frequency means less granularity, not suitable for realtime metrics but lower memory usage Lower frequency means more granularity, suitable for realtime metrics but higher memory usage Keep it between 5-20 minutes in general.

✨ Usage
-------

[](#-usage)

### Basic Usage

[](#basic-usage)

Record a simple metric using the facade:

```
use Itsemon245\Lamet\Facades\Metrics;

// Record an API request
Metrics::increment('api.requests', 1, [
    'endpoint' => '/users',
    'method' => 'GET',
    'status_code' => 200
]);
```

### Available Methods

[](#available-methods)

- **Basic Metrics**: [Counter &amp; Gauge Metrics](docs/basic-metrics.md)
- **Timing**: [Time-based Metrics](docs/timing-metrics.md)
- **Exceptions**: [Exception Tracking](docs/exception-tracking.md)
- **Database**: [Database Query Monitoring](docs/database-monitoring.md)
- **Cache Management**: [Cache Operations](docs/cache-management.md)
- **Data Retrieval**: [Data Retrieval](docs/data-retrieval.md)
- **Cleanup**: [Cleanup Operations](docs/cleanup-operations.md)

Each method supports three usage patterns:

- **Facade**: `Metrics::methodName()`
- **Helper Functions**: `metricsMethodName()`
- **Dependency Injection**: Inject `MetricsManager`

---

For advanced usage and query examples, see:

- [Query Examples](docs/query-examples.md) - Common SQL queries for Grafana
- [Advanced Usage](docs/advance-usage.md) - Advanced metric types and patterns
- [Grafana Queries](docs/grafana-queries.md) - Grafana-specific query examples

📝 Notes
-------

[](#-notes)

- The `tags` column is flexible and can store any key-value pairs.
- The `recorded_at` column is used for time-series queries in Grafana.
- The `type` column defaults to `counter` for all metrics.
- The `unit` column is available for any unit

📚 More
------

[](#-more)

- See the published `config/lamet.php` for all options.
- See the migration for the table structure.
- For advanced usage, see the helper functions and artisan commands provided.

Commands
--------

[](#commands)

### `lamet:install`

[](#lametinstall)

Installs the package by publishing configuration and migration files.

```
php artisan lamet:install
```

Options:

- `--force`: Overwrite existing files

### `lamet:flush`

[](#lametflush)

Flushes cached metrics to the database.

```
php artisan lamet:flush
```

Options:

- `--dry-run`: Run the command without actually doing anything
- `-P|--print`: Print the flush keys
- `--force`: Force flush even if cache is disabled

### `lamet:clean`

[](#lametclean)

Cleans old metrics from the database.

```
php artisan lamet:clean
```

Options:

- `--dry-run`: Run the command without actually doing anything
- `--days=30`: Number of days to keep (default: 30)
- `--force`: Force the operation without confirmation

Configuration
-------------

[](#configuration)

The package configuration is located in `config/lamet.php`. You can customize the following options:

### General Settings

[](#general-settings)

- `enabled`: Enable/disable metrics recording
- `log_metrics`: Log metrics to Laravel's log system
- `default_tags`: Default tags to add to all metrics (environment, app\_name, user fields)

### Database Query Monitoring

[](#database-query-monitoring)

- `db_query.enabled`: Enable/disable auto database query monitoring
- `db_query.metric_name`: Name for database query metrics
- `db_query.tags`: Tags to include with database queries
- `db_query.store_only_slow_query`: Store only slow queries (default: true)
- `db_query.slow_query_name_suffix`: Suffix for slow query metric names (default: '.slow')
- `db_query.slow_query_threshold`: Threshold in milliseconds for slow queries (default: 1500ms)

### Exception Monitoring

[](#exception-monitoring)

- `exception.enabled`: Enable/disable auto exception monitoring
- `exception.metric_name`: Name for exception metrics
- `exception.tags`: Tags to include with exception metrics

### Ignore Configuration

[](#ignore-configuration)

- `ignore.paths`: Array of paths to ignore when recording metrics
- `ignore.exceptions`: Array of exception classes to ignore
- `ignore.db_query.tables`: Array of database tables to ignore when monitoring queries
- `ignore.db_query.sql_patterns`: Array of regex patterns to ignore specific SQL queries

### Cache Configuration

[](#cache-configuration)

- `cache.store`: Cache store to use (default: redis)
- `cache.prefix`: Prefix for cache keys (default: metrics:)
- `cache.ttl`: Time to live for cached metrics (default: 3600 seconds)
- `cache.batch_size`: Number of metrics to insert in one batch (default: 1000)

### Database Settings

[](#database-settings)

- `table`: Database table name for storing metrics
- `connection`: Database connection to use (null to disable database storage)

Environment Variables
---------------------

[](#environment-variables)

You can configure the package using these environment variables:

```
LAMET_ENABLED=true
LAMET_LOG=false
LAMET_TABLE=lamet

# Cache Configuration
LAMET_CACHE_STORE=redis
LAMET_CACHE_PREFIX=lamet:
LAMET_CACHE_TTL=3600
LAMET_CACHE_BATCH_SIZE=1000
```

Cache System
------------

[](#cache-system)

The package includes a caching system that stores metrics in cache first, then periodically flushes them to the database. This provides:

- **Better Performance**: Metrics are stored in fast cache storage
- **Reduced Database Load**: Batch inserts instead of individual records
- **Data Aggregation**: Similar metrics are automatically aggregated
- **Fault Tolerance**: Metrics survive application restarts

### Cache Configuration

[](#cache-configuration-1)

- `LAMET_CACHE_STORE`: Cache store to use (default: redis)
- `LAMET_CACHE_PREFIX`: Prefix for cache keys (default: metrics:)
- `LAMET_CACHE_TTL`: Time to live for cached metrics (default: 3600 seconds)
- `LAMET_CACHE_BATCH_SIZE`: Number of metrics to insert in one batch (default: 1000)

Scheduled Tasks
---------------

[](#scheduled-tasks)

Add these to your `app/Console/Kernel.php` to automatically flush and clean metrics:

```
protected function schedule(Schedule $schedule): void
{
    // Flush metrics every 5 minutes
    $schedule->command('lamet:flush')->everyFiveMinutes();

    // Clean old metrics daily at 2 AM (keep last 90 days)
    // $schedule->command('lamet:clean --days=90 --force')->dailyAt('02:00');
}
```

Grafana Integration
-------------------

[](#grafana-integration)

The package is designed to work seamlessly with Grafana for creating beautiful dashboards and visualizations.

### Database as Data Source

[](#database-as-data-source)

Connect your metrics database to Grafana:

1. **Add Data Source** in Grafana:

    - **PostgreSQL**: Use the PostgreSQL data source
    - **MySQL**: Use the MySQL data source
2. **Connection Settings**:

    ```
    Host: your-database-host
    Database: your-metrics-database
    User: your-database-user
    Password: your-database-password

    ```

### Recommended Dashboard Panels

[](#recommended-dashboard-panels)

1. **Time Series**: Response times, memory usage, CPU usage
2. **Stat**: Current values, totals, averages
3. **Table**: Top endpoints, error rates, recent events
4. **Gauge**: Current system health, utilization

### Alerting

[](#alerting)

Set up Grafana alerts based on your metrics:

```
-- High response time alert
SELECT avg(value) as avg_response_time
FROM lamet
WHERE name = 'api.response_time'
  AND recorded_at >= now() - interval '5 minutes'
HAVING avg(value) > 1000;  -- Alert if > 1 second
```

For more Grafana query examples, see [Grafana Queries](docs/grafana-queries.md).

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance53

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

9

Last Release

325d ago

Major Versions

v0.1.5 → v1.02025-06-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/77df49af7a8f7ee50264b96f33af69a80ca6fe96826db69684fdbdd1dace6034?d=identicon)[itsemon245](/maintainers/itsemon245)

---

Top Contributors

[![itsemon245](https://avatars.githubusercontent.com/u/82655944?v=4)](https://github.com/itsemon245 "itsemon245 (25 commits)")

---

Tags

laravelloggingmonitoringperformancelaravel-packageMetricscachedashboardanalyticsaggregationtelemetryproductionobservabilitytime seriesgrafana

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/itsemon245-lamet/health.svg)

```
[![Health](https://phpackages.com/badges/itsemon245-lamet/health.svg)](https://phpackages.com/packages/itsemon245-lamet)
```

###  Alternatives

[muhammadsadeeq/laravel-activitylog-ui

A beautiful, modern UI for Spatie's Activity Log with advanced filtering, analytics, and real-time features.

17510.1k](/packages/muhammadsadeeq-laravel-activitylog-ui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
