2017 © Pedro Peláez
 

library awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

image

fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  • Sunday, September 10, 2017
  • by fustundag
  • Repository
  • 4 Watchers
  • 6 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

AWS CloudWatch Custom Metrics Build Status Scrutinizer Code Quality

You can send custom metrics to AWS CloudWatch like disk/memory usage, (*1)

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 <?php

use AWSCustomMetric\DI; use AWSCustomMetric\Logger\DefaultLogger; use AWSCustomMetric\Sender as CWSender; use AWSCustomMetric\CommandRunner;, (*2)

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

// 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 }, (*4)

// ..., (*5)

- Add to cron like :
``` shell
*/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 : ``` shell /usr/bin/wget -q -O - http://169.254.169.254/latest/meta-data/instance-id, (*6)

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
<?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 :, (*7)

shell composer require fustundag/awscw-custom-metrics, (*8)

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., (*9)

Disclaimer

Your AWS CloudWatch usage my be charged. Please check CloudWatch pricing page : https://aws.amazon.com/cloudwatch/pricing/, (*10)

License

This project is licensed under the MIT license. LICENSE file can be found in this repository., (*11)

The Versions

10/09 2017

dev-master

9999999-dev http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

10/09 2017

2.1.3

2.1.3.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

10/09 2017

2.1.2

2.1.2.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

09/09 2017

2.1.1

2.1.1.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

19/02 2017

2.1.0

2.1.0.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

20/03 2016

2.0.5

2.0.5.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

21/09 2015

2.0.0

2.0.0.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch

19/08 2015

1.0.0

1.0.0.0 http://github.com/fustundag/awscw-custom-metrics

Send custom metric data to AWS CloudWatch for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

amazon aws data custom monitor alert metric cloudwatch