edisonlabs/metrics
Composer 安装命令:
composer require edisonlabs/metrics
包简介
PHP library for collecting metrics.
README 文档
README
Metrics Collector
Overview
The Metrics Collector is a simple library that provides base classes to easily extend and collect custom metrics.
Usage
This library does not provide any metrics by default. To create new metrics, create a Composer package and then add a dependency to this package:
composer require edisonlabs/metrics
Now create the metrics classes extending edisonlabs/metrics classes.
Example: Number of PHP files.
// src/EdisonLabs/Metric/NumberOfPhpFiles.php namespace EdisonLabs\Metric; use EdisonLabs\Metrics\Metric\AbstractMetricBase; class NumberOfPhpFiles extends AbstractMetricBase { public function getName() { return 'Number of PHP files'; } public function getDescription() { return 'The total number of PHP files'; } public function getMetric() { // Put the logic to calculate the total of PHP files here. // .. // Random example. return rand(10, 50); } }
Configure the autoload in composer.json:
"autoload": { "psr-4": { "EdisonLabs\\Metric\\": "src/EdisonLabs/Metric" } }
Re-create the Composer autoloader:
composer dump-autoload
Collecting metrics
There are two ways to collect the metrics: programmatically and by command-line.
Programmatically
// collector.php use EdisonLabs\Metrics\Collector; $date = strtotime('now'); $config = array(); $collector = new Collector($date, $config); $metrics = $collector->getMetrics();
Command
The command is located at vendor/bin/metrics. Include the vendor/bin directory in the system $PATH to run this command from anywhere.
Type metrics --help to see all the available options.
Saving metrics
Create datastore classes to save your metrics:
// src/EdisonLabs/Metric/Datastore/SqLite.php namespace EdisonLabs\Metric\Datastore; use EdisonLabs\Metrics\Metric\Datastore\AbstractMetricDatastore; class SqLite extends AbstractMetricDatastore { public function getName() { return 'SQLite'; } public function getDescription() { return 'Stores metrics to SQLite'; } public function save() { $metrics = $this->getMetrics(); // Put your logic to store the metrics to SQLite here. return true; } }
Programmatically
// datastore.php use EdisonLabs\Metrics\Collector; use EdisonLabs\Metrics\DatastoreHandler; $date = strtotime('now'); $config = array(); $collector = new Collector($date, $config); $metrics = $collector->getMetrics(); $datastoreHandler = new DatastoreHandler($date, $config); $datastore = $datastoreHandler->getDatastoreByName('SQLite'); $datastore->setMetrics($metrics); $datastore->save();
Command
Use the option --save to list and save your metrics.
metrics --save=SQLite
The --save option accepts multiple values.
metrics --save=SQLite,MySql,MyCustomDatastore
统计信息
- 总下载量: 465
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2018-07-03