定制 scoutapp/scout-apm-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

scoutapp/scout-apm-php

Composer 安装命令:

composer require scoutapp/scout-apm-php

包简介

Scout Application Performance Monitoring Agent - https://scoutapm.com

README 文档

README

Build Latest Stable Version Total Downloads License

Email us at support@ScoutAPM.com to get on the beta invite list!

Monitor the performance of PHP apps with Scout's PHP APM Agent.

Detailed performance metrics and transaction traces are collected once the agent is installed and configured.

Requirements

PHP Versions: 7.2+

Quick Start

This package is the base library for the various framework-specific packages.

Laravel, Lumen, Symfony support

To install the ScoutAPM Agent for a specific framework, use the specific package instead.

Using the base library directly

use Psr\Log\LoggerInterface;
use Scoutapm\Agent;
use Scoutapm\Config;
use Scoutapm\Config\ConfigKey;

// It is assumed you are using a PSR Logger
/** @var LoggerInterface $psrLoggerImplementation */

$agent = Agent::fromConfig(
    Config::fromArray([
        ConfigKey::APPLICATION_NAME => 'Your application name',
        ConfigKey::APPLICATION_KEY => 'your scout key',
        ConfigKey::MONITORING_ENABLED => true,
    ]),
    $psrLoggerImplementation
);
// If the core agent is not already running, this will download and run it (from /tmp by default)
$agent->connect();

// Use $agent to record `webTransaction`, `backgroundTransaction`, `instrument` or `tagRequest` as necessary

// Nothing is sent to Scout until you call this - so call this at the end of your request
$agent->send();

Default log level

By default, the library is very noisy in logging by design - this is to help us figure out what is going wrong if you need assistance. If you are confident everything is working, and you can see data in your Scout dashboard, then you can increase the minimum log level by adding the following configuration to set the "minimum" log level (which only applies to Scout's logging):

use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Scoutapm\Agent;
use Scoutapm\Config;
use Scoutapm\Config\ConfigKey;

/** @var LoggerInterface $psrLoggerImplementation */

$agent = Agent::fromConfig(
    Config::fromArray([
        ConfigKey::APPLICATION_NAME => 'Your application name',
        ConfigKey::APPLICATION_KEY => 'your scout key',
        ConfigKey::MONITORING_ENABLED => true,
        ConfigKey::LOG_LEVEL => LogLevel::ERROR, // <-- add this configuration to reduce logging verbosity
    ]),
    $psrLoggerImplementation
);

Monitoring of PHP internal functions

You can enable additional monitoring of internal PHP function executions to measure time taken there. To do so, you need to install and enable the scoutapm PHP extension from PECL, for example:

$ sudo pecl install scoutapm

You may need to add zend_extension=scoutapm.so into your php.ini to enable the extension.

With the extension enabled, specific IO-bound functions in PHP are monitored, for example file_get_contents, file_put_contents, PDO->exec and so on.

Alternatively, you can install from source.

Enable caching for Scout

Due to PHP's stateless and "shared-nothing" architecture, the Scout library performs some checks (such as sending some metadata about the running system) on every request. These can be eliminated by giving Scout a PSR-16 (Simple Cache) implementation when creating the agent:

use Doctrine\Common\Cache\RedisCache;
use Psr\Log\LoggerInterface;
use Roave\DoctrineSimpleCache\SimpleCacheAdapter;
use Scoutapm\Agent;
use Scoutapm\Config;
use Scoutapm\Config\ConfigKey;

/** @var LoggerInterface $psrLoggerImplementation */
$yourPsrSimpleCacheImplementation = new SimpleCacheAdapter(new RedisCache());

$agent = Agent::fromConfig(
    Config::fromArray([
        ConfigKey::APPLICATION_NAME => 'Your application name',
        ConfigKey::APPLICATION_KEY => 'your scout key',
        ConfigKey::MONITORING_ENABLED => true,
    ]),
    $psrLoggerImplementation,
    $yourPsrSimpleCacheImplementation
);

Using the PSR-15 Middleware provided

Since scoutapp/scout-apm-php release version 8.1.0, a PSR-15 compatible middleware is included out the box, which may be used in a PSR-15 middleware-compatible framework, such as Slim or Mezzio. For example, in Slim framework:

// Assumes $app is defined, e.g. an instance of `\Slim\App`
$app->add(\Scoutapm\Middleware\ScoutApmMiddleware::class);

You will very likely need to define \Scoutapm\Middleware\ScoutApmMiddleware::class in your container. For example, if your container is Laminas ServiceManager, you could define a factory like:

// Assumes $serviceManager is defined, e.g. an instance of `\Laminas\ServiceManager\ServiceManager`
$serviceManager->setFactory(
    \Scoutapm\Middleware\ScoutApmMiddleware::class,
    static function (\Psr\Container\ContainerInterface $container) {
        $logger = $container->get(LoggerInterface::class);

        $agent = Agent::fromConfig(
            Config::fromArray([
                // any additional array configuration
            ]),
            $logger
        );

        return new ScoutApmMiddleware($agent, $logger);
    }
);

Documentation

For full installation and troubleshooting documentation, visit our help site.

Support

Please contact us at support@ScoutAPM.com or create an issue in this repo.

scoutapp/scout-apm-php 适用场景与选型建议

scoutapp/scout-apm-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 890.33k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2019 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 scoutapp/scout-apm-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 890.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 41
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-06