PHPackages                             vanquynguyen/laravel-system-statistics - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. vanquynguyen/laravel-system-statistics

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vanquynguyen/laravel-system-statistics
======================================

A very simple system statistics for project

161PHP

Since Oct 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/vanquynguyen/laravel-system-statistics)[ Packagist](https://packagist.org/packages/vanquynguyen/laravel-system-statistics)[ RSS](/packages/vanquynguyen-laravel-system-statistics/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-system-statistics
=========================

[](#laravel-system-statistics)

Chúng ta không thể phủ nhận rằng việc thu thập data system statistics là cực kỳ thiết yếu, chính vì vậy hãy làm việc này để giúp sản phẩm, hệ thống của bạn được tốt hơn. Nhận thấy điều này là hữu ích nên mình có dành một chút thời gian và có viết ra một package tạm đặt tên là: `laravel system statistics`

#### Giới thiệu về package laravel system statistics

[](#giới-thiệu-về-package-laravel-system-statistics)

Mình xây dựng package `vanquynguyen/laravel-system-statistics` giúp chúng ta có thể dễ dàng thu thập các dữ liệu hệ thống theo các key metrics của riêng mình. Tất cả dữ liệu sẽ được lưu trong bảng `system_statistics` để tiện cho việc sử dụng sau này.

Download tại: [Laravel System statistics package](https://packagist.org/packages/vanquynguyen/laravel-system-statistics)

#### Cài đặt package

[](#cài-đặt-package)

Bạn có thể cài đặt package thông qua composer:

```
composer require vanquynguyen/laravel-system-statistics
```

Sau khi cài đặt xong bạn cần chạy command để tạo migrations tự động:

```
php artisan vendor:publish --provider="Vanquy\SystemStatistics\SystemStatisticServiceProvider" --tag="migrations"
```

Và đương nhiên rồi sau khi migrations file đã được tạo bạn cần phải chạy `migrate` để thêm bảng vào database

```
php artisan migrate
```

Đừng quên chạy lệnh để tạo file config nữa

```
php artisan vendor:publish --provider="Vanquy\SystemStatistics\SystemStatisticServiceProvider" --tag="config"
```

Package có viết sẵn cho bạn một command để thu thập dữ liệu, có sẵn rồi thì ngần ngại gì mà không dùng nhỉ =))

```
php artisan vendor:publish --provider="Vanquy\SystemStatistics\SystemStatisticServiceProvider" --tag="commands"
```

##### Hướng dẫn sử dụng

[](#hướng-dẫn-sử-dụng)

- Models

Bạn có thể sử dụng model theo namespace `Vanquy\SystemStatistics\Models\SystemStatistic` .

```
  use Vanquy\SystemStatistics\Models\SystemStatistic;

  SystemStatistic::all();
```

Hoặc nếu bạn muốn tạo trong App\\Models để dễ dàng mở rộng thì có thể tạo và extends Model đã được tạo sẵn trong package

```
  namespace App\Models;

  use Vanquy\SystemStatistics\Models\SystemStatistic;

  class StatisticModel extends SystemStatistic
  {
    //
  }
```

- Có thể sử dụng một số hàm sẵn có:

Hiện tại package có viết sẵn 2 class: `Collector` và `Repository`. Class `Collector` là những đoạn code giúp ta thu thập dữ liệu cho các key metrics, `Repository` cung cấp một số hàm lấy data theo điều kiện. Với namespace là: `Vanquy\SystemStatistics\Components\Collector` và `Vanquy\SystemStatistics\Components\Repository`

- Commands

**Thu thập data theo ngày**

```
  namespace App\Console\Commands;

  use Vanquy\SystemStatistics\Components\Collector;

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  public function handle(Collector $statsCollector)
  {
      $dateArg = $this->option('date');
      $date = $dateArg !== null ? Carbon::createFromFormat('Y-m-d', $dateArg) : Carbon::now()->subDay(1);

      $this->deleteOldStatistics($date);
      $queries = [];
      $statistics = $statsCollector->forDate($queries, $date);

      $data = $statistics->map(function ($item, $key) use ($date) {
          return [
              'type' => $key,
              'data' => $item,
              'date' => $date,
          ];
      });

      SystemStatistic::insert($data->toArray());
  }
```

Bạn cần thêm các query ứng với key metrics mà bạn cần và thêm vào biến $queries, Ví dụ:

```
  namespace App\Console\Commands;

  use Vanquy\SystemStatistics\Components\Collector;

  public function handle(Collector $statsCollector)
  {
    $queries = [
      [
          'type' => 'total_users',
          'query' => $statsCollector->countTotalSystem('users'),
      ],
    ];
    ...
  }
```

**Send daily report**

```
  namespace App\Console\Commands;

  use Vanquy\SystemStatistics\Components\Repository

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  public function handle(Repository $statsRepository)
  {
      $currentDate = Carbon::now()->subDay(1);
      $lastDate = Carbon::now()->subDay(2);
      $types = [];

      $dataStatistics = $statsRepository->getStatisticsForReport($types, $currentDate, $lastDate);

      return $dataStatistics;
  }
```

Bạn cần thêm các type vào biến $types để lấy ra dữ liệu của các type mà bạn cần, ví dụ:

```
$type = ['total_users', 'total_new_users'];
.....
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32449788?v=4)[vanquynguyen](/maintainers/vanquynguyen)[@vanquynguyen](https://github.com/vanquynguyen)

---

Top Contributors

[![vanquynguyen](https://avatars.githubusercontent.com/u/32449788?v=4)](https://github.com/vanquynguyen "vanquynguyen (4 commits)")[![quynv-1217](https://avatars.githubusercontent.com/u/45259239?v=4)](https://github.com/quynv-1217 "quynv-1217 (1 commits)")

### Embed Badge

![Health badge](/badges/vanquynguyen-laravel-system-statistics/health.svg)

```
[![Health](https://phpackages.com/badges/vanquynguyen-laravel-system-statistics/health.svg)](https://phpackages.com/packages/vanquynguyen-laravel-system-statistics)
```

###  Alternatives

[destinylab/swetest

The simple wrapper of swisseph library's swetest

221.6k](/packages/destinylab-swetest)

PHPackages © 2026

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