cleaniquecoders/nadi-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cleaniquecoders/nadi-php

最新稳定版本:1.2.2

Composer 安装命令:

composer require cleaniquecoders/nadi-php

包简介

Nadi for PHP

README 文档

README

Build Status

Nadi PHP Client

Nadi is a simple issue tracker for monitoring your application crashes. This package developed for PHP.

Installation

composer require cleaniquecoders/nadi-php

Adding New Metric

You can add a new metric as you see fit to your application / framework.

Do take note, all metrics will be converted to associative array.

In order to create your own metrics, you need to extends the class CleaniqueCoders\Nadi\Metric\Base and implement your metrics details in metrics() method which always return an array. You may need to define as a dot notation in your metric.

However, Nadi will convert to the associative array.

Following is an example for capture Http request for Laravel framework.

<?php

namespace App\Metric;

use CleaniqueCoders\Nadi\Support\Arr;
use CleaniqueCoders\Nadi\Metric\Base;
use Illuminate\Support\Str;

class Http extends Base
{
    public function metrics(): array
    {
        $startTime = defined('LARAVEL_START') ? LARAVEL_START : request()->server('REQUEST_TIME_FLOAT');

        return [
            'http.client.duration' => $startTime ? floor((microtime(true) - $startTime) * 1000) : null,
            'http.scheme' => request()->getScheme(),
            'http.route' => request()->getRequestUri(),
            'http.method' => request()->getMethod(),
            'http.status_code' => http_response_code(),
            'http.query' => request()->getQueryString(),
            'http.uri' => str_replace(request()->root(), '', request()->fullUrl()) ?: '/',
            'http.headers' => Arr::undot(collect(request()->headers->all())
                ->map(function ($header) {
                    return $header[0];
                })
                ->reject(function ($header, $key) {
                    return in_array($key, [
                        'authorization', config('nadi.header-key'), 'nadi-key',
                    ]);
                })
                ->toArray()),
        ];
    }
}

Once you have declared your metric, you can use in your application:

use App\Metrics\Http;
use CleaniqueCoders\Nadi\Metric\Metric;

$metric = new Metric();

$metric->add(new Http());

$metric->toArray();

If you are adding from Laravel framework, you can simply just add in config/nadi.php:

'metrics' => [
    \App\Metrics\Http::class,
];

Class Diagram

nadi-php-uml-diagram.png

统计信息

  • 总下载量: 1.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-27