定制 fustundag/awscw-custom-metrics 二次开发

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

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

fustundag/awscw-custom-metrics

最新稳定版本:2.1.3

Composer 安装命令:

composer require fustundag/awscw-custom-metrics

包简介

Send custom metric data to AWS CloudWatch for PHP

README 文档

README

You can send custom metrics to AWS CloudWatch like disk/memory usage

Features

  • Send custom metrics to AWS CloudWatch
  • Add new metrics what you need by metric plugins
  • Configure different cron time for each metric plugin

Requirements

  • PHP 5.5+
  • aws/aws-sdk-php
  • mtdowling/cron-expression

Usage

Basic usage

  • Create php file like awscw-agent.php
<?php

use AWSCustomMetric\DI;
use AWSCustomMetric\Logger\DefaultLogger;
use AWSCustomMetric\Sender as CWSender;
use AWSCustomMetric\CommandRunner;

try {
$diObj = new DI();
$diObj->setCommandRunner(new CommandRunner());
//Optional
//$diObj->setLogger(new DefaultLogger());

// Create the Sender
$cwSender = new CWSender("AWS_KEY", "AWS_SECRET", "AWS_REGION", new CommandRunner());
$cwSender->setNamespace('Custom/System');
$cwSender->addPlugin([
    new DiskUsage($diObj),
    new MemoryUsage($diObj)
]);
$cwSender->run();
} catch (\Exception $e) {
    //Error handling
}

// ...
  • Add to cron like :
*/10 * * * * /path/to/php /path/to/awscw-agent.php

Auto Discover InstanceId

For AWS EC2 instances, some meta-data can be obtained from system like instance-id :

/usr/bin/wget -q -O - http://169.254.169.254/latest/meta-data/instance-id

While creating Sender object, if you dont give instance-id param, class tries to find instance-id using above cmd.

Cron for Metric Plugins

Each metric plugin can be configured to run at specified time. Time can be defined at crontab format. For more info: https://github.com/mtdowling/cron-expression

<?php

use AWSCustomMetric\DI;
use AWSCustomMetric\Logger\DefaultLogger;
use AWSCustomMetric\Sender as CWSender;
use AWSCustomMetric\CommandRunner;

try {
$diObj = new DI();
$diObj->setCommandRunner(new CommandRunner());
//Optional
//$diObj->setLogger(new DefaultLogger());

//metric will be sent at every sender->run calls
$diskPlugin = new DiskUsage($diObj, 'Appname/System', '* * * * *');

//metric will be sent at every hour
$memoryPlugin = new MemoryUsage($diObj, 'Appname/System', '0 * * * *');

// Create the Sender
$cwSender = new CWSender("AWS_KEY", "AWS_SECRET", "AWS_REGION", new CommandRunner());
$cwSender->setNamespace('Custom/System');
$cwSender->addPlugin([$diskPlugin, $memoryPlugin]);
$cwSender->run();
} catch (\Exception $e) {
    //Error handling
}

// ...

Installation

You can use Composer to install :

composer require fustundag/awscw-custom-metrics

TODO

  • NOT TESTED. 86% Coverage 100% Coverage
  • MORE PLUGINS.

Contributing

You can contribute by forking the repo and creating pull requests. You can also create issues or feature requests.

Disclaimer

Your AWS CloudWatch usage my be charged. Please check CloudWatch pricing page : https://aws.amazon.com/cloudwatch/pricing/

License

This project is licensed under the MIT license. LICENSE file can be found in this repository.

统计信息

  • 总下载量: 50
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固