承接 intouch/laravel-newrelic 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

intouch/laravel-newrelic

Composer 安装命令:

composer require intouch/laravel-newrelic

包简介

Laravel 5 NewRelic Integration

README 文档

README

Laravel Version Package Tag Supported
5.x.x 2.2.x yes
5.2.x 2.1.x yes
5.1.x 2.0.x yes
5.0.x 2.0.x no

see below for Laravel 4.x support

Installation

See the table above for package version information, and change the version below accordingly.

Using composer, run:

composer require intouch/laravel-newrelic:"~2.0"

Or add intouch/laravel-newrelic to your composer requirements:

"require": {
    "intouch/laravel-newrelic": "~2.0"
}

... and then run composer install

Once the package is installed, open your config/app.php configuration file and locate the providers key. Add the following line to the end:

Intouch\LaravelNewrelic\NewrelicServiceProvider::class,

Optionally, locate the aliases key and add the following line:

'Newrelic' => Intouch\LaravelNewrelic\Facades\Newrelic::class,

Finally, publish the default configuration (it will end up in config/newrelic.php):

php artisan vendor:publish --provider="Intouch\LaravelNewrelic\NewrelicServiceProvider"

Configuration

Once the configuration from the package if published, see config/newrelic.php for configuration options and descriptions.

Transaction Names

Naming is done by replacing tokens in a name_provider string with formatted output collected from the application. The newrelic.name_provider config parameter holds this string - note that non-token string parts are left as-is.

Token Description Example
{controller} Controller / Action name App\Http\Controllers\MyController@action
{method} HTTP Verb GET, POST
{route} Route Name if named, otherwise {controller} auth.login
{path} Registered route path /users/{id?}
{uri} Request URI path /users/12345

The default newrelic.name_provider string is '{uri} {route}'.

Eloquent Model Observers

There are two observer classes for monitoring your Eloquent models, the NewrelicCountingObserver and the NewrelicTimingObserver. As their names suggest, one counts the number of times observable model events happen and the other gathers their timings (in milliseconds). These recorded metrics will show up in your NewRelic Custom Metrics.

The NewrelicCountingObserver can be used for any observable model events, including your custom events. The NewrelicTimingObserver currently only supports the built-in Eloquent observable events (see Model Events in the Laravel documentation).

Using the observers is simple - wherever you choose to register your model observers, simply add:

User::observe(new \Intouch\LaravelNewrelic\Observers\NewrelicTimingObserver() );
User::observe(new \Intouch\LaravelNewrelic\Observers\NewrelicCountingObserver() );

... assuming you want to observe the User model.

Both observers take two optional parameters to their constructors: $name and $care. $name is the name you want to give to your custom metric, and if unset will default to the class name of the model object it is observing. If you want to change the $care array without changing the naming, simply pass null as the first constructor argument.

$care is an array of event names you want to care about. This differs slightly between the Counting and Timing observers. For the Counting observer, any event can be counted independently. For the Timing observer, it uses the difference in time between saving and saved to submit the metric, so only the after-operation events can be observed: created, saved, updated, deleted, restored. This is also why custom observable events are not supported for the Timing observer (yet ... working on it, we're happy to take PRs).

Per NewRelic's "best practice" suggestions, all metric names are prefaced with 'Custom/'. The Counting observer also adds 'Counts/' to the name, while the Timing observer adds 'Timing/' to the name. Both observers append the event name to the end of the metric name. Take as an example, using the Counting observer on the User model monitoring the created event - the name would be: Custom/Counts/App/User/created (where App/User is the namespaced class name of the observed model with slashes reversed for NewRelic metric paths, or will be whatever you set in $name if supplied).

It is safe to run these observers in integration tests or interactive test environments as long as newrelic.throw_if_not_installed is set to false. Then if the NewRelic PHP Agent is not installed in that environment, the custom metrics will simply not be recorded. If the NewRelic PHP Agent is installed in that environment, the metrics will be recorded.

The default events both observers care about are: created, saved, updated, deleted, restored.

NOTE: To use the observers, the Newrelic Facade must be loaded in your application configuration, not just the Service Provider.

NOTE: NewRelic restricts the total number of custom metrics you can have to 2000, and recommends less than 1000.

Example Custom Metrics Dashboard

dashboard

Basic Use

This package includes a Facade to the Intouch/Newrelic class.
Any of its methods may be accessed as any other Facade is accessed, for example:

App::after( function() {
    Newrelic::setAppName( 'MyApp' );
} );

... would set the NewRelic App Name to 'MyApp'

Laravel 4.x Support

Laravel Version Package Tag Supported
4.2.x 1.1.5 no
4.1.x 1.1.5 no
4.0.x 1.0.4 no
*we will review PRs for unsupported versions, but we don't use those versions in production ourselves so we aren't
testing / working on that*

Issues

Before opening an issues for data not reporting in the format you have configured, please check your NewRelic PHP Agent logs and please see: https://discuss.newrelic.com/t/php-agent-4-19-0-disabled-3rd-party-service-provider-incorrectly/1666

If that hasn't cleared things up, please open an issue here or send us a PR.

intouch/laravel-newrelic 适用场景与选型建议

intouch/laravel-newrelic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.15M 次下载、GitHub Stars 达 173, 最近一次更新时间为 2013 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「newrelic」 「new relic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 intouch/laravel-newrelic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 intouch/laravel-newrelic 我们能提供哪些服务?
定制开发 / 二次开发

基于 intouch/laravel-newrelic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.15M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 180
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 173
  • Watchers: 13
  • Forks: 44
  • 开发语言: PHP

其他信息

  • 授权协议: Apache
  • 更新时间: 2013-04-22