buonzz/l4-newrelic-insight

Laravel 用于与 NewRelic Insight 交互的库

v1.0.2 2014-09-14 04:49 UTC

This package is auto-updated.

Last update: 2024-09-06 08:28:44 UTC


README

这是一个 Laravel 库,用于与 NewRelic Insight 交互。它试图以 Laravel 的方式定义简单的事件,并在 NewRelic Insights 仪表板上显示。

特性

  • PSR-0 自动加载兼容结构
  • 使用 PHPUnit 进行单元测试
  • PHPDocumentor

需求

安装

在 composer.json 文件中要求该包

composer require buonzz/l4-newrelic-insight

在 config/app.php 服务提供者中添加服务提供者和外观

Buonzz\NewRelic\Insight\Laravel4\ServiceProviders\InsightServiceProvider

外观

'Insight'            => 'Buonzz\NewRelic\Insight\Laravel4\Facades\Insight',

发布配置文件

php artisan config:publish buonzz/l4-newrelic-insight

编辑 app/config/packages/buonzz/l4-newrelic-insight/config.php 配置文件

  • account_id - 必需的,这应该是您的 NewRelic 账户 ID
  • query_key - 当您需要从 NewRelic 获取数据时必需
  • insert_key - 当您需要插入自定义事件时必需

使用方法

执行查询

$nrql = "SELECT uniquecount(session) FROM PageView";
$nrql .= "WHERE appName='PHP Application' SINCE 1 hour ago COMPARE WITH 1 hour ago";
$result = Insight::query($nrql);

发送自定义事件

$events = array();
$events[] = array('eventType'=> 'Event Name', 'atrribute1'=> 'attribute value 1', 'attribute2'=> 'atrribute value 2');
Insight::insertCustomEvents($events);

您也可以在运行时动态设置配置设置

Insight::setAccountID('<put your account id here>'); // used to associate your account to calls
Insight::setQueryKey('<put your query key here>'); // required to query data
Insight::setInsertKey('<put your insert key here>'); // this is when you need to send custom events

列出过去一小时内的页面访问量

use Buonzz\NewRelic\Insight\Aggregates\PageView;

Route::get('pageviews', function()
{
	$pv = new PageView();
	$pageviews = $pv->all();
	return $pageviews;
});