定制 yproximite/influxdb-preset-bundle 二次开发

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

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

yproximite/influxdb-preset-bundle

Composer 安装命令:

composer require yproximite/influxdb-preset-bundle

包简介

InfluxDbPresetBundle: send metrics to InfluxDB server based on Events

README 文档

README

CI (master) PHP Version

InfluxDbPresetBundle: send metrics to InfluxDB server based on Events

Since it relies on the great official influxdb-php library client (via the Symfony bundle) you can configure the latter to benefit from:

  • Send multiple metrics at once (batch sending)
  • Udp Events (sends the metrics using UDP)
  • Http Events (sends the metrics to the InfluxDB API over HTTP)

Both methods (Udp/Http) can also be deferred, meaning you can send the metrics only when kernel.terminate event is fired in order not to slow your application. You can read more on the documentation of influxdb-bundle

profiler_influx

This bundle is inspired from StatsdBundle

Installation

Require yproximite/influxdb-preset-bundle to your composer.json file:

$ composer require yproximite/influxdb-preset-bundle

Register the bundle in app/AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Yproximite\Bundle\InfluxDbPresetBundle\YproximiteInfluxDbPresetBundle(),
        new Yproximite\InfluxDbBundle\InfluxDbBundle(),
    );
}

Also, be sure that you followed the configuration procedure for influxdb-bundle since it uses it to take the pre-configured service to communicate with the InfluxDB server.

Configuration

Here is the configuration reference:

# app/config/config.yml
yproximite_influx_db_preset:
    default_profile_name: default # by default it's "default"
    profiles:
        default:
            connections:
                default:
                    protocol: udp
                    deferred: true
            presets:
                app.user.created:
                    measurement: users
                    tags: { type: member, action: created, free: yes, foo: bar }
                    fields: { extra_value: true }
                api.company.created:
                    measurement: api
                    tags: { action: created, object: company }
                api.company.deleted:
                    measurement: api
                    tags: { action: deleted, object: company }
                app.memory_usage:
                    measurement: app_memory_usage
                    tags: { metric_type: memory }
                app.exception:
                    measurement: app
                    tags: { metric_type: exception, code: "<value>" }
                app.page_views:
                    measurement: app
                    tags: { metric_type: page_views }
        other:
            connections:
                default:
                    protocol: http
            presets:
                app.response_time:
                    measurement: app
                    tags: { metric_type: response_time }
                app.order.requested:
                    measurement: orders
                    tags: { action: requested, delivery: false }
                    fields: { extra_value: true }
    extensions:
        memory:
            enabled: true
            preset_name: app.memory_usage
        response_time:
            enabled: true
            preset_name: app.response_time
            profile_name: other # by default it's "default"
        exception:
            enabled: true
            preset_name: app.exception
        request_count:
            enabled: true
            preset_name: app.page_views

# influx_db:
#     default_connection:   ~
#     connections:
#         default:
#             host:                 influxdb.example.com
#             database:             my_db
#             udp:                  true
#             udp_port:             4444
#             http_port:            8086
#         other:
#             host:                 important.example.com
#             database:             my_db
#             udp:                  false
#             udp_port:             4444
#             http_port:            8086

Usage

Sending

through events:

use Yproximite\Bundle\InfluxDbPresetBundle\Event\InfluxDbEvent;

// Symfony\Component\EventDispatcher\EventDispatcherInterface
$eventDispatcher = $this->get('event_dispatcher');

// Preset from default profile
$eventDispatcher->dispatch('app.user.created', new InfluxDbEvent(1));

// Advanced event parameters
$event = new InfluxDbEvent(
    $value = 1, // will be converted to float
    string $profileName = 'other',
    ?\DateTimeInterface $dateTime = new \DateTime()
);

$eventDispatcher->dispatch('app.order.requested', $event);

using the client:

// Yproximite\Bundle\InfluxDbPresetBundle\Client\ClientInterface
$client = $this->get('yproximite.influx_db_preset.client.client');

$client->sendPoint(
    string $profileName = 'other',
    string $presetName = 'app.user.created',
    float $value = 0.5,
    ?\DateTimeInterface $dateTime = new \DateTime()
);

Listening for events

you can listen each client request through ClientRequestEvent:

use Yproximite\Bundle\InfluxDbPresetBundle\Event\ClientRequestEvent;

final class MyAppListener
{
    public function onClientRequest(ClientRequestEvent $event)
    {
        dump(
            $event->getProfileName(),
            $event->getPresetName(),
            $event->getValue(),
            $event->getDateTime()
        );
    }
}

do not forget to add the following code into services.yml:

services:
    app.event_listener.my_app_listener:
        class: AppBundle\EventListener\MyAppListener
        tags:
            - { name: kernel.event_listener, event: yproximite.bundle.influx_db_preset.client_request, method: onClientRequest }

You can enable extensions that will automatically (see configuration example) send the metrics for the memory usage, how much time the Request/Response cycle last, the status code of errors and the quantity of page views.

统计信息

  • 总下载量: 20.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固