Download the PHP package alexpon92/php2elk-metrics without Composer
On this page you can find all versions of the php package alexpon92/php2elk-metrics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexpon92/php2elk-metrics
More information about alexpon92/php2elk-metrics
Files in alexpon92/php2elk-metrics
Package php2elk-metrics
Short Description Package to transfer application and monitoring metrics to ELK
License MIT
Informations about the package php2elk-metrics
PHP2ELK Metrics Package
- Overview
- Installation
- Configuration
- Usage
- Index and default mappings creation
- Check mappings
- Non Laravel users
Overview
This package helps to transfer application metrics to elasticsearch to some indices with prepared mappings for metrics fields. Using Kibana on top of elastic gives you an opportunity to create informative dashboards or trigger some monitoring events. You can use it with Laravel applications or with other frameworks. This package is based on official elasticsearch client (https://github.com/elastic/elasticsearch-php).
Installation
To install through composer, run the following command from terminal:
Configuration
Register the main package provider in your applications
It gives you an opportunity to publish default config and edit it:
Also, you may publish another provider to register main package services in your service container:
It will place package service provider in your directory.
Usage
- Create your custom metrics package has class, and all of your metrics must extend this base class.
-
Implement necessary methods:
method provides unique metric name.
method helps to serialize metric fields to associative array.
Example of custom metric:
- Add your new metrics to metrics registry
If you have published default package provider with command:
You should edit it and add your new metric in register method:
- Add metric mappings in elasticsearch for your index, for instance in kibana dev console:
IMPORTANT! If you will not add mapping for new metrics and produce metrics from your application, your new fields will be converted to strings by elastics and you can't use it in aggregations etc., only for concrete search. Only reindex may help in this situation.
- Now you can produce it in your application
After publish, document in elastic will have next structure:
-
Asynch Metrics producing Package has default listener to produce metric in asynch mode to prevent any additional delays. To use it, you should register in your in attribute
- Bulk metrics producing
Create Index and default mappings
Package has artisan command to prepare an index for your metrics:
- to specify connection name from your config (or default connection)
- index name (or default index from config if not passed)
- flag to add default package metrics
Package has some default metrics and collectors:
-
Dead rows collector for PostgreSQL This collector estimates number of dead rows in concrete database and produce Also you can use artisan command to launch collection of this metric it in crontab
-
Failed queue jobs collector This collector estimates number of failed jobs and produce Also you can use artisan command to launch collection of this metric it in crontab
- Latency metric This metric helps to estimate latency of some actions in your application.
Check mappings
To check metrics mappings in elasticsearch package has command
It helps you not to corrupt your index and to check new metrics mappings in elasticsearch before deploy of new version.
Non Laravel users
WIP